Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Move user to tag #1230

Merged
merged 21 commits into from May 13, 2019
Merged
Show file tree
Hide file tree
Changes from 20 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 4 additions & 0 deletions docs/source/rest-api.rst
Expand Up @@ -353,6 +353,8 @@ Request Structure
| experiment_id | ``INT64`` | ID of the associated experiment. |
+------------------+---------------------------------+------------------------------------------------------------------------------------------------+
| user_id | ``STRING`` | ID of the user executing the run. |
| | | This field is deprecated and will be removed in a later MLflow version. Use the |
| | | ``mlflow.user`` run tag instead. |
+------------------+---------------------------------+------------------------------------------------------------------------------------------------+
| run_name | ``STRING`` | Human readable name for the run. |
| | | This field is deprecated and will be removed in MLflow 1.0. Use the ``mlflow.runName`` run tag |
Expand Down Expand Up @@ -1279,6 +1281,8 @@ Metadata of a single run.
| | | tag instead. |
+------------------+-------------------------+------------------------------------------------------------------------------------------------+
| user_id | ``STRING`` | User who initiated the run. |
| | | This field is deprecated and will be removed in a later MLflow version. Use the |
| | | ``mlflow.user`` run tag instead. |
+------------------+-------------------------+------------------------------------------------------------------------------------------------+
| status | :ref:`mlflowrunstatus` | Current status of the run. |
+------------------+-------------------------+------------------------------------------------------------------------------------------------+
Expand Down
1 change: 1 addition & 0 deletions examples/rest_api/mlflow_tracking_rest_api.py
Expand Up @@ -26,6 +26,7 @@ def __init__(self, hostname, port, experiment_id):
def create_run(self):
"""Create a new run for tracking."""
url = self.base_url + '/runs/create'
# user_id is deprecated and will be removed from the API in a future release
payload = {'experiment_id': self.experiment_id, 'start_time': int(time.time() * 1000), 'user_id': _get_user_id()}
r = requests.post(url, json=payload)
run_id = None
Expand Down
25 changes: 10 additions & 15 deletions mlflow/R/mlflow/R/tracking-runs.R
Expand Up @@ -26,18 +26,18 @@ mlflow_log_metric <- function(key, value, timestamp = NULL, run_id = NULL, clien
invisible(value)
}

