Python Panels
This page presents specifics about working with Python Panels.
General instructions for creating Python and JavaScript Panels are here.
When writing a Python Panel, you can use all of the standard data science Python modules, including: comet_ml
, matplotlib
, numpy
, pandas
, scikit-learn
, seaborn
, and scipy
.
A simple Python Panel¶
Get a feel for Python Panels with this simple example.
Enter the following code in the Code tab:
from comet_ml import ui
ui.display("My first Python Panel!")
Click Run to display the output in the Panel Preview area on the right-hand side.
To display items on the Panel canvas, you need to import the comet_ml.ui
library, and call ui.display()
. See ui for addition details on comet_ml.ui.display()
.
Info
Python Panels do not automatically update with new experiments nor upon receiving new logged metrics. This is by design, as your Python Panel may be expensive to compute, and you may not wish to have it automatically refresh whenever new data is received.
See more examples on Python Panels.
Python SDK methods for Python Panels¶
API, ui, and APIExperiment classes in the Python SDK provide methods that you can call in your Pyton Panels code.
API¶
The Comet API class includes a number of methods that are only available within Python Panels:
API.get_panel_options
: The Panel options can be edited when in the Options tab of the Panel Code editor, and set when you are adding a Panel instance to a View.API.get_panel_experiment_keys
: This will return a list containing all of the current Experiment keys. Specifically:- If on a Project View, the Experiment keys from the visible experiment table page.
- If a filter is set, all of the matching Experiments.
- If a filter is set for this Panel, the matching Experiments.
API.get_panel_experiments
: Like theAPI.get_experiment_keys()
method, but returns a list ofAPIExperiment
s rather than just their keys.API.get_panel_project_id
: Get Project ID. That information can be useful to retrieve other Project-level information.API.get_panel_project_name
: Get Project name. That can be useful in creating report-like Panels.API.get_panel_workspace
: Get Workspace name. That can be useful in creating report-like Panels.API.get_panel_metrics_names
: Get the names of all metrics logged for all experiments in this Project.
ui¶
The Comet ui methods can be used within Python Panels to control the rendering of Panels. ui
contains three sets of methods:
- Display methods: To visualize different kinds of Python objects on the Panel canvas area
- Widgets methods: To add interactivity to Panels through elements that have a GUI representation
- Utility methods: To update the styling of Panels
Examples:
To use comet_ml.ui
, you need only import it:
from comet_ml import ui
choice = ui.dropdown("Choose one:", ["A", "B", "C"])
ui.display("You picked", choice)
APIExperiment¶
The Comet APIExperiment methods can be used within Python Panels. All get_*
methods in this class are available in Python Panels. Here are some of the main ones:
APIExperiment.get_asset
: Get an asset.APIExperiment.get_asset_list
: Get a list of assets associated with the Experiment.APIExperiment.get_metadata
: Get the metadata associated with this Experiment.APIExperiment.get_metrics
: Get all of the logged metrics.APIExperiment.get_metrics_summary
: Return the Experiment metrics summary.APIExperiment.get_model_asset_list
: Get an Experiment model's asset list by model name.
Make the most of Python Panels¶
Apply the following guidelines as you create and refine your Python Panels.
Check your browser¶
- You may have to open your browser's web development view to see additional errors.
- If a Panel is reporting an error, it could be caused by using an unsupported browser. Currently Python Panels is known to work under the following browsers:
- Chrome, version 71.0 and greater
- Firefox, version 70.0 and greater
- Edge, version 80 and greater
Print to debug¶
Note that using print
will display items in the Console area (bottom, right-hand corner). This is very useful for debugging.
Use standard Python modules¶
Python Panels allows you to use many other Python support modules, including:
asciitree | atomicwrites | attrs |
beautifulsoup4 | bleach | cloudpickle |
cssselect | cycler | cytoolz |
decorator | distlib | docutils |
freesasa | future | glpk |
html5lib | Jinja2 | imageio |
iniconfig | jedi | joblib |
kiwisolver | libiconv | libxml |
libxslt | libyaml | lxml |
markdown | MarkupSafe | micropip |
mne | more-itertools | mpmath |
msgpack | networkx | nlopt |
nose | numcodecs | optlang |
packaging | parso | patsy |
pluggy | py | Pygments |
pyparsing | pyrtl | pytest |
python-dateutil | python-sat | pytz |
pywavelets | pyyaml | regex |
retrying | setuptools | six |
soupsieve | statsmodels | swiglpk |
sympy | toolz | traits |
typing-extensions | uncertainties | webencodings |
xlrd | yt | zarr |
zlib |
To use a Python package that is not listed here, contact us through our Slack channel -- there might be an easy solution.
Make Python Panels efficient¶
Python Panels run in the browser rather than from a server. That has a number of implications. First, there is a slight overhead to load the libraries needed to execute Python code in the browser. Typically, this delay only occurs when required, typically once per Project or Experiment view. Note also, that Python Panels can use more memory than usual.
To create responsive Python Panels, it is suggested you:
- Limit the number of modules loaded.
- Limit the number of requests (for example,
api.get_
calls). - Limit the amount of information displayed.
The following Python modules are known to require significant load times:
matplotlib
(medium load time)pandas
(large load time)plotly.express
(large load times, as it requirespandas
)
Know the limitations¶
- Python Panels do not automatically update with new Experiments, nor upon receiving new logged metrics. This is by design, as your Python Panel may be expensive to compute, and you may not wish to have it automatically refresh whenever new data is received.
- These are the supported widget types.
- Line numbers in Python's tracebacks are off. See your web browser's console for current line numbers.
- Pandas'
DataFrame.style
is not available. - Vega and Altair are not available (they are still under development).
If you find any additional limitations or have a request, let us know.
Learn more¶
- About Panels
- Python SDK: API
- Python SDK: ui
- Python SDK: APIExperiment
- Examples for Comet Python Panels
- Browse the Comet Panels Gallery