Package org.mlflow.tracking
Class ActiveRun
java.lang.Object
org.mlflow.tracking.ActiveRun
public class ActiveRun
extends java.lang.Object
Represents an active MLflow run and contains APIs to log data to the run.
-
Method Summary
Modifier and Type Method Description void
endRun()
Ends the active MLflow run.void
endRun(Service.RunStatus status)
Ends the active MLflow run.java.lang.String
getArtifactUri()
Get the absolute URI of the run artifact directory root.java.lang.String
getId()
Gets the run id of this run.void
logArtifact(java.nio.file.Path localPath)
LikelogArtifact(Path, String)
with the artifactPath set to the root of the artifact directory.void
logArtifact(java.nio.file.Path localPath, java.lang.String artifactPath)
Uploads the given local file to the run's root artifact directory.void
logArtifacts(java.nio.file.Path localPath)
LikelogArtifacts(Path, String)
with the artifactPath set to the root of the artifact directory.void
logArtifacts(java.nio.file.Path localPath, java.lang.String artifactPath)
Uploads all files within the given local director an artifactPath within the run's root artifact directory.void
logMetric(java.lang.String key, double value)
LikelogMetric(String, double, int)
with a default step of 0.void
logMetric(java.lang.String key, double value, int step)
Logs a metric under this run.void
logMetrics(java.util.Map<java.lang.String,java.lang.Double> metrics)
LikelogMetrics(Map, int)
with a default step of 0.void
logMetrics(java.util.Map<java.lang.String,java.lang.Double> metrics, int step)
Log multiple metrics for this run.void
logParam(java.lang.String key, java.lang.String value)
Log a parameter under this run.void
logParams(java.util.Map<java.lang.String,java.lang.String> params)
Log multiple params for this run.void
setTag(java.lang.String key, java.lang.String value)
Sets a tag under this run.void
setTags(java.util.Map<java.lang.String,java.lang.String> tags)
Sets multiple tags for this run.
-
Method Details
-
getId
public java.lang.String getId()Gets the run id of this run.- Returns:
- The run id of this run.
-
logParam
public void logParam(java.lang.String key, java.lang.String value)Log a parameter under this run.- Parameters:
key
- The name of the parameter.value
- The value of the parameter.
-
setTag
public void setTag(java.lang.String key, java.lang.String value)Sets a tag under this run.- Parameters:
key
- The name of the tag.value
- The value of the tag.
-
logMetric
public void logMetric(java.lang.String key, double value)LikelogMetric(String, double, int)
with a default step of 0. -
logMetric
public void logMetric(java.lang.String key, double value, int step)Logs a metric under this run.- Parameters:
key
- The name of the metric.value
- The value of the metric.step
- The metric step.
-
logMetrics
public void logMetrics(java.util.Map<java.lang.String,java.lang.Double> metrics)LikelogMetrics(Map, int)
with a default step of 0. -
logMetrics
public void logMetrics(java.util.Map<java.lang.String,java.lang.Double> metrics, int step)Log multiple metrics for this run.- Parameters:
metrics
- A map of metric name to value.step
- The metric step.
-
logParams
public void logParams(java.util.Map<java.lang.String,java.lang.String> params)Log multiple params for this run.- Parameters:
params
- A map of param name to value.
-
setTags
public void setTags(java.util.Map<java.lang.String,java.lang.String> tags)Sets multiple tags for this run.- Parameters:
tags
- A map of tag name to value.
-
logArtifact
public void logArtifact(java.nio.file.Path localPath)LikelogArtifact(Path, String)
with the artifactPath set to the root of the artifact directory.- Parameters:
localPath
- Path of file to upload. Must exist, and must be a simple file (not a directory).
-
logArtifact
public void logArtifact(java.nio.file.Path localPath, java.lang.String artifactPath)Uploads the given local file to the run's root artifact directory. For example,activeRun.logArtifact("/my/localModel", "model") mlflowClient.listArtifacts(activeRun.getId(), "model") // returns "model/localModel"
- Parameters:
localPath
- Path of file to upload. Must exist, and must be a simple file (not a directory).artifactPath
- Artifact path relative to the run's root directory given bygetArtifactUri()
. Should NOT start with a /.
-
logArtifacts
public void logArtifacts(java.nio.file.Path localPath)LikelogArtifacts(Path, String)
with the artifactPath set to the root of the artifact directory.- Parameters:
localPath
- Directory to upload. Must exist, and must be a directory (not a simple file).
-
logArtifacts
public void logArtifacts(java.nio.file.Path localPath, java.lang.String artifactPath)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", thenactiveRun.logArtifacts("/my/local/dir", "model") mlflowClient.listArtifacts(activeRun.getId(), "model") // returns "model/file1" and // "model/file2"
(i.e., the contents of the local directory are now available in model/).- Parameters:
localPath
- Directory to upload. Must exist, and must be a directory (not a simple file).artifactPath
- Artifact path relative to the run's root directory given bygetArtifactUri()
. Should NOT start with a /.
-
getArtifactUri
public java.lang.String getArtifactUri()Get the absolute URI of the run artifact directory root.- Returns:
- The absolute URI of the run artifact directory root.
-
endRun
public void endRun()Ends the active MLflow run. -
endRun
Ends the active MLflow run.- Parameters:
status
- The status of the run.
-