Logging and visualizing experiments with Comet.

The Comet Experiment Tracker is an Experiment Tracker flavor provided with the Comet ZenML integration that uses the Comet experiment tracking platform to log and visualize information from your pipeline steps (e.g., models, parameters, metrics).

When would you want to use it?

Comet is a popular platform that you would normally use in the iterative ML experimentation phase to track and visualize experiment results. That doesn't mean that it cannot be repurposed to track and visualize the results produced by your automated pipeline runs, as you make the transition towards a more production-oriented workflow.

You should use the Comet Experiment Tracker:

  • if you have already been using Comet to track experiment results for your project and would like to continue doing so as you are incorporating MLOps workflows and best practices in your project through ZenML.

  • if you are looking for a more visually interactive way of navigating the results produced from your ZenML pipeline runs (e.g., models, metrics, datasets)

  • if you would like to connect ZenML to Comet to share the artifacts and metrics logged by your pipelines with your team, organization, or external stakeholders

You should consider one of the other Experiment Tracker flavors if you have never worked with Comet before and would rather use another experiment tracking tool that you are more familiar with.

How do you deploy it?

The Comet Experiment Tracker flavor is provided by the Comet ZenML integration. You need to install it on your local machine to be able to register a Comet Experiment Tracker and add it to your stack:

zenml integration install comet -y

The Comet Experiment Tracker needs to be configured with the credentials required to connect to the Comet platform using one of the available authentication methods.

Authentication Methods

You need to configure the following credentials for authentication to the Comet platform:

  • api_key: Mandatory API key token of your Comet account.

  • project_name: The name of the project where you're sending the new experiment. If the project is not specified, the experiment is put in the default project associated with your API key.

  • workspace: Optional. The name of the workspace where your project is located. If not specified, the default workspace associated with your API key will be used.

This option configures the credentials for the Comet platform directly as stack component attributes.

This is not recommended for production settings as the credentials won't be stored securely and will be clearly visible in the stack configuration.

# Register the Comet experiment tracker
zenml experiment-tracker register comet_experiment_tracker --flavor=comet \
    --workspace=<workspace> --project_name=<project_name> --api_key=<key>

# Register and set a stack with the new experiment tracker
zenml stack register custom_stack -e comet_experiment_tracker ... --set

For more up-to-date information on the Comet Experiment Tracker implementation and its configuration, you can have a look at the SDK docs.

How do you use it?

To be able to log information from a ZenML pipeline step using the Comet Experiment Tracker component in the active stack, you need to enable an experiment tracker using the @step decorator. Then use Comet logging capabilities as you would normally do, e.g.:

from zenml.client import Client

experiment_tracker = Client().active_stack.experiment_tracker

def my_step():
    experiment_tracker.log_metrics({"my_metric": 42})
    experiment_tracker.log_params({"my_param": "hello"})

Instead of hardcoding an experiment tracker name, you can also use the Client to dynamically use the experiment tracker of your active stack, as shown in the example above.

Comet UI

Comet comes with a web-based UI that you can use to find further details about your tracked experiments.

Every ZenML step that uses Comet should create a separate experiment which you can inspect in the Comet UI.

You can find the URL of the Comet experiment linked to a specific ZenML run via the metadata of the step in which the experiment tracker was used:

from zenml.client import Client

last_run = client.get_pipeline("<PIPELINE_NAME>").last_run
trainer_step = last_run.get_step("<STEP_NAME>")
tracking_url = trainer_step.run_metadata["experiment_tracker_url"].value

Alternatively, you can see an overview of all experiments at{WORKSPACE_NAME}/{PROJECT_NAME}/experiments/.

The naming convention of each Comet experiment is {pipeline_run_name}_{step_name} (e.g., comet_example_pipeline-25_Apr_22-20_06_33_535737_my_step), and each experiment will be tagged with both pipeline_name and pipeline_run_name, which you can use to group and filter experiments.

Additional configuration

For additional configuration of the Comet experiment tracker, you can pass CometExperimentTrackerSettings to provide additional tags for your experiments:

from zenml.integrations.comet.flavors.comet_experiment_tracker_flavor import CometExperimentTrackerSettings

comet_settings = CometExperimentTrackerSettings(

        "experiment_tracker.comet": comet_settings
def my_step():

Check out the SDK docs for a full list of available attributes and this docs page for more information on how to specify settings.

Last updated