Skip to content

Commit

Permalink
[R] Add order_by support to mlflow_search_runs (mlflow#1485)
Browse files Browse the repository at this point in the history
  • Loading branch information
aarondav authored Jun 21, 2019
1 parent dbd4944 commit 484bb43
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 4 deletions.
6 changes: 5 additions & 1 deletion docs/source/R-api.rst
Original file line number Diff line number Diff line change
Expand Up @@ -1227,7 +1227,8 @@ Metric and Param keys.
.. code:: r
mlflow_search_runs(filter = NULL, run_view_type = c("ACTIVE_ONLY",
"DELETED_ONLY", "ALL"), experiment_ids = NULL, client = NULL)
"DELETED_ONLY", "ALL"), experiment_ids = NULL, order_by = list(),
client = NULL)
.. _arguments-28:

Expand All @@ -1252,6 +1253,9 @@ Arguments
| | search over. Attempts to use active |
| | experiment if not specified. |
+-------------------------------+--------------------------------------+
| ``order_by`` | List of properties to order by. |
| | Example: “metrics.acc DESC”. |
+-------------------------------+--------------------------------------+
| ``client`` | (Optional) An MLflow client object |
| | returned from |
| | `mlflow_client <#mlflow-client>`__ . |
Expand Down
8 changes: 6 additions & 2 deletions mlflow/R/mlflow/R/tracking-runs.R
Original file line number Diff line number Diff line change
Expand Up @@ -253,10 +253,13 @@ mlflow_get_metric_history <- function(metric_key, run_id = NULL, client = NULL)
#' @param filter A filter expression over params, metrics, and tags, allowing returning a subset of runs.
#' The syntax is a subset of SQL which allows only ANDing together binary operations between a param/metric/tag and a constant.
#' @param run_view_type Run view type.
#' @param order_by List of properties to order by. Example: "metrics.acc DESC".
#'
#' @export
mlflow_search_runs <- function(filter = NULL,
run_view_type = c("ACTIVE_ONLY", "DELETED_ONLY", "ALL"), experiment_ids = NULL,
run_view_type = c("ACTIVE_ONLY", "DELETED_ONLY", "ALL"),
experiment_ids = NULL,
order_by = list(),
client = NULL) {
experiment_ids <- resolve_experiment_id(experiment_ids)
# If we get back a single experiment ID, e.g. the active experiment ID, convert it to a list
Expand All @@ -272,7 +275,8 @@ mlflow_search_runs <- function(filter = NULL,
response <- mlflow_rest("runs", "search", client = client, verb = "POST", data = list(
experiment_ids = experiment_ids,
filter = filter,
run_view_type = run_view_type
run_view_type = run_view_type,
order_by = cast_string_list(order_by)
))

runs_list <- response$run %>%
Expand Down
5 changes: 4 additions & 1 deletion mlflow/R/mlflow/man/mlflow_search_runs.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 9 additions & 0 deletions mlflow/R/mlflow/tests/testthat/test-tracking-runs.R
Original file line number Diff line number Diff line change
Expand Up @@ -249,6 +249,15 @@ test_that("mlflow_search_runs() works", {
expect_equal(nrow(mlflow_search_runs(filter = "metrics.test > 10", experiment_ids = list("0"))), 1)
expect_equal(nrow(mlflow_search_runs(filter = "metrics.test < 20", experiment_ids = list("0"))), 1)
expect_equal(nrow(mlflow_search_runs(filter = "metrics.test > 20", experiment_ids = list("0"))), 0)

search <- mlflow_search_runs(order_by = "metrics.test", experiment_ids = list("0"))
expect_equal(search$metrics[[1]]$value[1], 10)
expect_equal(search$metrics[[2]]$value[1], 20)

search <- mlflow_search_runs(order_by = list("metrics.test DESC"), experiment_ids = list("0"))
expect_equal(search$metrics[[1]]$value[1], 20)
expect_equal(search$metrics[[2]]$value[1], 10)

mlflow_set_experiment("new-experiment")
expect_equal(nrow(mlflow_search_runs()), 0)
with(mlflow_start_run(), {
Expand Down

0 comments on commit 484bb43

Please sign in to comment.