2

I would like to use MLFlow (with Python) to log time series with time interval equal to 1 day. My idea would be to create a new run with a certain ID and to use function log_metric every day (say, with a cron job) with a new value. Once my run is terminated, can I "reopen" it and log a new metric ? What I have in mind is:

# Day 1
import mlflow

tracking_uri = "my_uri"
mlflow.set_tracking_uri(tracking_uri)
xp_id = 0
mlflow.start_run(run_name="test", experiment_id=xp_id)
mlflow.log_metric("test_metric", 1)
mlflow.end_run()

And the following days:

import mlflow

def log_daily_metric(daily_value_metric):
  tracking_uri = "my_uri"
  mlflow.set_tracking_uri(tracking_uri)
  xp_id = 0
  mlflow.restart_run(run_name="test", experiment_id=xp_id)  # /!\ function mlflow.restart does not exist
  mlflow.log_metric("test_metric", daily_value_metric)
  mlflow.end_run()

so that run "test" would have new metrics logged every day.

Any idea to achieve this ?

dallonsi
  • 1,299
  • 1
  • 8
  • 29

2 Answers2

1

The solution seems to be:

# day 1

import mlflow

tracking_uri = "my_uri"
mlflow.set_tracking_uri(tracking_uri)
xp_id = 0

client = MlflowClient()
run = client.create_run(experiment_id=xp_id)
print(run.info.run_id)  # gives you the run ID of your experiment. Example: "df85f660dca47d21b41454342cd3a7cb". Let's save this id somewhere...

Then,

import mlflow

def log_daily_metric(daily_value_metric: float, day: int):
  tracking_uri = "my_uri"
  mlflow.set_tracking_uri(tracking_uri)
  xp_id = 0
  client = MlflowClient()
  run_id = "df85f660dca47d21b41454342cd3a7cb"
  client.log_metric(run_id=run_id, key="test_metric", value=daily_value_metric, step=day)
dallonsi
  • 1,299
  • 1
  • 8
  • 29
0

I'm late to the party, but here is what I found, with mlflow 1.28.

Step 1.: find the run_id.

xp_id = mlflow.get_experiment_by_name('your_experiment')._experiment_id
run_id = mlflow.search_runs(xp, output_format="list")[0].info.run_id

Note, by default, mlflow.search_runs lists runs from newest to oldest.

Step 2.:

Re-activate run by run_id, by passing it to mlflow.start_run.

mlflow.set_experiment('your_experiment')
with mlflow.start_run(run_id):
    mlflow.log_param('new', 'param!')
0x2A
  • 1