Comet Javascript SDK

This page documents the Comet JavaScript SDK.

See also:

Note: almost all of the following methods return a Promise.

API

Kind: global class
Access: public

new API(apiKey)

summary Comet Javascript SDK

Returns: API - API instance

Param Type
apiKey string

api.getVersion() ⇒ string

Kind: instance method of API
Summary: Returns the REST version string for this API instance.
Returns: string - the version string
Access: public
Example
```js

api.getVersion() "v2" ```

api.experimentURL(experimentKey) ⇒ string

Returns the URL for the experiment.

Kind: instance method of API
Returns: string - the url
Access: public

Param Type
experimentKey string

api.experimentMetadata(experimentKey) ⇒ Promise

Returns a Promise for the metadata for the given experimentKey.

Kind: instance method of API
Returns: Promise - Promise of an object of metadata
Access: public

Param Type
experimentKey string

Example
```js

api.experimentMetadata('7387462874624747').then(result => { console.log(results); });

{'archived': false, 'durationMillis': 72, 'endTimeMillis': 1572435457349, 'experimentKey': "5a67221477dc5d76b37d10adbe41486d", 'experimentName': null, 'optimizationId': null, 'projectId': "0306c896110140a2aaa24e54dbb40e6b", 'projectName': "my-project-name", 'startTimeMillis': 1572435384908, 'workspaceName': "myworkspace" } ```

api.experimentTags(experimentKey) ⇒ Promise

Returns a Promise for the list of tags for the given experimentKey.

Kind: instance method of API
Returns: Promise - Promise of an object of a list of tags
Access: public

Param Type
experimentKey string

Example
```js

api.experimentTags('7387462874624747').then(result => { console.log(results); });

['tag1', 'tag2', ...] ```

api.workspaces() ⇒ Promise

Returns a Promise for an array of workspace names for the current Comet user.

Kind: instance method of API
Returns: Promise - the Promise of an array of string names
Access: public
Example
```js

api.workspaces().then(result => { console.log(results); });

['workspace1', 'workspace2', 'workspace3'] ```

api.projects(workspace) ⇒ Promise

Returns a Promise for an array of project JSON objects for the given workspace.

Kind: instance method of API
Returns: Promise - an array of JSON project objects
Access: public

Param Type Description
workspace string the name of the workspace

Example
```js

api.projects('workspace').then(result => { console.log(results); });

[ { "projectId": "NA", "projectName": "general", "projectDescription": "View all experiments that aren't assigned to a project.", "ownerUserName": "username", "workspaceId": "workspace ID", "workspaceName": "workspace name", "isPublic": false, "numberOfExperiments": 1, "lastUpdated": 1527183924215 } ] ```

api.projectNotes(projectId) ⇒ Promise

Returns a Promise for the string of project notes.

Kind: instance method of API
Returns: Promise - Promise of a string of notes in markdown
Access: public

Param Type Description
projectId string the name of the project

Example
```js

api.projectNotes(projectId).then(result => { console.log(results); });

'# Heading\nMy notes.' ```

api.projectMetadata(projectId) ⇒ Promise

Returns a Promise for the project metadata.

Kind: instance method of API
Returns: Promise - Promise of the project metadata
Access: public

Param Type Description
projectId string the name of the project

Example
```js

api.projectMetadata(projectId).then(result => { console.log(results); });

{ "public": true, "lastUpdated": 1587065944275, "numberOfExperiments": 5, "ownerUserName": "username", "projectDescription": "Project Description", "projectId": "aProjectId", "projectName": "Project Name", "workspaceName": "Name of the workspace" } ```

api.get([workspace], [project], [experiment]) ⇒ Promise

Returns a Promise for an array of names or objects.

Kind: instance method of API
Returns: Promise - an array of workspaces, projects, or experiments.
Access: public

Param Type Description
[workspace] string the name of the "workspace", "workspace/project", or "workspace/project/experiment".
[project] string the name of the project
[experiment] string the name of the experiment

