Run an Experiment in Jupyter Notebooks¶
Comet integrates seamlessly with hosted Jupyter Notebook services, including Google's Colab, Microsoft's Azure Notebooks, Amazon SageMaker Studio Lab, Amazon SageMaker notebook instance, and others.
Start logging data to Comet¶
You can pip install and configure the comet_ml
library from any notebook using:
1 2 3 4 |
|
You can then create a new experiment using the Experiment
class which will start the Comet auto-loggers and allow you to log custom metrics:
1 2 3 4 5 6 7 8 |
|
Please refer to Logging Experiment data for information on how to log different data types, integrations for an overview of the frameworks that Comet integrates with and corresponding functionalities, and Python SDK for a complete reference to all the methods provided by comet_ml
.
Note
When you call exp.end()
, Comet will know the training is completed and will log all the executed cells. This allows you to know exactly what code was run and in what order meaning every training run is reproducible even in Notebooks !
Display the Comet UI directly in a Notebook¶
Another key feature of Comet in Notebooks is the ability to display the Comet UI within a cell using the Experiment.display()
method:
1 2 3 4 5 6 |
|
The following tab names are available:
panels | code | parameters |
metrics | graph | output |
system-metrics | installed-packages | notes |
graphics | audio | text |
confusion-matrices | histograms | other |
html | assets | artifacts |

Managing Comet API Key in Google Colab¶
When using Comet in Google Colab, you can securely store your API key using Colab's built-in secrets management system. This feature ensures your API key remains private even when sharing notebooks.
Setting up the Secret¶
- In your Google Colab notebook, click on the "🔑" icon in the left sidebar to open the "Secrets" panel
- Click on "Add new secret"
- Set the following:
- Name:
COMET_API_KEY
- Value: Your Comet API key
- Name:
- Click "Add new secret"
Note
- Secrets are global and available across all your notebooks, but you need to explicitly grant access to each notebook that needs to use them
- Once set, the secret name cannot be changed, but you can update its value
Using the Secret in Your Code¶
You can access your API key in your notebook using the userdata
module. Here's how to use it with Comet:
1 2 3 4 5 6 7 8 9 10 11 |
|
Alternatively, you can pass the API key directly to comet_ml.start
:
1 2 3 4 5 6 7 8 |
|
End an Experiment¶
When running Comet in a Notebook, we must end your Experiment explicitly when the training is finished using the comet.end()
method:
1 |
|
When as experiment is ended, Comet will finish uploading all remaining data as well as all the code cells that where executed before returning.