Skip to content

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, 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")

You can also make a new experiment using the API:

## Make a new APIExperiment (assumes api keys are configured):
>>> experiment = APIExperiment(workspace="my-username",
                               project_name="general")

Here is an end-to-end snippet to rename a metric. You can use this basic structure for logging new metrics (after the experiment has completed) such as averages or scaling to a baseline.

from comet_ml import API

WORKSPACE = "your-comet-id"
PROJECT_NAME = "general"
EXP_KEY = "your-experiment-key"
OLD_METRIC_NAME = "loss"
NEW_METRIC_NAME = "train_loss"

api = API() # can also: API(api_key="...")

experiment = api.get_experiment(WORKSPACE, PROJECT_NAME, EXP_KEY)
old_metrics = experiment.get_metrics(OLD_METRIC_NAME)

for old_metric in old_metrics:
    experiment.log_metric(
        NEW_METRIC_NAME,
        old_metric["metricValue"],
        step=old_metric["step"],
        timestamp=old_metric["timestamp"],
    )

For more usage examples, see Comet Python API examples.

APIExperiment.init

__init__(*args, **kwargs)

Create a new APIExperiment, or use a previous experiment key to access an existing experiment.

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:
# (assumes api keys are configured):
>>> experiment = APIExperiment(previous_experiment=EXPERIMENT_KEY)
  • Note: api_key may be defined in environment (COMET_API_KEY) or in a .comet.config file. Additional arguments will be given to API().

APIExperiment.add_tag

add_tag(tag)

Append onto an experiment's list of tags.

Args:

  • tag: a tag (string)

Example:

>>> api_experiment.add_tag("baseline")

APIExperiment.add_tags

add_tags(tags)

Append onto an experiment's list of tags.

Args:

  • tags: a list of tags (strings)

Example:

>>> api_experiment.add_tags(["successful", "best"])

APIExperiment.archive

archive()

Archive this experiment.

Example:

>>> api_experiment.archive()
create_symlink(project_name)

Create a copy of this experiment in another project in the workspace.

Args:

  • project_name: the name of the project with which to create a symlink to this experiment in.

Example:

>>> api_experiment.create_symlink("my-other-project")

APIExperiment.delete_asset

delete_asset(asset_id)

Delete an experiment's asset.

Args:

  • asset_id: the asset id of the asset to delete

APIExperiment.delete_tags

delete_tags(tags: List[str])

Delete from an experiment the list of tags.

Args:

  • tags: a list of tags (strings)

Example:

>>> api_experiment.delete_tags(["successful", "best"])

APIExperiment.display

display(clear=False, wait=True, new=0, autoraise=True, tab=None)

Show the Comet.ml experiment page in an IFrame in a Jupyter notebook or Jupyter lab, OR open a browser window or tab.

Common Args: tab: name of the Tab on Experiment View

Note: the Tab name should be one of: * "artifacts" * "assets" * "audio" * "charts" * "code" * "confusion-matrices" * "histograms" * "images" * "installed-packages" * "metrics" * "notes" * "parameters" * "system-metrics" * "text"

For Jupyter environments:

Args:

  • clear: to clear the output area, use clear=True
  • wait: to wait for the next displayed item, use wait=True (cuts down on flashing)

For non-Jupyter environments:

Args:

  • new: open a new browser window if new=1, otherwise re-use existing window/tab
  • autoraise: make the browser tab/window active

APIExperiment.display_project

display_project(view_id=None, clear=False, wait=True, new=0, autoraise=True)

Show the Comet.ml project page in an IFrame in a Jupyter notebook or Jupyter lab, OR open a browser window or tab.

Common Args: view_id: (optional, string) the id of the view to show

For Jupyter environments:

Args:

  • clear: to clear the output area, use clear=True
  • wait: to wait for the next displayed item, use wait=True (cuts down on flashing)

For non-Jupyter environments:

Args:

  • new: open a new browser window if new=1, otherwise re-use existing window/tab
  • autoraise: make the browser tab/window active

APIExperiment.download_model

download_model(name, output_path="./", expand=True)

