Skip to content

Use the SDK on premises

If you are running from an on-prem version of Comet, you must set several additional configuration variables.

First, you should make sure that you can perform import comet_ml. If comet_ml is not installed, you can install it (and upgrade it) using pip or conda. For more information, see Installation Instructions.

For the following examples, replace comet.your-company.com with your company's on-prem installation URL or IP address.

Set values

You can set values for the variables using one of the following three methods:

  • Shell environment variable
  • Script environment variable
  • Comet configuration file

Shell environment variable

You could put these variables and their values in a shell script which could be executed each time a user creates a new shell:

export COMET_URL_OVERRIDE=http://comet.your-company.com/clientlib/

You can also set your personal COMET_API_KEY in this manner, but we suggest using the Comet Configuration option, below.

Script environment variable

You could put these variables and their values in the script itself. Note that the import comet_ml comes after these setting:

import os

os.environ["COMET_URL_OVERRIDE"]="http://comet.your-company.com/clientlib/"

import comet_ml

You can also set your personal COMET_API_KEY in this manner, but we suggest using the Comet configuration option, below.

Comet configuration file

You could put these variables and their values in a file named ./.comet.config in your home directory. Note that this is also a good place for your personal Comet API key.

[comet]

URL_OVERRIDE = http://comet.your-company.com/clientlib/
API_KEY = ...

Test

Once you have the above configuration parameters set, test your setup.

Test experiment

# Script: test_comet.py
from comet_ml import Experiment
from time import sleep
import random

experiment = Experiment(project_name="test-comet")

print("Setting and logging some items...")
experiment.set_name("testing comet")
experiment.add_tag("working!")
experiment.log_other("finished", False)

print("Logging parameters...")
experiment.log_parameter("param_A", 1.1)
experiment.log_parameter("param_B", 2.2)
experiment.log_parameter("param_D", "high")
experiment.log_parameter("param_E", "low")
experiment.log_parameter("param_F", True)

print("Logging metrics", end="")
for y in range(60):
   experiment.log_metric("a", random.random() * y, step=y)
   experiment.log_metric("b", random.random(), step=y)
   experiment.log_metric("c", y, step=y)
   experiment.log_metric("d", y/60, step=y)
   print(".", end="")
   sleep(1.0)

print("Done!")
experiment.log_other("finished", True)
experiment.end()

You should get an experiment URL initially. You can go to that page and see the experiment update live. The entire script will take 60 seconds to run.

Test optimizer

from comet_ml import Optimizer

config = {
    "algorithm": "bayes",
    "parameters": {
        "hidden_layer_size": {"type": "integer", "min": 40, "max": 50},
    },
    "spec": {
        "metric": "loss",
        "objective": "minimize",
    },
}

optimizer = Optimizer(config)

for experiment in optimizer.get_experiments(project_name="test-comet"):
    # Pretend loss for testing:
    loss = experiment.get_parameter("hidden_layer_size")
    experiment.log_metric("loss", loss)
    experiment.end()

You should log exactly 11 experiments with the second script. The entire script will take a couple of minutes to run.

If you have any issues running either of these scripts, see your on-prem adminstrator.

Additional resources

If you have additional questions, see the documentation on Comet Configuration Variables or contact us on your Comet Support Slack channel.

Apr. 11, 2024