Comet
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 method requires you to configure a ZenML secret to store the Comet tracking service credentials securely.
You can create the secret using the zenml secret create
command:
zenml secret create comet_secret \
--workspace=<WORKSPACE> \
--project_name=<PROJECT_NAME> \
--api_key=<API_KEY>
Once the secret is created, you can use it to configure the Comet Experiment Tracker:
# Reference the workspace, project, and api-key in our experiment tracker component
zenml experiment-tracker register comet_tracker \
--flavor=comet \
--workspace={{comet_secret.workspace}} \
--project_name={{comet_secret.project_name}} \
--api_key={{comet_secret.api_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 for our Comet integration.
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
@step(experiment_tracker=experiment_tracker.name)
def my_step():
...
# go through some experiment tracker methods
experiment_tracker.log_metrics({"my_metric": 42})
experiment_tracker.log_params({"my_param": "hello"})
# or use the Experiment object directly
experiment_tracker.experiment.log_model(...)
# or pass the Comet Experiment object into helper methods
from comet_ml.integration.sklearn import log_model
log_model(
experiment=experiment_tracker.experiment,
model_name="SVC",
model=model,
)
...
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.steps["<STEP_NAME>"]
tracking_url = trainer_step.run_metadata["experiment_tracker_url"].value
print(tracking_url)

Alternatively, you can see an overview of all experiments at https://www.comet.com/{WORKSPACE_NAME}/{PROJECT_NAME}/experiments/
.
Full Code Example
This section combines all the code from this section into one simple script that you can use to run easily:
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(
tags=["some_tag"],
run_name="",
settings={},
)
@step(
experiment_tracker="<COMET_TRACKER_STACK_COMPONENT_NAME>",
settings={
"experiment_tracker": 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
Was this helpful?