Example
```js

api.get().then(result => { console.log(results); });

['general', 'workspace1']

api.get('workspace1').then(result => { console.log(results); });

[{"lastUpdated": 1572435457347, numberOfExperiments: 1, ownerUserName: "user", projectDescription: "Project Description", projectId: "0306c897310140a1aaa24ea4343430e6b", projectName: "project1", public: false, workspaceName: "user", }]

api.get('workspace1/project1').then(result => { console.log(results); });

["4d51ea0c5ebb48eea3465f3ad0ba12b3", "dfae44c27ebe41ef9231fc35eae137e8", ...]

api.get('workspace1/project¼d51ea0c5ebb48eea3465f3ad0ba12b3').then(result => { console.log(results); });

{ "durationMillis": 0, "startTimeMillis": 1527184671290, "endTimeMillis": 1527184671290, "experimentKey": "4d51ea0c5ebb48eea3465f3ad0ba12b3", "experimentName": "someExperimentName", "optimizationId": "someOptimizationId", "archived": false, "projectName": "project1", "projectId": "someProjectId", "workspaceName": "workspace1", } ```

api.experimentsByProjectName(workspace, project) ⇒ Promise

Returns a Promise for an array of experiment JSON objects.

Kind: instance method of API
Returns: Promise - an array of experiment JSON objects
Access: public

Param Type Description
workspace string the name of the workspace
project string the name of the project

Example
```js

api.experimentsByProjectName('workspace1', 'project1').then(result => { console.log(results); });

[ { "durationMillis": 0, "startTimeMillis": 1527184671290, "endTimeMillis": 1527184671290, "experimentKey": "someExperimentKey", "experimentName": "someExperimentName", "optimizationId": "someOptimizationId", "archived": false, "projectName": "someProjectName", "projectId": "someProjectId", "workspaceName": "someWorkspaceName", } ] ```

api.experimentsByProjectId(projectId) ⇒ Promise

Returns a Promise for an array of experiment JSON objects given a project id.

Kind: instance method of API
Returns: Promise - an array of experiment JSON objects
Access: public

Param Type Description
projectId string the name of the project

Example
```js

api.experimentsByProjectId('project-uuid').then(result => { console.log(results); });

[ { "durationMillis": 0, "startTimeMillis": 1527184671290, "endTimeMillis": 1527184671290, "experimentKey": "someExperimentKey", "experimentName": "someExperimentName", "optimizationId": "someOptimizationId", "archived": false, "projectName": "someProjectName", "projectId": "someProjectId", "workspaceName": "someWorkspaceName", } ] ```

api.experimentHtml(experimentKey) ⇒ Promise

Returns a Promise for the HTML associated with the experiment or null.

Kind: instance method of API
Returns: Promise - the HTML string of the experiment or null if there is no HTML.
Access: public

Param Type Description
experimentKey string the experiment key

Example
```js

api.experimentHtml('experimentKey1').then(result => { console.log(results); });

'The HTML' ```

api.experimentCode(experimentKey) ⇒ Promise

Returns a Promise for the source code associated with the experiment or null.

Kind: instance method of API
Returns: Promise - the source code as a string of the experiment or null if there is no source code.
Access: public

Param Type Description
experimentKey string the experiment key

Example
```js

api.experimentCode('experimentKey1').then(result => { console.log(results); });

'print("The Source Code")' ```

api.experimentOutput(experimentKey) ⇒ Promise

Returns a Promise for the standard output associated with the experiment or null.

Kind: instance method of API
Returns: Promise - the output as a string of the experiment or null if there is no output.
Access: public

Param Type Description
experimentKey string the experiment key

Example
```js

api.experimentOutput('experimentKey1').then(result => { console.log(results); });

'The Output of the Program' ```

api.experimentInstalledPackages(experimentKey) ⇒ Promise

Returns a Promise for an Array of installed packages associated with the experiment.

Kind: instance method of API
Returns: Promise - an Array of Python packages in "package=version" format.
Access: public

Param Type Description
experimentKey string the experiment key

Example
```js

api.experimentInstalledPackages('experimentKey1').then(result => { console.log(results); });

['pip=19.01', 'comet=1.0.28'] ```

api.experimentSystemDetails(experimentKey) ⇒ Promise

Returns a Promise for an Object of JSON system details associated with the experiment.

Kind: instance method of API
Returns: Promise - an Object of JSON system details.
Access: public

Param Type Description
experimentKey string the experiment key

