# Run an Experiment in a Jupyter Workspace
Jupyter is one of the best tools for building and developing ML code and with the workspaces feature you can easily use Jupyter backed by remote compute.
When you've worked on your code and want to run an experiment that is tracked by cnvrg, you can easily do so using the Python SDK.
This tutorial will explain run an experiment in a Jupyter workspace.
# Prerequisites
All you will need is an open Jupyter workspace.
# Start an Experiment with Experiment.init()
When you are ready to start an experiment, you will need to import the cnvrg Experiment package and initialize an Experiment object. Run the following code in a cell to get started:
from cnvrg import Experiment
e = Experiment.init()
You will now have created an experiment in your cnvrg project. You will receive a link to the experiment, and you can view the experiment in the experiments sidebar of the workspace. You can now execute cells of your code as desired, but make sure to track your experiment using the Python SDK as explained below.
# Tracking and Visualizing
You will need to use the SDK methods to fully track your experiment. Use the below methods in your code to track the experiment as you execute each relevant cell.
# Track logs
To save logs in your experiment, use the e.log()
method. For example:
e.log("Experiment started")
Anything in this method will be saved as part of the logs in your cnvrg experiment.
# Track parameters
To track a parameter in your experiment, use the e.log_param()
method. For example:
e.log_param("tag_key", "tag_value")
This will save a parameter as metadat on your experiment, which can then be search, sorted and compared by.
# Create graphs
You can create graphs using the e.log_metric()
(line graphs) and e.log_chart()
(confusion matrices, scatter graphs and bar graphs) methods. For example:
e.log_metric("chart_name",
Ys=[0.1, 0.2, 0.3],
Xs=[1,2,3])
The documentation on how to use the SDK's methods for tracking and visualizing, can be found here.
# Experiment artifacts
To save and version an experiment artifact, use the e.log_artifacts()
method. For example:
e.log_artifacts(["output1.h5", "plots.pdf"])
Use this to track models and other artifacts alongside your experiment.
# Finishing the Experiment
When you have executed the cells and code of your experiment, it is time to tell cnvrg that the experiment is over. Use e.finish()
to do so. For example:
e.finish(exit_status=0)
You can set other exit statuses if needed.
# Summary
To run an experiment in Jupyter. Just make sure you follow these simple guidelines:
- Use
e = Experiment.init()
to start an experiment. - Run your code and track it using the SDK.
- Finish your experiment with
e.finish()
.