Class ActiveRun

java.lang.Object
org.mlflow.tracking.ActiveRun

public class ActiveRun extends Object
Represents an active MLflow run and contains APIs to log data to the run.
  • Method Details

    • getId

      public String getId()
      Gets the run id of this run.
      Returns:
      The run id of this run.
    • logParam

      public void logParam(String key, 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(String key, 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(String key, double value)
      Like logMetric(String, double, int) with a default step of 0.
    • logMetric

      public void logMetric(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(Map<String,Double> metrics)
      Like logMetrics(Map, int) with a default step of 0.
    • logMetrics

      public void logMetrics(Map<String,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(Map<String,String> params)
      Log multiple params for this run.
      Parameters:
      params - A map of param name to value.
    • setTags

      public void setTags(Map<String,String> tags)
      Sets multiple tags for this run.
      Parameters:
      tags - A map of tag name to value.
    • logArtifact

      public void logArtifact(Path localPath)
      Like logArtifact(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(Path localPath, 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 by getArtifactUri(). Should NOT start with a /.
    • logArtifacts

      public void logArtifacts(Path localPath)
      Like logArtifacts(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(Path localPath, 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", then
         activeRun.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 by getArtifactUri(). Should NOT start with a /.
    • getArtifactUri

      public 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

      public void endRun(Service.RunStatus status)
      Ends the active MLflow run.
      Parameters:
      status - The status of the run.