Example
```js

api.experimentSystemDetails('experimentKey1').then(result => { console.log(results); });

{command: ["/usr/local/bin/pytest", ...], executable: "/usr/local/bin/python", experimentKey: "4d51ea0c5ebb48eea3465f3ad0ba12b3", gpuStaticInfoList: [], hostname: "b94cd9a8ee38", installedPackages: ["atomicwrites==1.3.0", ...], ip: "172.19.0.5", logAdditionalSystemInfoList: [], maxTotalMemory: null, networkInterfaceIps: (2) ["127.0.0.1", "172.19.0.5"], os: "Linux-4.15.0-1057-oem-x86_64-with-debian-10.1", osPackages: [], osType: "Linux", pid: 6, pythonVersion: "3.6.9", pythonVersionVerbose: "3.6.9 (default, Sep 12 2019, 16:23:48) \n[GCC 8.3.0]", systemMetricNames: ["sys.cpu.percent.01", ...], totalRam: null, user: "root", } ```

api.experimentGraph(experimentKey) ⇒ Promise

Returns a Promise for the graph associated with the experiment's model, or null.

Kind: instance method of API
Returns: Promise - the graph as a string of the experiment's model or null if there is no graph.
Access: public

Param Type Description
experimentKey string the experiment key

Example
```js

api.experimentGraph('experimentKey1').then(result => { console.log(results); });

'Network()' ```

api.experimentImages(experimentKey) ⇒ Promise

Returns a Promise for an Array of image JSON objects associated with the experiment.

Kind: instance method of API
Returns: Promise - array of JSON image objects
Access: public

Param Type Description
experimentKey string the experiment key

Example
```js

api.experimentImages('experimentKey1').then(result => { console.log(results); });

[ { "apiKey": "someApiKey", "runId": "someRunId0123456789012345", "experimentKey": "someExperimentKey", "projectId": null, "figCounter": 123, "figName": "imageName", "step": 12312, "runContext": "contextA", "fileName": "file.py", "imagePath": "https://comet-ml.nyc3.digitaloceanspaces.com/file.py" } ] ```

api.experimentParameters(experimentKey, [name]) ⇒ Promise

If no parameter name is given, then it returns a Promise of an Array of parameter JSON objects associated with the experiment. If a parameter name is given, then it returns a Promise of the valueCurrent of the parameter.

Kind: instance method of API
Returns: Promise - array of JSON parameter objects or value of given parameter name
Access: public

Param Type Description
experimentKey string the experiment key
[name] string the name of the parameter

Example
```js

api.experimentParameters('experimentKey1').then(result => { console.log(result); });

[ { "name": "nameA", "valueMax": "valueA", "valueMin": "valueA", "valueCurrent": "valueA", "timestampMax": 1527266735622, "timestampMin": 1527266735622, "timestampCurrent": 1527266735622, "runContextMax": "", "runContextMin": "", "runContextCurrent": "", "stepMax": null, "stepMin": null, "stepCurrent": null }, { "name": "nameB", "valueMax": "valueB", "valueMin": "valueB", "valueCurrent": "valueB", "timestampMax": 1538888303, "timestampMin": 1538888303, "timestampCurrent": 1538888303, "runContextMax": "", "runContextMin": "", "runContextCurrent": "", "stepMax": null, "stepMin": null, "stepCurrent": null } ]

api.experimentParameters('experimentKey1', 'nameA').then(result => { console.log(result); });

[ { "name": "nameA", "valueMax": "valueA", "valueMin": "valueA", "valueCurrent": "valueA", "timestampMax": 1527266735622, "timestampMin": 1527266735622, "timestampCurrent": 1527266735622, "runContextMax": "", "runContextMin": "", "runContextCurrent": "", "stepMax": null, "stepMin": null, "stepCurrent": null } ] ```

api.experimentMetricsSummary(experimentKey, [metricName]) ⇒ Promise

Returns a Promise for a JSON object that has the summary data of the given metric, or a list of the JSON objects for each metric if no metricName is given.

Kind: instance method of API
Returns: Promise - JSON metric object, or Array of
Access: public

Param Type Description
experimentKey string the experiment key
[metricName] string the name of the metric

Example
```js

api.experimentMetricsSummary('experimentKey1', 'someNameA').then(result => { console.log(results); });

{ "name": "someNameA", "valueMax": "1.123", "valueMin": "1.123", "valueCurrent": "1.123", "timestampMax": 1527266664729, "timestampMin": 1527266664729, "timestampCurrent": 1527266664729, "runContextMax": null, "runContextMin": null, "runContextCurrent": null, "stepMax": null, "stepMin": null, "stepCurrent": null }

api.experimentMetricsSummary('experimentKey1').then(result => { console.log(results); });

[ { "name": "someNameA", "valueMax": "1.123", "valueMin": "1.123", "valueCurrent": "1.123", "timestampMax": 1527266664729, "timestampMin": 1527266664729, "timestampCurrent": 1527266664729, "runContextMax": null, "runContextMin": null, "runContextCurrent": null, "stepMax": null, "stepMin": null, "stepCurrent": null }, { "name": "someNameB", "valueMax": "42", "valueMin": "40", "valueCurrent": "41", "timestampMax": 1727266664729, "timestampMin": 1727266664729, "timestampCurrent": 1727266664729, "runContextMax": null, "runContextMin": null, "runContextCurrent": null, "stepMax": null, "stepMin": null, "stepCurrent": null } ] ```

