Python Panels SDK APIExperiment

This page documents the comet_ml.APIExperiment for Comet Python Panels.

Other Python Panel Resources:


APIExperiment

The APIExperiment class is used to access data from the Comet.ml Python API.

You can use an instance of the APIExperiment() class to easily access all of your logged experiment information at Comet.ml, including metrics, parameters, tags, and assets.

Examples:

The following examples assume your COMET_API_KEY is configured as per Python Configuration.

This example shows looking up an experiment by its URL:

>>> from comet_ml.api import API, APIExperiment

## (assumes api keys are configured):
>>> api = API() # can also: API(api_key="...")

## Get an APIExperiment from the API:
>>> experiment = api.get("cometpublic/comet-notebooks/example 001")

For more usage examples, see Comet Python API examples.

It is best not to call this constructor directly but to use an API method such as:

experiment = api.get_experiment_by_key(KEY)

APIExperiment.name

Get the name of the experiment.

Example:

experiment = api.get_experiment_by_key(KEY)
print(experiment.name)

APIExperiment.url

Get the url of the experiment.

Example:

>>> api_experiment.url
"https://www.comet.ml/username/34637643746374637463476"

APIExperiment.__init__

__init__(self, *args, **kwargs)

Use a previous experiment key to access an existing experiment. Note that Comet does not support creating/editing experiments from with Python Panels. To create new experiments via the Python API, see the Python SDK

Examples:

# Python API to create a new experiment:
# (assumes api keys are configured):
>>> experiment = APIExperiment(workspace=WORKSPACE,
  project_name=PROJECT)

# Python API to access an existing experiment:
>>> experiment = APIExperiment(previous_experiment=EXPERIMENT_KEY)

Note: api_keys are set on Panels by default fo


APIExperiment.get_additional_system_info

get_additional_system_info(self)

Get the associated additional system info for this experiment.

Example:

>>> api_experiment.get_additional_system_info()
[]

APIExperiment.get_asset

get_asset(self, asset_id, return_type="binary")

Get an asset, given the asset_id.

Args:

  • asset_id: the asset ID
  • return_type: the type of object returned. Default is "binary". Options: "binary" or "text"

Example:

>>> api_experiment.get_asset("298378237283728", return_type="json")
{...}

APIExperiment.get_asset_list

get_asset_list(self, asset_type="all")

Get a list of assets associated with the experiment.

Args:

  • asset_type: Optional String, type of asset to return. Can be "all", "image", "histogram_combined_3d", "video", or "audio".

Returns a list of dictionaries of asset properties, like:

>>> from comet_ml.api import API
>>> api = API()
>>> x = api.get("myworkspace/project1/experiment_key")
>>> x.get_asset_list()
[{'fileName': 'My Filename.png',
'fileSize': 21113,
'runContext': None,
'step': None,
'link': 'https://www.comet.ml/api/asset/download?experimentKey=KEY&assetId=ASSET_ID',
'createdAt': 1565898755830,
'dir': 'assets',
'canView': False,
'audio': False,
'video': False,
'histogram': False,
'image': True,
'type': 'image',
'metadata': None,
'assetId': ASSET_ID}, ...]

>>> x.get_asset_list("image")
[{'fileName': 'My Filename.png',
'fileSize': 21113,
'runContext': None,
'step': None,
'link': 'https://www.comet.ml/api/asset/download?experimentKey=KEY&assetId=ASSET_ID',
'createdAt': 1565898755830,
'dir': 'assets',
'canView': False,
'audio': False,
'video': False,
'histogram': False,
'image': True,
'type': 'image',
'metadata': None,
'assetId': ASSET_ID}, ...]

APIExperiment.get_code

get_code(self)

Get the associated source code for this experiment.

Example:

>>> api_experiment.get_code()
'import comet_ml
experiment = comet_ml.Experiment()
experiment.end()'

APIExperiment.get_command

get_command(self)

Get the associated command-line script and args for this experiment.

Example:

>>> api_experiment.get_command()
['keras.py', '--size', '1024', '--log', 'experiment.log']

APIExperiment.get_curves

get_curves(self)

Get all curve assets as JSON.

Example:

>>> api_experiment.get_curves()
[...]

APIExperiment.get_environment_details

get_environment_details(self)

Deprecated. Use APIExperiment.get_os_packages() instead.


APIExperiment.get_executable

get_executable(self)

Get the associated executable for this experiment.

Example:

>>> api_experiment.get_executable()
'/usr/local/bin/python'

APIExperiment.get_gpu_static_info

get_gpu_static_info(self)

Get the system details associated with this experiment.


APIExperiment.get_hostname

get_hostname(self)

Get the system details associated with this experiment.


APIExperiment.get_html