mlflow_create_run <- function(start_time = NULL, tags = NULL, experiment_id = NULL, client) {
experiment_id <- resolve_experiment_id(experiment_id)

# Read user_id from tags
# user_id is deprecated and will be removed from a future release
user_id <- tags[[MLFLOW_TAGS$MLFLOW_USER]] %||% "unknown"


mlflow_create_run <- function(user_id = NULL, start_time = NULL, tags = NULL,
experiment_id = NULL, client) {
experiment_id <- resolve_experiment_id(experiment_id)
tags <- if (!is.null(tags)) tags %>%
purrr::imap(~ list(key = .y, value = .x)) %>%
unname()

start_time <- start_time %||% current_time()
user_id <- user_id %||% mlflow_user()

response <- mlflow_rest(
"runs", "create",
Expand Down Expand Up @@ -310,7 +310,6 @@ mlflow_set_terminated <- function(status, end_time, run_id, client) {
mlflow_get_run(client = client, run_id = response$run_info$run_uuid)
}


#' Download Artifacts
#'
#' Download an artifact file or directory from a run to a local directory if applicable,
Expand Down Expand Up @@ -341,7 +340,6 @@ mlflow_download_artifacts <- function(path, run_id = NULL, client = NULL) {
gsub("\n", "", result$stdout)
}


# ' Download Artifacts from URI.
mlflow_download_artifacts_from_uri <- function(artifact_uri, client = mlflow_client()) {
result <- mlflow_cli("artifacts", "download-from-uri", "-a", artifact_uri, echo = FALSE,
Expand Down Expand Up @@ -444,12 +442,11 @@ mlflow_log_artifact <- function(path, artifact_path = NULL, run_id = NULL, clien
mlflow_list_artifacts(run_id = run_id, path = artifact_path, client = client)
}


#' Start Run
#'
#' Starts a new run. If `client` is not provided, this function infers contextual information such as
#' source name and version, and also registers the created run as the active run. If `client` is provided,
#' no inference is done, and additional arguments such as `user_id` and `start_time` can be provided.
#' no inference is done, and additional arguments such as `start_time` can be provided.
#'
#' @param run_id If specified, get the run with the specified UUID and log metrics
#' and params under that run. The run's end time is unset and its status is set to
Expand All @@ -462,7 +459,6 @@ mlflow_log_artifact <- function(path, artifact_path = NULL, run_id = NULL, clien
#' @param source_version Optional Git commit hash to associate with the run.
#' @param entry_point_name Optional name of the entry point for to the current run.
#' @param source_type Integer enum value describing the type of the run ("local", "project", etc.).
#' @param user_id User ID or LDAP for the user executing the run. Only used when `client` is specified.
#' @param start_time Unix timestamp of when the run started in milliseconds. Only used when `client` is specified.
#' @param tags Additional metadata for run in key-value pairs. Only used when `client` is specified.
#' @template roxlate-client
Expand All @@ -475,21 +471,19 @@ mlflow_log_artifact <- function(path, artifact_path = NULL, run_id = NULL, clien
#' }
#'
#' @export
mlflow_start_run <- function(run_id = NULL, experiment_id = NULL, user_id = NULL,
start_time = NULL, tags = NULL, client = NULL) {
mlflow_start_run <- function(run_id = NULL, experiment_id = NULL, start_time = NULL, tags = NULL, client = NULL) {

# When `client` is provided, this function acts as a wrapper for `runs/create` and does not register
# an active run.
if (!is.null(client)) {
if (!is.null(run_id)) stop("`run_id` should not be specified when `client` is specified.", call. = FALSE)
run <- mlflow_create_run(client = client, user_id = user_id, start_time = start_time,
run <- mlflow_create_run(client = client, start_time = start_time,
tags = tags, experiment_id = experiment_id)
return(run)
}

# Fluent mode, check to see if extraneous params passed.

if (!is.null(user_id)) stop("`user_id` should only be specified when `client` is specified.", call. = FALSE)
if (!is.null(start_time)) stop("`start_time` should only be specified when `client` is specified.", call. = FALSE)
if (!is.null(tags)) stop("`tags` should only be specified when `client` is specified.", call. = FALSE)

Expand Down Expand Up @@ -524,13 +518,13 @@ mlflow_start_run <- function(run_id = NULL, experiment_id = NULL, user_id = NULL
run
}


mlflow_get_run_context <- function(client, ...) {
UseMethod("mlflow_get_run_context")
}

mlflow_get_run_context.default <- function(client, experiment_id, ...) {
tags <- list()
tags[[MLFLOW_TAGS$MLFLOW_USER]] <- mlflow_user()
tags[[MLFLOW_TAGS$MLFLOW_SOURCE_NAME]] <- get_source_name()
tags[[MLFLOW_TAGS$MLFLOW_SOURCE_VERSION]] <- get_source_version()
tags[[MLFLOW_TAGS$MLFLOW_SOURCE_TYPE]] <- MLFLOW_SOURCE_TYPE$LOCAL
Expand Down Expand Up @@ -580,6 +574,7 @@ mlflow_end_run <- function(status = c("FINISHED", "SCHEDULED", "FAILED", "KILLED
}

MLFLOW_TAGS <- list(
MLFLOW_USER = "mlflow.user",
MLFLOW_SOURCE_NAME = "mlflow.source.name",
MLFLOW_SOURCE_VERSION = "mlflow.source.version",
MLFLOW_SOURCE_TYPE = "mlflow.source.type"
Expand Down
10 changes: 6 additions & 4 deletions mlflow/R/mlflow/tests/testthat/test-tracking-runs.R
Expand Up @@ -6,8 +6,7 @@ test_that("mlflow_start_run()/mlflow_get_run() work properly", {
run <- mlflow_start_run(
client = client,
experiment_id = "0",
user_id = "user1",
tags = list(foo = "bar", foz = "baz")
tags = list(foo = "bar", foz = "baz", mlflow.user = "user1")
)

run <- mlflow_get_run(client = client, run$run_uuid)
Expand All @@ -16,7 +15,11 @@ test_that("mlflow_start_run()/mlflow_get_run() work properly", {

expect_true(
all(purrr::transpose(run$tags[[1]]) %in%
list(list(key = "foz", value = "baz"), list(key = "foo", value = "bar"))
list(
list(key = "foz", value = "baz"),
list(key = "foo", value = "bar"),
list(key = "mlflow.user", value = "user1")
)
)
)
})
Expand Down Expand Up @@ -72,7 +75,6 @@ test_that("logging functionality", {
expect_true(all(difftime(metric_history$timestamp, run_start_time) >= 0))
expect_true(all(difftime(metric_history$timestamp, run_end_time) <= 0))


expect_error(
mlflow_get_run(),
"`run_id` must be specified when there is no active run\\."
Expand Down
48 changes: 48 additions & 0 deletions mlflow/java/client/src/main/java/org/mlflow/api/proto/Service.java

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

Expand Up @@ -84,6 +84,8 @@ public RunInfo createRun(String experimentId) {
CreateRun.Builder request = CreateRun.newBuilder();
request.setExperimentId(experimentId);
request.setStartTime(System.currentTimeMillis());
// userId is deprecated and will be removed in a future release.
// It should be set as the `mlflow.user` tag instead.
String username = System.getProperty("user.name");
if (username != null) {
request.setUserId(System.getProperty("user.name"));
Expand Down Expand Up @@ -432,7 +434,6 @@ public void logArtifacts(String runId, File localDir) {
getArtifactRepository(runId).logArtifacts(localDir);
}


/**
* Uploads all files within the given local director an artifactPath within the run's root
* artifact directory. For example, if /my/local/dir/ contains two files "file1" and "file2", then
Expand Down