Download and save all files from the model.

Args:

  • model_name: str, the name of the model
  • output: str, the output directory; defaults to current directory
  • expand: if True, the downloaded zipfile is unzipped; if False, then the zipfile is copied to the output_path

APIExperiment.download_tensorflow_folder

download_tensorflow_folder(output_path="./", overwrite=False)

Download all files logged with Experiment.log_tensorflow_folder(FOLDER).

Args:

  • output_path: (str) where to download the files
  • overwrite: (bool) if True, then overwrite any file that exists

Example:

>>> experiment = comet_ml.Experiment()
>>> experiment.log_tensorboard_folder("logs")
>>> api = comet_ml.API()
>>> api_experiment = api.get_experiment_by_id(experiment.id)
>>> api_experiment.download_tensorflow_folder()

APIExperiment.end

end()

Method called at end of experiment.

APIExperiment.get_additional_system_info

get_additional_system_info()

Get the associated additional system info for this experiment.

Example:

>>> api_experiment.get_additional_system_info()
[]

APIExperiment.get_asset

get_asset(asset_id, return_type="binary", stream=False)

Get an asset, given the asset_id.

Args:

  • asset_id: (str) the asset ID
  • return_type: (str) the type of object returned. Default is "binary". Options: "binary", "json", or "response"
  • stream: (bool) when return_type is "response", you can also use stream=True to use the response as a stream

Examples:

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

To use with the streaming option:

>>> asset_response = api_experiment.get_asset(
...     "298378237283728",
...     return_type="response",
...     stream=True,
... )
>>> with open(filename, 'wb') as fd:
>>>     for chunk in asset_response.iter_content(chunk_size=1024*1024):
>>>         fd.write(chunk)

APIExperiment.get_asset_by_name

get_asset_by_name(asset_filename, asset_type="all", return_type="binary",
    stream=False)

Get an asset, given the asset filename.

Args:

  • asset_filename: (str) the asset filename
  • asset_type: Optional String, type of asset to return. Can be "all", "image", "histogram_combined_3d", "video", or "audio".
  • return_type: (str) the type of object returned. Default is "binary". Options: "binary", "json", or "response"
  • stream: (bool) when return_type is "response", you can also use stream=True to use the response as a stream

Notes: will return the first asset found, if there are more than one with the same name. If you give the asset_type, the function will run faster. If no asset is found, then the method returns None.

Examples:

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

APIExperiment.get_asset_list

