Skip to content

Resume an Experiment¶

There are several scenarios where you might to resume logging to an experiment or to append data:

  • You are resuming the logging of a training run or doing distributed running, in that case you can use comet_ml.start to get the same experience as a normal training run.
  • In all other cases, you can use the APIExperiment object to append data.

The main difference between these two options is that the comet_ml.start method returns an Experiment class optimized for logging data during a training run (autologging, data upload in background thread for better performance, etc) while the APIExperiment is a light wrapper over the Comet REST API.

Note

If you have an experiment already running in you process but don't have access to the experiment object, you can use the comet_ml.get_running_experiment method that will return the experiment object if it exists.

Use comet_ml.start¶

You can use comet_ml.start to log data to an existing experiment, this will allows you to continue logging from where you left off. Once the Experiment is resumed, auto-loggers will start logging data to Comet once again and you can use the log_*() methods to log any additional information you need.

In order to use this class, you will need to know the experiment key for the experiment you would like to resume. It can be found in the UI either in the Single Experiment page or by adding the Experiment Key column to your Experiment table.

Once you have the Experiment Key, you can resume logging data using:

1
2
3
4
5
import comet_ml

comet_ml.login() # Only required if the API key is not configured for this environment

exp = comet_ml.start(mode="get", experiment_key="your_experiment_key")

Warning

In order to avoid overwriting any previously logged information, we disable by default the following parameters: log_code, log_graph, parse_args, log_env_details, log_git_metadata, log_git_patch, log_env_gpu, log_env_cpu and log_env_host. These can be turned on again when you create the ExistingExperiment object.

Use the APIExperiment class¶

The APIExperiment object is a wrapper around the Comet REST API and should be used to either download data logged to an experiment or to log data in a one off manner. If you are resuming a training run, we recommend you use the ExistingExperiment class.

If you know the Experiment Key of the experiment you want to access, you can create an APIExperiment using:

1
2
3
4
5
import comet_ml

comet_ml.login()  # Only required if the API key is not configured for this environment

api_exp = comet_ml.APIExperiment(previous_experiment="your_experiment_key")

If you don't know the Experiment Key or would like to fetch a specific experiment, you can use the API.query() method:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
import comet_ml
from comet_ml.query import Tag

comet_ml.login()

api = comet_ml.API()

# Query experiments based on tags for example
api.query(
    workspace="your_workspace_name",
    project_name="your_proejct_name",
    query=(Tag() == "baseline"),
)

You can learn more about the API.query method in the reference documentation here

Use the get_running_experiment method¶

The get_running_experiment() method lets you get access to a running experiment created previously in the current Python process:

import comet_ml
experiment = comet_ml.get_running_experiment()

Info

The details of comet_ml.get_running_experiment may change in the future.

If you are trying to continue an experiment from a different session, worker, process, or thread, it is recommended you use the method described in the previous section.

Nov. 18, 2024