Skip to content

Resume an Experiment

To resume logging data to an existing experiment, you can use one of two classes:

  • ExistingExperiment
  • APIExperiment

The main difference between these two classes is that the APIExperiment is a simple wrapper over the Comet REST API while the ExistingExperiment shares the same functionality as the Experiment class (autologging, data upload in background thread for better performance, etc).

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_global_experiment() that will return the experiment object if it exists. We do not recommend you use the ExistingExperiment or APIExperiment in this scenario.

Use the ExistingExperiment class

Comet provides an ExistingExperiment object that allows you to continue logging from where you left off. Once the Experiment is restarted, 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
6
7
import comet_ml

comet_ml.init()

exp = comet_ml.ExistingExperiment(
    previous_experiment="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
6
import comet_ml

comet_ml.init() # 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.init()

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_global method

The get_global() method lets you get access to the current experiment created in another part of the code. So:

import comet_ml
experiment = comet_ml.get_global_experiment()

Info

The details of comet_ml.get_global_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.

Apr. 29, 2024