get_asset_list(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.com/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.com/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()

Get the associated source code for this experiment.

Example:

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

APIExperiment.get_command

get_command()

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_curve

get_curve(asset_id)

Get curve logged with experiment by asset id.

Example:

>>> api_experiment.get_curve("57457745745745774")
{"name": "curve1", "x": [1, 2, 3], "y": [4, 5, 6], "step": 0}

APIExperiment.get_curves

get_curves()

Get all curves logged with experiment.

Example:

>>> api_experiment.get_curves()
[{"name": "curve1", "x": [1, 2, 3], "y": [4, 5, 6], "step": 0}]

APIExperiment.get_environment_details

get_environment_details()

Deprecated. Use APIExperiment.get_os_packages() instead.

APIExperiment.get_executable

get_executable()

Get the associated executable for this experiment.

Example:

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

APIExperiment.get_git_metadata

get_git_metadata()

Get the git-metadata associated with this experiment.

Example:

>>> api_experiment.get_git_metadata()
{
    "branch": 'refs/heads/master',
    "origin": 'git@github.com:comet-ml/comet-examples.git',
    "parent": '96ff529b4c02e4e0bb92992a7c4ce81275985764',
    "root": 'eec2d16daa057d0cf4c2c49974e6ea51e732a7b2',
    "user": 'user',
}

APIExperiment.get_git_patch

get_git_patch()

Get the git-patch associated with this experiment as a zipfile containing a unique file named zip_file.patch.

Example:

>>> import io, zipfile
>>> zip_patch = io.BytesIO(api_experiment.get_git_patch())
>>> archive = zipfile.ZipFile(zip_patch)
>>> patch = archive.read("git_diff.patch")
>>> patch
b'...'

APIExperiment.get_gpu_static_info

get_gpu_static_info()

Get the associated GPU static info for this experiment.

Example:

>>> api_experiment.get_gpu_static_info()
[{
    "gpuIndex": 0,
    "name": "GeForce GTX 950",
    "uuid": "GPU-cb6c1b39-5a56-6d79-8899-3796f23c6425",
    "totalMemory": 2090074112,
    "powerLimit": 110000,
}, ...]

APIExperiment.get_hostname

get_hostname()

Get the associated hostname for this experiment.

Example:

>>> api_experiment.get_hostname()
'name-of-computer-host'

APIExperiment.get_html

get_html()

Get the HTML associated with this experiment.

Example:

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

APIExperiment.get_installed_packages

get_installed_packages()

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()

Get the associated IP for this experiment.

Example:

>>> api_experiment.get_ip()
'175.29.200.91'

APIExperiment.get_machine

get_machine()

Get the associated total RAM for this experiment.

Example:

>>> api_experiment.get_machine()
'AMD64'

APIExperiment.get_max_memory

get_max_memory()

Get the associated max total memory for this experiment.

Example:

>>> api_experiment.get_max_memory()
1024

APIExperiment.get_metadata

get_metadata()

Get the metadata associated with this experiment.

Example:

>>> from comet_ml import APIExperiment
>>> api_experiment = APIExperiment(previous_experiment='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',
}

APIExperiment.get_metrics

get_metrics(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:

>>> from comet_ml.api import API
>>> 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(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:

>>> from comet_ml.api import API
>>> 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(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(name)

Deprecated. Use APIExperiment.get_model_asset_list(model_name) instead.

APIExperiment.get_model_graph

get_model_graph()

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()

Get a list of model names associated with this experiment.

Returns: list of model names

APIExperiment.get_name

get_name()

Get the name of the experiment, if one.

Example:

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

APIExperiment.get_network_interface_ips

get_network_interface_ips()

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()

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()

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()

Get the associated OS release for this experiment.

Example:

>>> api_experiment.get_os_release()
'8'

APIExperiment.get_os_type

get_os_type()

Get the associated os type for this experiment.

Example:

>>> api_experiment.get_os_type()
'Linux'

APIExperiment.get_others_summary

get_others_summary(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:

>>> from comet_ml.api import API
>>> 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_output

get_output()

Get the associated standard output for this experiment.

Example:

>>> api_experiment.get_output()
"Experiment is live"

APIExperiment.get_parameters_summary

get_parameters_summary(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:

>>> from comet_ml.api import API
>>> 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()

Get the pid for this experiment.

Example:

>>> api_experiment.get_pid()
34658

APIExperiment.get_processor

get_processor()

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()

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()

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) \n[GCC 8.3.0]'

APIExperiment.get_state

get_state() -> str

Get current state of experiment. Returns: 'running', 'finished' or 'crashed'

APIExperiment.get_system_details

get_system_details()

Get the system details associated with this experiment.

Returns a dictionary like:

{
  "experimentKey": "someExperimentKey",
  "user": "system username"
  "pythonVersion": "python version"
  "pythonVersionVerbose": "python version with verbose flag"
  "pid": <Integer, pid>,
  "osType": "os experiment ran on",
  "os": "os with version info",
  "ip": "ip address",
  "hostname": "hostname",
  "gpuStaticInfoList": [
    {
      "gpuIndex": <Integer, index>,
      "name": "name",
      "uuid": "someUniqueId",
      "totalMemory": <Integer, total memory>,
      "powerLimit": <Integer, max power>
    }
  ],
  "logAdditionalSystemInfoList": [
    {
      "key": "someKey",
      "value": "someValue"
    }
  ],
  "systemMetricNames": ["name", "anotherName"],
  "maxTotalMemory": <double, max memory used>,
  "networkInterfaceIps": ["ip", "anotherIp"]
  "command": ["part1", "part2"],
  "executable": "The python Exe, if any (in future could be non python executables)",
  "osPackages": ["package", "anotherPackage"],
  "installedPackages": ["package", "anotherPackage"]
}

APIExperiment.get_system_metric_names

get_system_metric_names()

Get the associated system metric names for this experiment.

Example:

>>> api_experiment.get_system_metric_names()
['sys.cpu.percent.03', 'sys.cpu.percent.02', 'sys.cpu.percent.01', ...]

APIExperiment.get_tags

get_tags()

Get the associated tags for this experiment.

Example:

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

APIExperiment.get_total_memory

get_total_memory()

Get the associated total RAM for this experiment.

Example:

>>> api_experiment.get_total_memory()
1024

APIExperiment.get_user

get_user()

Get the associated user for this experiment.

Example:

>>> api_experiment.get_user()
'usename'

APIExperiment.key

key()

Get the experiment key (the unique id).

Example:

>>> api_experiment.key
"34637643746374637463476"

APIExperiment.log_additional_system_info

log_additional_system_info(key, value)

Log additional system information for this experiment.

Args:

  • key: (string) the name for this system information
  • value: (any type), the value of the system information

Example:

>>> experiment.log_additional_system_info("some name": 42)

APIExperiment.log_asset

log_asset(filename, step=None, name=None, overwrite=None, context=None,
    ftype=None, metadata=None)

Upload an asset to an experiment.

Args:

  • filename: the name of the asset file to upload
  • step: the current step
  • overwrite: if True, overwrite any previous upload
  • context: the current context (e.g., "train" or "test")
  • ftype: the type of asset (e.g., "image", "histogram_combined_3d", "image", "audio", or "video")
  • metadata: a JSON object to attach to image

Note: don't delete the file until upload is complete

Example:

>>> api_experiment.log_asset("histogram.json", ftype="histogram_compbined_3d")

APIExperiment.log_cpu_metrics

log_cpu_metrics(cpu_metrics, context=None, step=None, epoch=None,
    timestamp=None)

Log an instance of cpu_metrics.

Args:

  • cpu_metrics: a list of integer percentages, ordered by cpu
  • context: optional, a run context
  • step: optional, the current step
  • epoch: optional, the current epoch
  • timestamp: optional, current time, in milliseconds

Example:

# Four CPUs:
>>> api_experiment.log_cpu_metrics([25, 50, 10, 45])

APIExperiment.log_curve

log_curve(name, x, y, overwrite=False, step=None)

Log timeseries data.

Args:

  • name: (str) name of data
  • x: list of x-axis values
  • y: list of y-axis values
  • overwrite: (optional, bool) if True, overwrite previous log
  • step: (optional, int) the step value

Examples:

>>> experiment.log_curve("my curve", x=[1, 2, 3, 4, 5],
                                     y=[10, 20, 30, 40, 50])
>>> experiment.log_curve("my curve", [1, 2, 3, 4, 5],
                                     [10, 20, 30, 40, 50])

APIExperiment.log_gpu_metrics

log_gpu_metrics(gpu_metrics)

Log an instance of gpu_metrics.

Args:

  • gpu_metrics: a list of dicts with keys:
  • gpuId: required, Int identifier
  • freeMemory: required, Long
  • usedMemory: required, Long
  • gpuUtilization: required, Int percentage utilization
  • totalMemory: required, Long

Example:

>>> api_experiment.log_gpu_metrics([{
...        "gpuId": 1,
...        "freeMemory": 1024,
...        "usedMemory": 856,
...        "gpuUtilization": 25,
...        "totalMemory": 2056,
... }])

APIExperiment.log_html

log_html(html, clear=False, timestamp=None)

Set, or append onto, an experiment's HTML.

Args:

  • html: (string) the HTML text to associate with this experiment
  • clear: (optional, boolean) if True, clear any previously logged HTML
  • timestamp: (optional, number) the current time (in milliseconds)

Example:

>>> api_experiment.log_html("<b>Hello!</b>")

APIExperiment.log_image

log_image(filename: str, image_name: Optional[str] = None,
    step: Optional[int] = None, overwrite: Optional[bool] = None,
    context: Optional[str] = None, metadata: Optional[Dict[str,
    Any]] = None) -> Dict[str, Any]

Upload an image asset to an experiment.

Args:

  • filename: the name of the image file to upload
  • image_name: the name of the image
  • step: the current step
  • overwrite: if True, overwrite any previous upload
  • context: the current context (e.g., "train" or "test")
  • metadata: Some additional data to attach to the image. Must be a JSON-compatible dict.

Note: don't delete the file until upload is complete

Example:

>>> api_experiment.log_image("image.png", "Weights")

APIExperiment.log_load_metrics

log_load_metrics(load_avg, context=None, step=None, epoch=None,
    timestamp=None)

Log an instance of system load metrics.

Args:

  • load_avg: required, the load average
  • context: optional, the run context
  • step: optional, the current step
  • epoch: optional, the current epoch
  • timestamp: optional, the current timestamp in milliseconds

Example:

>>> api_experiment.log_load_metrics(1.5, "validate", 100, 25, 65364346)

APIExperiment.log_metric

log_metric(metric: str, value: Any, step: Optional[int] = None,
    epoch: Optional[int] = None, timestamp: Optional[int] = None)

Set a metric name/value pair for an experiment.

Args:

  • metric: string, the name of the metric
  • value: any type, the value of the metric
  • step: optional integer, the current step
  • epoch: optional integer, the current epoch
  • timestamp: optional, the current timestamp in milliseconds

Example:

>>> api_experiment.log_metric("loss", 0.698)

APIExperiment.log_metrics

log_metrics(metric_dict: Dict[str, Any], step: Optional[int] = None,
    epoch: Optional[int] = None, timestamp: Optional[int] = None)

Set a dictionary of metric name/value pairs for an experiment.

Args:

  • metric_dict: dict in the form of {"metric_name": value, ...}
  • step: optional integer, the current step
  • epoch: optional integer, the current epoch
  • timestamp: optional, the current timestamp in milliseconds

Example:

>>> api_experiment.log_metrics({"loss": 0.698, "accuracy": 0.12})
[...]

APIExperiment.log_other

log_other(key, value, timestamp=None)

Set another key/value pair for an experiment.

Args:

  • key: string, the name of the other information
  • value: any type, the value of the other information
  • timestamp: optional, the current timestamp in milliseconds

Example:

>>> api_experiment.log_other("key", value)

APIExperiment.log_output

log_output(output, context=None, stderr=False, timestamp=None)

Log output line(s).

Args:

  • output: string representing standard output or error
  • context: optional, the run context
  • stderr: optional, boolean, if True, the lines are standard errors
  • timestamp: optional, the current timestamp in milliseconds

Example:

>>> api_experiment.log_output("output line 1\noutput line 2")

APIExperiment.log_parameter

log_parameter(parameter, value, step=None, timestamp=None)

Set a parameter name/value pair for an experiment.

Args:

  • parameter: string, the name of the parameter
  • value: any type, the value of the parameter
  • step: optional integer, the current step
  • timestamp: optional, the current timestamp in milliseconds

Example:

>>> api_experiment.log_parameter("hidden_layer_size", 64)

APIExperiment.log_parameters

log_parameters(param_dict: Any, step: Optional[int] = None,
    timestamp: Optional[int] = None, nested_support: bool = True)

Set a dictionary of parameter name/value pairs for an experiment.

Args:

  • param_dict: dict in the form of {"param_name": value, ...}
  • step: optional integer, the current step
  • timestamp: optional, the current timestamp in milliseconds
  • nested_support: boolean, support nested parameters

Example:

>>> api_experiment.log_parameters({"learning_rate": 0.12, "layers": 3})
[...]

APIExperiment.log_ram_metrics

log_ram_metrics(total_ram, used_ram, context=None, step=None, epoch=None,
    timestamp=None)

Log an instance of RAM metrics.

Args:

  • total_ram: required, total RAM available
  • used_ram: required, RAM used
  • context: optional, the run context
  • step: optional, the current step
  • epoch: optional, the current epoch
  • timestamp: optional, the current timestamp in millisconds

Example:

>>> api_experiment.log_ram_metrics(1024, 865, "train", 100, 1, 3645346534)

APIExperiment.log_table

log_table(filename, tabular_data=None, headers=False, **format_kwargs)

Log tabular data, including data, csv files, tsv files, and Pandas dataframes.

Args:

  • filename: str (required), a filename ending in ".csv", or ".tsv" (for tablular data) or ".json", ".csv", ".md", or ".html" (for Pandas dataframe data).
  • tabular_data: (optional) data that can be interpreted as 2D tabular data or a Pandas dataframe).
  • headers: bool or list, if True, will add column headers automatically if tabular_data is given; if False, no headers will be added; if list then it will be used as headers. Only useful with tabular data (csv, or tsv).
  • format_kwargs: (optional keyword arguments), when passed a Pandas dataframe these keyword arguments are used in the conversion to "json", "csv", "md", or "html". See Pandas Dataframe conversion methods (like to_json()) for more information.

See also:

Examples:

>>> api_experiment.log_table("vectors.tsv",
...                      [["one", "two", "three"],
...                       [1, 2, 3],
...                       [4, 5, 6]],
...
>>> api_experiment.log_table("dataframe.json", pandas_dataframe)

APIExperiment.name

name()

Get the experiment name.

Example:

>>> api_experiment.name
"laughing_toaster_23454"

APIExperiment.name

name(value)

Set the experiment name in this APIExperiment instance.

Example:

>>> api_experiment.name = "my-preferred-name"
  • NOTE: setting the name here does not changed the logged experiment name. To change that, use:
api_experiment.log_other("name", "my-preferred-name")

APIExperiment.register_model

register_model(model_name, version=None, workspace=None, registry_name=None,
    public=None, description=None, comment=None, status=None, tags=None,
    stages=None)

Register an experiment model in the workspace registry.

Args:

  • model_name: the name of the experiment model
  • workspace: optional, the name of workspace; defaults to current workspace
  • version: a proper semantic version string; defaults to "1.0.0"
  • registry_name: optional, the name of the registered workspace model, if not provided the model_name will be used instead.
  • public: optional, if True, then the model will be publically viewable
  • description: optional, a textual description of the model
  • comment: optional, a textual comment about the model
  • tags: optional, a list of textual tags such as ["tag1", "tag2"], etc.
  • stages: optional, equivalent to tags, DEPRECATED with newer backend versions
  • status: optional, allowed values are configured at the organization level.

Returns {"registryModelId": "ath6ho4eijaexeShahJ9sohQu", "registryModelItemId": "yoi5saes7ea2vooG2ush1uuwi"} if successful.

APIExperiment.set_code

set_code(code=None, filename=None)

Set the code for this experiment. Pass in either the code as a string, or provide filename.

Args:

  • code: string, optional, the source code for this experiment
  • filename: string, optional, the filename for this experiment

Example:

>>> api_experiment.set_code("import comet_ml\nexperiment = comet_ml.Experiment()")
>>> api_experiment.set_code(filename="script.py")

APIExperiment.set_command

set_command(command_args_list)

Set the command-line (script and args) for this experiment.

Args:

  • command_args_list: list of strings, starting with name of script, and followed by arguments.

Example:

>>> api_experiment.set_command(["script.py", "arg1", "arg2", "--flag", "arg3"])

APIExperiment.set_end_time

set_end_time(end_server_timestamp)

Set the end time of an experiment.

Args:

  • end_server_timestamp: a timestamp in milliseconds

Example:

>>> api_experiment.set_end_time(2652656352)

Note: Time is in milliseconds. If the start time has not been set, it will be set to 1 second before the end time.

APIExperiment.set_executable

set_executable(executable)

Set the executable for this experiment.

Args:

  • executable: string, the python executable

Example:

>>> api_experiment.set_executable("/usr/bin/python3")

APIExperiment.set_filename

set_filename(filename)

Set the path and filename for this experiment.

Args:

  • filename: string, the python path and filename

Example:

>>> api_experiment.set_filename("../src/script.py")

APIExperiment.set_git_metadata

set_git_metadata(user, root, branch, parent, origin)

Set the git metadata for this experiment.

Args:

  • user: (string, required) the name of the git user
  • root: (string, required) the name of the git root
  • branch: (string, required) the name of the git branch
  • parent: (string, required) the name of the git parent
  • origin: (string, required) the name of the git origin

Example:

>>> api_experiment.set_git_metadata("user", "root", "branch", "parent", "origin")

APIExperiment.set_git_patch

set_git_patch(file_data)

Set the git patch for this experiment.

Args:

  • file_data: the contents or filename of the git patch file

Example:

>>> api_experiment.set_git_patch("git.patch")

APIExperiment.set_gpu_static_info

set_gpu_static_info(gpu_static_info)

Set the GPU static info for this experiment.

Args:

  • gpu_static_info: list of dicts containing keys gpuIndex, name, uuid, totalMemory, and powerLimit and their values.

Example:

>>> api_experiment.set_gpu_static_info([{
        "gpuIndex": 0,
        "name": "GeForce GTX 950",
        "uuid": "GPU-cb6c1b39-5a56-6d79-8899-3796f23c6425",
        "totalMemory": 2090074112,
        "powerLimit": 110000,
    }, ...])

APIExperiment.set_hostname

set_hostname(hostname)

Set the hostname for this experiment.

Args:

  • hostname: string, the hostname of the computer the experiment ran on

Example:

>>> api_experiment.set_hostname("machine.company.com")

APIExperiment.set_installed_packages

set_installed_packages(installed_packages)

Set the installed Python packages for this experiment.

Args:

  • installed_packages: list of strings, a list of the installed Python packages

Example:

>>> api_experiment.set_installed_packages(["comet_ml", "matplotlib"])

APIExperiment.set_ip

set_ip(ip)

Set the internet protocol (IP) address for this experiment.

Args:

  • ip: string, the internet protocol address

Example:

>>> api_experiment.set_ip("10.0.0.7")

APIExperiment.set_machine

set_machine(machine)

Set the machine for this experiment.

Args:

  • machine: string, the machine type

Example:

>>> import platform
>>> api_experiment.set_machine(platform.machine())

APIExperiment.set_model_graph

set_model_graph(graph)

Set the model graph for this experiment.

Args:

  • graph: various types, a representation of the model graph

Example:

>>> api_experiment.set_model_graph(model)

APIExperiment.set_name

set_name(name)

Set a name for the experiment. Useful for filtering and searching on Comet.ml. Will shown by default under the Other tab.

Args:

  • name: String. A name for the experiment.

APIExperiment.set_network_interface_ips

set_network_interface_ips(network_interface_ips)

Set the network interface ips for this experiment.

Args:

  • network_interface_ips: list of strings, of local network interfaces

Example:

>>> api_experiment.set_network_interface_ips(["127.0.0.1", "192.168.1.100"])

APIExperiment.set_os

set_os(os)

Set the OS for this experiment.

Args:

  • os: string, the OS platform identifier

Example:

>>> import platform
>>> api_experiment.set_os(platform.platform(aliased=True))

APIExperiment.set_os_packages

set_os_packages(os_packages)

Set the OS packages for this experiment.

Args:

  • os_packages: list of strings, the OS package list

Example:

>>> api_experiment.set_os_packages(['accountsservice=0.6.45-1ubuntu1', ...])

APIExperiment.set_os_release

set_os_release(os_release)

Set the OS release for this experiment.

Args:

  • os_release: string, the OS release

Example:

>>> import platform
>>> api_experiment.set_os_release(platform.uname()[2])

APIExperiment.set_os_type

set_os_type(os_type)

Set the OS type for this experiment.

Args:

  • os_type: string, the OS type

Example:

>>> api_experiment.set_os_type("Linux 2.0.1, Ubuntu 16.10")

APIExperiment.set_pid

set_pid(pid)

Set the process ID for this experiment.

Args:

  • pid: string, the OS process ID

Example:

>>> api_experiment.set_pid(54238)

APIExperiment.set_processor

set_processor(processor)

Set the processor for this experiment.

Args:

  • processor: string, the processor name

Example:

>>> import platform
>>> api_experiment.set_processor(platform.processor())

APIExperiment.set_python_version

set_python_version(python_version)

Set the Python version for this experiment.

Args:

  • python_version: string, the verbose Python version

Example:

>>> api_experiment.set_python_version("3.6.7")

APIExperiment.set_python_version_verbose

set_python_version_verbose(python_version_verbose)

Set the Python version verbose for this experiment.

Args:

  • python_version_verbose: string, the verbose Python version

Example:

>>> api_experiment.set_python_version_verbose("3.6.7, by Anaconda")

APIExperiment.set_start_time

set_start_time(start_server_timestamp)

Set the start time of an experiment.

Args:

  • start_server_timestamp: a timestamp in milliseconds

Example:

>>> api_experiment.set_start_time(2652656352)

Note: Time is in milliseconds. If the end time has not been set it will automatically be set for 1 second after the start time.

APIExperiment.set_state

set_state(state: str)

Set current state of the experiment.

Args:

  • state: String representing new experiment state. Must be either: 'running', 'finished' or 'crashed'

APIExperiment.set_user

set_user(user)

Set the user for this experiment.

Args:

  • user: string, the OS username

Example:

>>> api_experiment.set_user("os-user-name")

APIExperiment.to_json

to_json(full=False)

The experiment data in JSON-like format.

Args:

  • full: bool (optional), if True, get all experiment information.

Examples:

>>> experiment.to_json()

Returns:

{'id': '073e272581ac48c283910a05e5495381',
 'name': None,
 'workspace': 'testuser',
 'project_name': 'test-project-7515',
 'archived': False,
 'url': 'https://www.comet.com/testuser/test-project-7515/073e272581ac48c283910a05e54953801',
 'duration_millis': 4785,
 'start_server_timestamp': 1571318652586,
 'end_server_timestamp': 7437457,
 'optimization_id': None,
}

```python
  >>> experiment.to_json(full=True)

Returns:

  {'id': '073e272581ac48c283910a05e5495380',
  'name': None,
  'workspace': 'testuser',
  'project_name': 'test-project-7515',
  'archived': False,
  'url': 'https://staging.comet.com/testuser/test-project-7515/073e272581ac48c283910a05e5495380',
  'duration_millis': 4785,
  'start_server_timestamp': 1571318652586,
  'end_server_timestamp': 7437457,
  'optimization_id': None,
  'asset_list': [],
  'code': 'one\ntwo\nthree\n',
  'html': '<b>hello<b>\r\n<i>world!</i>\r\n',
  'metrics': [],
  'metrics_summary': [],
  'output': 'four\nfive\nsix\n',
  'parameters_summary': [],
  'system_details': {'experimentKey': None,
  'user': None,
  'pythonVersion': None,
  'pythonVersionVerbose': None,
  'pid': None,
  'osType': None,
  'os': None,
  'ip': None,
  'hostname': None,
  'gpuStaticInfoList': [],
  'logAdditionalSystemInfoList': [],
  'systemMetricNames': [],
  'maxTotalMemory': None,
  'networkInterfaceIps': None,
  'command': None,
  'executable': None,
  'osPackages': ['lib1', 'lib2', 'lib3'],
  'installedPackages': [],
  'totalRam': None},
  'tags': ['tag6', 'tag7', 'tag8'],
  'git_patch': b'',
  'git_metadata': {'user': None, 'root': None, 'branch': None, 'parent': None, 'origin': None},
  }

APIExperiment.update_status

update_status()

Update the status for this experiment. Sends the keep-alive status for it in the UI. The return JSON dictionary contains the recommended interval to send subsequent update_status() messages.

Example:

>>> api_experiment.update_status()
{'isAliveBeatDurationMillis': 10000,
 'gpuMonitorIntervalMillis': 60000,
 'cpuMonitorIntervalMillis': 68000}

APIExperiment.url

url()

Get the url of the experiment.

Example:

>>> api_experiment.url
"https://www.comet.com/username/34637643746374637463476"
Mar. 27, 2024