get_html(self)

Get the HTML associated with this experiment.

Example:

>>> api_experiment.get_html()
"<b>Hello, world!</b>"

APIExperiment.get_images

get_images(self)

Get all image assets as bytes.

Example:

>>> api_experiment.get_images()
[...]

APIExperiment.get_installed_packages

get_installed_packages(self)

Get the associated installed packages for this experiment.

Example:

>>> api_experiment.get_installed_packages()
['absl-py==0.8.1', 'adal==1.2.2', 'alabaster==0.7.12', ...]

APIExperiment.get_ip

get_ip(self)

Get the associated IP for this experiment.

Example:

>>> api_experiment.get_ip()
'175.29.200.91'

APIExperiment.get_machine

get_machine(self)

Get the associated total RAM for this experiment.

Example:

>>> api_experiment.get_machine()
'AMD64'

APIExperiment.get_max_memory

get_max_memory(self)

Get the associated max total memory for this experiment.

Example:

>>> api_experiment.get_max_memory()
1024

APIExperiment.get_metadata

get_metadata(self)

Get the metadata associated with this experiment.

Example:

>>> api = API(...)
>>> api_experiment = APIExperiment(API=api, experiment_key="EXPERIMENT-KEY")
>>> api_experiment.get_metadata()
{
  "archived": False,
  "durationMillis": 7,
  "endTimeMillis": 1586174765277,
  "experimentKey": "EXPERIMENT-KEY",
  "experimentName": None,
  "fileName": None,
  "filePath": None,
  "optimizationId": None,
  "projectId": "PROJECT-ID",
  "projectName": "PROJECT-NAME",
  "running": False,
  "startTimeMillis": 1586174757596,
  "throttle": False,
  "workspaceName": "WORKSPACE-NAME",
}

To assign metadata to a variable, use await:
>>> meta = api_experiment.get_metadata()
>>> print(meta)

APIExperiment.get_metrics

get_metrics(self, metric=None)

Get all of the logged metrics. Optionally, just get the given metric name.

Args:

  • metric: Optional. String. If given, filter the metrics by name.

Example:

>>> api = API(...)
>>> x = api.get("myworkspace/project1/experiment_key")

>>> x.get_metrics()
[{"metricName": "val_loss",
"metricValue": "0.13101346811652184",
"timestamp": 1558962376383,
"step": 1500,
"epoch": None,
"runContext": None},
{"metricName": "acc",
"metricValue": "0.876",
"timestamp": 1564536453647,
"step": 100,
"epoch": None,
"runContext": None},
...]

>>> x.get_metrics("acc")
[{"metricName": "acc",
"metricValue": "0.876",
"timestamp": 1564536453647,
"step": 100,
"epoch": None,
"runContext": None},
...]

APIExperiment.get_metrics_summary

get_metrics_summary(self, metric=None)

Return the experiment metrics summary. Optionally, also if you provide the metric name, the function will only return the summary of the metric.

Args:

  • metric: optional (string), name of a metric

Examples:

>>> api = API(...)
>>> x = api.get("myworkspace/project1/experiment_key")
>>> x.get_metrics_summary()
[{"name": "val_loss",
"valueMax": "0.24951280827820302",
"valueMin": "0.13101346811652184",
"valueCurrent": "0.13101346811652184",
"timestampMax": 1558962367938,
"timestampMin": 1558962367938,
"timestampCurrent": 1558962376383,
"stepMax": 500,
"stepMin": 1500,
"stepCurrent": 1500},
...]

>>> api.get_metrics_summary("val_loss")
{"name": "val_loss",
"valueMax": "0.24951280827820302",
"valueMin": "0.13101346811652184",
"valueCurrent": "0.13101346811652184",
"timestampMax": 1558962367938,
"timestampMin": 1558962367938,
"timestampCurrent": 1558962376383,
"stepMax": 500,
"stepMin": 1500,
"stepCurrent": 1500}

APIExperiment.get_model_asset_list

get_model_asset_list(self, model_name)

Get an experiment model's asset list by model name.

Args:

  • model_name: str, the name of the model

Returns: a list of asset dictionaries with these fields:

  • fileName
  • fileSize
  • runContext
  • step
  • link
  • createdAt
  • dir
  • canView
  • audio
  • histogram
  • image
  • type
  • metadata
  • assetId

Example:

>>> from comet_ml import API
>>> api = API()
>>> api_exp = api.get("workspace/project/765643463546345364536453436")
>>> api_exp.get_model_asset_list("Model Name")
[
{
  "assetId": 74374637463476,
  "audio": False,
  "canView": False,
  "createdAt": 7337347634,
  "dir": "trained-models",
  "fileName": "model.h5",
  "fileSize": 254654,
  "histogram": False,
  "image": False,
  "link": "https://link-to-download-asset-file",
  "metadata": None,
  "remote": False,
  "runContext": "train",
  "step": 54,
  "type": "asset",
}
]

