/comet:comet-experimentsfrom comet
Add Comet experiment tracking to ML code and run it - create experiments with comet_ml.start(), log parameters, metrics, curves, images, tables, confusion matrices, models and artifacts, use framework autologging (PyTorch, Keras, sklearn, XGBoost, LightGBM, ...), run sweeps with the Comet Optimizer, work offline, and report the experiment URL. Use for "track this training run in Comet", "log metrics to Comet", "add comet_ml to my script", "run an experiment", "sweep these hyperparameters", "register this model". Not for reading past runs (use comet-query) or building dashboards (use comet-views).
Ships in comet. Installing the plugin adds it to Claude Code.
What the skill costs in Claude's context, stage by stage
Name and description: Claude knows it exists.
SKILL.md joins the conversation and stays.
Read when SKILL.md points to them.
Credentials, configuration and source lookup: see the comet-ml skill.
Full logging method list: references/logging.md.
comet-ml). If none,
offer offline mode (COMET_START_ONLINE=false) or ask the user to run
comet login.api.get_default_workspace()) and
project. Never let runs land in general by accident.import comet_ml # import before torch/tensorflow/sklearn so autologging can patch them
experiment = comet_ml.start(
project_name="my-project",
experiment_config=comet_ml.ExperimentConfig(
name="resnet50-lr3e-4",
tags=["baseline", "dataset=v2"],
),
)
try:
experiment.log_parameters({"lr": 3e-4, "batch_size": 64, "epochs": 10})
for epoch in range(10):
train_loss = train_one_epoch()
val_loss, val_acc = evaluate()
experiment.log_metrics(
{"train_loss": train_loss, "val_loss": val_loss, "val_acc": val_acc},
epoch=epoch,
step=epoch,
)
experiment.log_model("resnet50", "model.pt")
finally:
print("Comet experiment:", experiment.url)
experiment.end() # flushes uploads; always call it
Key facts:
comet_ml.start() reads key, workspace and server from the environment,
honours COMET_START_ONLINE=false, resumes an experiment when given
experiment_key=, and reuses the running experiment when a notebook cell
re-runs. Prefer it over constructing comet_ml.Experiment(...).Experiment is not a context manager. Use try/finally: experiment.end().step is the x-axis of charts; epoch drives epoch progress. Pass step
for per-batch metrics, both for per-epoch ones.experiment.get_key() and experiment.url identify the run. Report them
to the user when the run finishes.with experiment.train():, with experiment.validate(): and
with experiment.test(): to prefix metrics with train_, validate_,
test_ automatically.With comet_ml imported first and an experiment started, these log on
their own: Keras/TensorFlow fit, PyTorch loss via backward, PyTorch
Lightning (CometLogger), scikit-learn estimator parameters, XGBoost and
LightGBM eval curves, Hugging Face Trainer (via report_to="comet_ml"),
fastai, Prophet, SHAP and MLflow runs. Explicit log_metrics calls are
still fine alongside it. Turn a source off with ExperimentConfig
(auto_metric_logging=False, auto_param_logging=False, ...).
{project}-{model}-{YYYYMMDD}-{HHmm} in UTC. Counters collide once
runs are archived.key=value for sortable ones
(framework=pytorch, dataset=v2), single words for stages (baseline,
sweep). Do not pack them into the name.comet_ml.start(experiment_key=KEY) appends to an existing run.COMET_START_ONLINE=false (or comet_ml.start(online=False))
writes a zip under offline_directory; upload it later with
comet upload <file>.zip. Offline runs cannot log or fetch Artifacts,
cannot register models, and cannot use the Optimizer. COMET_MODE=offline
is not a setting.Save the model with its preprocessing (an sklearn Pipeline, a
normalization layer, or the statistics inside the file), so a registry
version runs on raw inputs. Then attach it to the run:
experiment.log_model("classifier", "model.pkl")
Registering a version in the Model Registry is a separate, team-visible
step covered by the comet-registry skill. Do not register unasked, and do
not register every run.
artifact = comet_ml.Artifact(name="train-data", artifact_type="dataset")
artifact.add("data/train.csv") # or artifact.add_remote("s3://...")
experiment.log_artifact(artifact) # new version
logged = experiment.get_artifact("train-data") # consume + record lineage
logged.download("data/")
config = {
"algorithm": "bayes", # or "grid", "random"
"parameters": {
"lr": {"type": "float", "min": 1e-5, "max": 1e-2, "scalingType": "loguniform"},
"batch_size": {"type": "discrete", "values": [32, 64, 128]},
},
"spec": {"metric": "val_loss", "objective": "minimize", "maxCombo": 20},
}
optimizer = comet_ml.Optimizer(config)
sweep_tag = f"sweep={optimizer.get_id()}"
for experiment in optimizer.get_experiments(project_name="my-project"):
try:
experiment.add_tags(["sweep", sweep_tag])
val_loss = train(lr=experiment.get_parameter("lr"),
batch_size=experiment.get_parameter("batch_size"))
experiment.log_metric("val_loss", val_loss)
finally:
experiment.end()
maxCombo) before starting it, and never raise it silently.sweep matches every past sweep).get_experiments(**kwargs) passes its arguments to each experiment, so
experiment options such as auto_metric_logging=False work there.comet_ml.Optimizer(<id>) on several machines shares one search.comet-query. Show the trials table, the
best trial's URL and the parameters to reproduce it. Do not register the
best trial from here.To make a user's ML repository agent-ready (credentials file, MCP server config, agent instructions, a training-script skeleton), see references/project-setup.md.
End with: experiment name, URL, the final values of the key metrics, and
anything that failed to log. To compare with earlier runs, hand off to
comet-query; to build a dashboard for the project, hand off to
comet-views.
Tested end to end against a Comet server; each prints a summary: line and checks its own result.
examples/experiments/dataset_artifact.pyexamples/experiments/train.pyexamples/experiments/sweep.pycomet_ml (autologging silently does nothing).experiment.end() in scripts (data still uploading is lost).log_parameters and tags.What SKILL.md sets; muted values are Claude Code's defaults
Other plugins' skills for the same job
npx claudepluginhub comet-ml/comet-python-sdk --plugin comet5 skills in this plugin
/comet-mlReference for the Comet ML Python SDK (comet_ml) - credentials and configuration, self-hosted servers, the object model (Experiment, API, APIExperiment, View, Artifact, Model), and how to look up exact signatures in the SDK source. Use for "how do I configure comet", "which comet_ml class does X", "what's the signature of log_X", "is my Comet key set up". For running experiments use comet-experiments; for views and panels use comet-views; for answering questions from Comet data use comet-query; for the model registry use comet-registry./comet-queryAnswer questions from a Comet server's data - find, filter and compare experiments, read metrics, curves, hyperparameters, tags, system info, logs, code and assets, list projects and workspaces, and look up registered models. Uses the Comet MCP server when connected, else comet_ml.API scripts. Use for "which run had the best val accuracy", "compare these experiments", "what learning rate did run X use", "show me the loss curve", "how many experiments are in project Y", "what changed between the last two runs", "which model version is in production". Read-only. Not for logging new runs (use comet-experiments) or building dashboards (use comet-views)./comet-registryWork with the Comet Model Registry - register a model version from an experiment, list models and versions with their status, tags and source run, promote or demote a version's status (Development, Staging, QA, Production), add or remove tags, and download or load a registered version for serving. Shows current state and asks for confirmation before every change. Use for "register this model", "promote 1.2.0 to production", "what's in production", "tag it champion", "load the production model". Not for logging models to a run (use comet-experiments).