api.experimentOther(experimentKey, [other], [value]) ⇒ Promise

If no other name is given, then it returns a Promise of an Array of all other JSON objects associated with the experiment. If a name is given, then it returns a Promise of the JSON object of given item. If a value is also given, then it will return a Promise of the JSON field of that name.

Kind: instance method of API
Returns: Promise - array of JSON logged other items, or a single matching JSON object, or the field of that JSON object.
Access: public

Param Type Description
experimentKey string the experiment key
[other] string the name of the logged item
[value] string the field of the JSON object

Example
```js

api.experimentOther('experimentKey1').then(result => { console.log(results); });

[ { "name": "key", "valueMax": "value", "valueMin": "value", "valueCurrent": "value", "timestampMax": 1527266796121, "timestampMin": 1527266796121, "timestampCurrent": 1527266796121, "runContextMax": null, "runContextMin": null, "runContextCurrent": null, "stepMax": null, "stepMin": null, "stepCurrent": null } ]

api.experimentOther('experimentKey1', 'key').then(result => { console.log(results); });

{ "name": "key", "valueMax": "value", "valueMin": "value", "valueCurrent": "value", "timestampMax": 1527266796121, "timestampMin": 1527266796121, "timestampCurrent": 1527266796121, "runContextMax": null, "runContextMin": null, "runContextCurrent": null, "stepMax": null, "stepMin": null, "stepCurrent": null }

api.experimentOther('experimentKey1', 'key', 'valueMax').then(result => { console.log(results); });

"value" ```

api.experimentName(experimentKey, [maxLength]) ⇒ Promise

Returns a Promise for the name of this experiment (if one) or key. The return value is limited in length if maxLength is given;

Kind: instance method of API
Returns: Promise - the name of the experiment key.
Access: public

Param Type Description
experimentKey string the experiment key
[maxLength] number the maximum length of name or key

Example
```js

api.experimentName('experimentKey1').then(result => { console.log(results); }); 'name given via experiment.set_name("name")'

api.experimentName('experimentKey1', 9) 'name give'

api.experimentName('experimentKey1') '09ce56129' ```

api.experimentMetric(experimentKey, [metricName], [interval]) ⇒ Promise

If no metric name is given, then it returns a Promise of an Array of all raw metric JSON objects associated with the experiment. If a metric name is given, then it returns a Promise of an Array of [(interval, metricValue), ...]. If an Array of metric names are given, then it retunrs a Promise of an Object of Arrays of [(interval, metricValue), ...]. If an interval is given, then it uses that field in the above return Arrays.

Kind: instance method of API
Returns: Promise - various formats (see below)
Access: public

Param Type Default Description
experimentKey string the experiment key
[metricName] string the name of the metric, or Array of metric names
[interval] string "'step'" the name of the interval

Example
```js

api.experimentMetric('experimentKey1', 'batch').then(result => { console.log(results); });

[(null, "0")] ```

api.experimentMetricsForChart(targetsExperiments, metrics, parameters, independentMetrics, fetchFull) ⇒ Promise

Return a Promise of a set of metrics and/or parameters aligned on step values.

Kind: instance method of API
Access: public

Param Type Description
targetsExperiments Array an array of experimentKeys
metrics string [metrics=undefined] the names of the metrics
parameters string [parameters=undefined] the names of the parameters
independentMetrics boolean independent, whether to align all of the selection and ignore all but those that match, or get all
fetchFull boolean full, whether to fetch all metrics (up to 15,000) or a sampled subset (about 500)

Example
```js

api.experimentMetricsForChart(['5a67221477dc4dc6b38d10adbe41486d']).then(result => { console.log(results); });

{'5a67221477dc4dc6b38d10adbe41486d': {'empty': false, 'epochs': null, 'params': null, 'steps': null, 'experimentKey': "5a67221477dc4dc6b38d10adbe41486d", 'metrics': [{'metricName': "acc", 'values': [], 'steps': [], 'epochs': [], 'timestamps': [], 'values': []}], } } ```