APIExperiment.get_model_data

get_model_data(self, name)

Deprecated. Use APIExperiment.get_model_asset_list(model_name) instead.


APIExperiment.get_model_graph

get_model_graph(self)

Get the associated graph/model description for this experiment.

Example:

>>> api_experiment.get_model_graph()
{"class_name": "Sequential", ...}

APIExperiment.get_model_names

get_model_names(self)

Get a list of model names associated with this experiment.

Returns: list of model names


APIExperiment.get_name

get_name(self)

Get the name of the experiment, if one.

Example:

>>> api_experiment.get_name()
"My Name"

APIExperiment.get_network_interface_ips

get_network_interface_ips(self)

Get the associated network interface IPs for this experiment.

Example:

>>> api_experiment.get_network_interface_ips()
['127.0.0.1', '10.0.0.71', ...]

APIExperiment.get_os

get_os(self)

Get the associated OS for this experiment.

Example:

>>> api_experiment.get_os()
'Linux-4.15.0-1059-oem-x86_64-with-Ubuntu-18.04-bionic'

APIExperiment.get_os_packages

get_os_packages(self)

Get the OS packages for this experiment.

Example:

>>> api_experiment.get_os_packages()
['accountsservice=0.6.45-1ubuntu1', 'acl=2.2.52-3build1', 'acpi-support=0.142', ...]

APIExperiment.get_os_release

get_os_release(self)

Get the associated OS release for this experiment.

Example:

>>> api_experiment.get_os_release()
'8'

APIExperiment.get_os_type

get_os_type(self)

Get the associated os type for this experiment.

Example:

>>> api_experiment.get_os_type()
'Linux'

APIExperiment.get_others_summary

get_others_summary(self, other=None)

Get the other items logged in summary form.

Args:

  • other: optional, string, the name of the other item logged. If given, return the valueCurrent of the other item. Otherwise, return all other items logged.

Examples:

>>> api = API(...)
>>> x = api.get("myworkspace/project1/experiment_key")
>>> x.get_others_summary()
[{"name": "trainable_params",
"valueMax": "712723",
"valueMin": "712723",
"valueCurrent": "712723",
"timestampMax": 1558962363411,
"timestampMin": 1558962363411,
"timestampCurrent": 1558962363411},
...]

>>> x.get_others_summary("trainable_params")
["712723"]

APIExperiment.get_parameters_summary

get_parameters_summary(self, parameter=None)

Return the experiment parameters summary. Optionally, also if you provide a parameter name, the method will only return the summary of the given parameter.

Args:

  • parameter: optional (string), name of a parameter

Examples:

>>> api = API(...)
>>> x = api.get("myworkspace/project1/experiment_key")
>>> x.get_parameters_summary()
[{"name": "batch_size",
"valueMax": "120",
"valueMin": "120",
"valueCurrent": "120",
"timestampMax": 1558962363411,
"timestampMin": 1558962363411,
"timestampCurrent": 1558962363411},
...]

>>> x.get_parameters_summary("batch_size")
{"name": "batch_size",
"valueMax": "120",
"valueMin": "120",
"valueCurrent": "120",
"timestampMax": 1558962363411,
"timestampMin": 1558962363411,
"timestampCurrent": 1558962363411}

APIExperiment.get_pid

get_pid(self)

Get the pid for this experiment.

Example:

>>> api_experiment.get_pid()
34658

APIExperiment.get_processor

get_processor(self)

Get the associated total RAM for this experiment.

Example:

>>> api_experiment.get_processor()
'Intel64 Family 6 Model 60 Stepping 3, GenuineIntel

APIExperiment.get_python_version

get_python_version(self)

Get the Python version for this experiment.

Example:

>>> api_experiment.get_python_version()
'3.6.8'

APIExperiment.get_python_version_verbose

get_python_version_verbose(self)

Get the Python version verbose for this experiment.

Example:

>>> api_experiment.get_python_version_verbose()
'3.6.8 (default, Oct  7 2019, 12:59:55) 
[GCC 8.3.0]'

APIExperiment.get_tags

get_tags(self)

Get the associated tags for this experiment.

Example:

>>> api_experiment.get_tags()
["best"]

APIExperiment.get_total_memory

get_total_memory(self)

Get the associated total RAM for this experiment.

Example:

>>> api_experiment.get_total_memory()
1024

APIExperiment.get_user

get_user(self)

Get the associated user for this experiment.

Example:

>>> api_experiment.get_user()
'usename'