Skip to content

Commit

Permalink
[R] Fix search runs bug & add test (mlflow#1310)
Browse files Browse the repository at this point in the history
Fixes bugs in mlflow_search_run and mlflow_list_run_infos within the R API, and adds a test verifying their correctness.
  • Loading branch information
smurching authored May 23, 2019
1 parent 43700cb commit 110065d
Show file tree
Hide file tree
Showing 6 changed files with 59 additions and 10 deletions.
16 changes: 11 additions & 5 deletions docs/source/R-api.rst
Original file line number Diff line number Diff line change
Expand Up @@ -471,7 +471,7 @@ the supported MLflow models.

.. code:: r
mlflow_load_flavor(model_path)
mlflow_load_flavor(flavor, model_path)
.. _arguments-13:

Expand All @@ -481,6 +481,8 @@ Arguments
+----------------+------------------------------------------------------------+
| Argument | Description |
+================+============================================================+
| ``flavor`` | An MLflow flavor object. |
+----------------+------------------------------------------------------------+
| ``model_path`` | The path to the MLflow model wrapped in the correct class. |
+----------------+------------------------------------------------------------+

Expand Down Expand Up @@ -926,7 +928,7 @@ Serves an RFunc MLflow model as a local web API.
.. code:: r
mlflow_rfunc_serve(model_uri, host = "127.0.0.1", port = 8090,
daemonized = FALSE, browse = !daemonized)
daemonized = FALSE, browse = !daemonized, ...)
.. _arguments-25:

Expand Down Expand Up @@ -956,6 +958,9 @@ Arguments
| ``browse`` | Launch browser with serving landing |
| | page? |
+-------------------------------+--------------------------------------+
| ``...`` | Optional arguments passed to |
| | ``mlflow_predict()``. |
+-------------------------------+--------------------------------------+

.. _details-20:

Expand Down Expand Up @@ -1117,8 +1122,9 @@ Arguments
+-------------------------------+--------------------------------------+
| ``run_view_type`` | Run view type. |
+-------------------------------+--------------------------------------+
| ``experiment_ids`` | List of experiment IDs to search |
| | over. Attempts to use active |
| ``experiment_ids`` | List of string experiment IDs (or a |
| | single string experiment ID) to |
| | search over. Attempts to use active |
| | experiment if not specified. |
+-------------------------------+--------------------------------------+
| ``client`` | (Optional) An ``mlflow_client`` |
Expand Down Expand Up @@ -1346,7 +1352,7 @@ Examples

.. code:: r
list("\n", "with(mlflow_start_run(), {\n", " mlflow_log(\"test\", 10)\n", "})\n")
list("\n", "with(mlflow_start_run(), {\n", " mlflow_log_metric(\"test\", 10)\n", "})\n")
Run MLflow User Interface
Expand Down
1 change: 1 addition & 0 deletions mlflow/R/mlflow/DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ Depends:
R (>= 3.3.0)
Imports:
base64enc,
dplyr,
forge,
fs,
git2r,
Expand Down
11 changes: 8 additions & 3 deletions mlflow/R/mlflow/R/tracking-runs.R
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,8 @@ mlflow_get_metric_history <- function(metric_key, run_id = NULL, client = NULL)
#' Search for runs that satisfy expressions. Search expressions can use Metric and Param keys.
#'
#' @template roxlate-client
#' @param experiment_ids List of experiment IDs to search over. Attempts to use active experiment if not specified.
#' @param experiment_ids List of string experiment IDs (or a single string experiment ID) to search
#' over. Attempts to use active experiment if not specified.
#' @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.
Expand All @@ -256,10 +257,14 @@ mlflow_search_runs <- function(filter = NULL,
run_view_type = c("ACTIVE_ONLY", "DELETED_ONLY", "ALL"), experiment_ids = NULL,
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
if (is.atomic(experiment_ids)) {
experiment_ids <- list(experiment_ids)
}
client <- resolve_client(client)

run_view_type <- match.arg(run_view_type)
experiment_ids <- cast_double_list(experiment_ids)
experiment_ids <- cast_string_list(experiment_ids)
filter <- cast_nullable_string(filter)

response <- mlflow_rest("runs", "search", client = client, verb = "POST", data = list(
Expand Down Expand Up @@ -465,7 +470,7 @@ mlflow_log_artifact <- function(path, artifact_path = NULL, run_id = NULL, clien
#' @examples
#' \dontrun{
#' with(mlflow_start_run(), {
#' mlflow_log("test", 10)
#' mlflow_log_metric("test", 10)
#' })
#' }
#'
Expand Down
3 changes: 2 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.

2 changes: 1 addition & 1 deletion mlflow/R/mlflow/man/mlflow_start_run.Rd

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

36 changes: 36 additions & 0 deletions mlflow/R/mlflow/tests/testthat/test-tracking-runs.R
Original file line number Diff line number Diff line change
Expand Up @@ -228,6 +228,42 @@ test_that("with() errors when not passed active run", {
)
})

test_that("mlflow_search_runs() works", {
mlflow_clear_test_dir("mlruns")
with(mlflow_start_run(), {
mlflow_log_metric("test", 10)
})
with(mlflow_start_run(), {
mlflow_log_metric("test", 20)
})
expect_equal(nrow(mlflow_search_runs(experiment_ids = list("0"))), 2)
expect_equal(nrow(mlflow_search_runs(experiment_ids = "0")), 2)
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)
mlflow_set_experiment("new-experiment")
expect_equal(nrow(mlflow_search_runs()), 0)
with(mlflow_start_run(), {
mlflow_log_metric("new_experiment_metric", 30)
})
expect_equal(nrow(mlflow_search_runs(filter = "metrics.new_experiment_metric = 30")), 1)
})

test_that("mlflow_list_run_infos() works", {
mlflow_clear_test_dir("mlruns")
expect_equal(nrow(mlflow_list_run_infos(experiment_id = "0")), 0)
with(mlflow_start_run(), {
mlflow_log_metric("test", 10)
})
expect_equal(nrow(mlflow_list_run_infos(experiment_id = "0")), 1)
mlflow_set_experiment("new-experiment")
expect_equal(nrow(mlflow_list_run_infos()), 0)
with(mlflow_start_run(), {
mlflow_log_metric("new_experiment_metric", 20)
})
expect_equal(nrow(mlflow_list_run_infos()), 1)
})

test_that("mlflow_log_batch() works", {
mlflow_clear_test_dir("mlruns")
mlflow_start_run()
Expand Down

0 comments on commit 110065d

Please sign in to comment.