api.experimentAssets(experimentKey) ⇒ Promise

Returns a Promise for an Array of asset JSON objects associated with the experiment.

Kind: instance method of API
Returns: Promise - array of JSON asset objects
Access: public

Param Type Description
experimentKey string the experiment key

Example
```js

api.experimentAssets('experimentKey1').then(result => { console.log(results); });

[ { "fileName": "file.py", "fileSize": 7, "runConext": "contextA", "step": 12312, "link": "https://www.comet.ml/api/rest/v2/experiment/asset/get-asset?experimentKey=someExperimentKey&assetId=6YZYszn9cO9mhDoYrfuQlDLcE", "createdAt": 1544067813424, "dir": "assets" } ] ```

api.experimentAssetByName(experimentKey, fileName, [returnType]) ⇒ Promise

Returns a Promise for an asset associated with the experiment by its name. If the asset is a JSON file, you can get the contents parsed as JSON data.

Kind: instance method of API
Returns: Promise - the contents (binary (if Python 3 and returnType === 'raw'), string (if Python 2 and returnType === 'raw'), or JSON if returnType === 'json')
Access: public

Param Type Default Description
experimentKey string the experiment key
fileName string the name of the asset
[returnType] string "'raw'" the type of data to return

Example
```js

api.experimentAssetByName('experimentKey1', 'file.py').then(result => { console.log(results); });

'the contents of the asset as string (Python 2)'

api.experimentAssetByName('experimentKey1', 'file.py').then(result => { console.log(results); });

b'the contents of the asset as binary (Python 3)'

api.experimentAssetByName('experimentKey1', 'file.json', 'json').then(result => { console.log(results); });

{someName: "value of key", someOther: [1, 2, 3]}

api.experimentAssetByName('experimentKey1', 'file.data', 'json').then(result => { console.log(results); });

[[1], [2], [3]] ```

api.experimentCurves(experimentKey)

Returns a Promise for a list of curves logged with experiment.

Kind: instance method of API
Access: public

Param Type Description
experimentKey string the experiment key

Example
```js

api.experimentCurves('experimentKey1').then(curves => { console.log(curves); });

[{x: [1, 2, 3], y: [4, 5, 6], name: "mycurve"}, ...] ```

api.experimentAsset(experimentKey, assetId, [returnType]) ⇒ Promise

Returns a Promise for an asset associated with the experiment by its id. If the asset is a JSON file, you can get the contents parsed as JSON data.

Kind: instance method of API
Returns: Promise - the contents (binary (if Python 3 and returnType === 'raw'), string (if Python 2 and returnType === 'raw'), or JSON if returnType === 'json')
Access: public

Param Type Default Description
experimentKey string the experiment key
assetId string the name of the asset
[returnType] string "'raw'" the type of data to return

Example
```js

api.experimentAsset('experimentKey1', '6YZYszn9cO9mhDoYrfuQlDLcE').then(result => { console.log(results); });

'the contents of the asset as string (Python 2)'

api.experimentAsset('experimentKey1', '6YZYszn9cO9mhDoYrfuQlDLcE').then(result => { console.log(results); });

b'the contents of the asset as binary (Python 3)'

api.experimentAsset('experimentKey1', '3873473463782746284762734', 'json').then(result => { console.log(results); });

{someName: "value of key", someOther: [1, 2, 3]}

api.experimentAsset('experimentKey1', '9093487348374873487348731', 'json').then(result => { console.log(results); });

[[1], [2], [3]] ```

api.store(key, value)

Given a key, value pair, save it locally, and send the whole store to the backend. Returns a Promise for the result.

Kind: instance method of API
Access: public

Param Type
key string
value string

Example
```js

api.store("text", "This is the text").then(result => { console.log(results); });

{"msg": "Stored"} ```

api.getFromStore(key)

Given a key, return a Promise for the value from the backend.

Kind: instance method of API
Access: public

Param Type
key string

Example
```js

api.getFromStore("text").then(result => { console.log(results); });

"This is the text" ```

api.getStore()

Return a Proimse for the store from the backend.

Kind: instance method of API
Access: public
Example
```js

api.getStore().then(result => { console.log(results); });

{"store": "{...}"} ```