{"id":3935,"library":"comet-ml","title":"Comet ML","description":"Comet ML is an MLOps platform for tracking, comparing, debugging, and optimizing machine learning models. It provides a comprehensive dashboard to visualize experiments, log code, metrics, hyperparameters, and artifacts. The current version is 3.57.3, and it receives frequent updates with new features and bug fixes.","status":"active","version":"3.57.3","language":"en","source_language":"en","source_url":"https://github.com/comet-ml/comet-ml-py","tags":["mlops","experiment-tracking","machine-learning","logging","data-science"],"install":[{"cmd":"pip install comet_ml","lang":"bash","label":"Install core library"}],"dependencies":[],"imports":[{"note":"While functional, importing directly from the top-level package is the standard and recommended approach.","wrong":"from comet_ml.experiment import Experiment","symbol":"Experiment","correct":"from comet_ml import Experiment"},{"note":"The `init` function is typically called as a method of the top-level `comet_ml` module, not directly imported.","wrong":"from comet_ml import init","symbol":"init","correct":"import comet_ml; comet_ml.init()"},{"note":"Logging functions are methods of an `Experiment` object, not global functions on the `comet_ml` module (unless using the simpler `comet_ml.init()` pattern).","wrong":"comet_ml.log_parameters({'param': value})","symbol":"log_parameters","correct":"experiment.log_parameters({'param': value})"}],"quickstart":{"code":"import os\nfrom comet_ml import Experiment\n\n# Ensure COMET_API_KEY and COMET_WORKSPACE are set as environment variables\n# or use comet_ml.login() if you prefer interactive login.\n# For example: os.environ['COMET_API_KEY'] = 'YOUR_API_KEY'\n# os.environ['COMET_WORKSPACE'] = 'YOUR_WORKSPACE'\n\n# Or, for local testing without an explicit API key (results only stored locally):\n# experiment = Experiment(project_name=\"my-test-project\", log_code=False, display_summary_to_terminal=False)\n\n# Initialize an experiment\n# It's best practice to use a context manager to ensure the experiment terminates correctly\nwith Experiment(project_name=\"my-quickstart-project\", \n                api_key=os.environ.get('COMET_API_KEY', None),\n                workspace=os.environ.get('COMET_WORKSPACE', None),\n                auto_output_logging='simple', # capture print statements\n                auto_metric_logging=True, # capture common metrics\n                log_code=True # logs your script code\n               ) as experiment:\n    # Log hyperparameters\n    hyper_params = {\"learning_rate\": 0.001, \"epochs\": 10, \"batch_size\": 32}\n    experiment.log_parameters(hyper_params)\n\n    # Simulate a training loop\n    for epoch in range(hyper_params[\"epochs\"]):\n        # Simulate metric calculation\n        accuracy = 0.5 + (epoch * 0.05) + (hyper_params[\"learning_rate\"] * 100)\n        loss = 1.0 - (epoch * 0.08) - (hyper_params[\"learning_rate\"] * 50)\n\n        # Log metrics for each epoch\n        experiment.log_metric(\"accuracy\", accuracy, step=epoch)\n        experiment.log_metric(\"loss\", loss, step=epoch)\n\n    # Log a final metric or result\n    final_accuracy = accuracy # from the last epoch\n    experiment.log_metric(\"final_accuracy\", final_accuracy)\n\n    print(f\"Experiment URL: {experiment.url}\")\n\nprint(\"Experiment finished.\")\n","lang":"python","description":"This quickstart demonstrates how to create an `Experiment` using a context manager, log hyperparameters, and track metrics during a simulated training loop. It leverages environment variables for authentication, which is a recommended best practice."},"warnings":[{"fix":"Set `COMET_API_KEY` and `COMET_WORKSPACE` as environment variables or call `comet_ml.login()` once to store credentials locally.","message":"Comet API Key and Workspace configuration: Hardcoding API keys directly in scripts is a security risk. Best practice is to use environment variables (`COMET_API_KEY`, `COMET_WORKSPACE`), a `.comet.config` file, or `comet_ml.login()` for interactive setup.","severity":"gotcha","affected_versions":"All versions"},{"fix":"Always use `with Experiment(...) as experiment:` for new experiments to ensure proper lifecycle management and resource cleanup, especially in scripts that might crash.","message":"Experiment lifecycle management: Forgetting to end an experiment (e.g., in case of script errors) can lead to hanging processes or incomplete experiment data. Using the `Experiment` class as a context manager (`with Experiment(...) as experiment:`) automatically handles experiment termination.","severity":"gotcha","affected_versions":"All versions"},{"fix":"Upgrade your Python environment to 3.8 or newer. If you must use an older Python version, consider pinning `comet_ml` to a 2.x version (though not recommended due to lack of updates).","message":"Python 2.x support dropped: Comet ML version 3.x and above requires Python 3.8 or higher. Attempts to use it with older Python versions will result in `ModuleNotFoundError` or `SyntaxError`.","severity":"breaking","affected_versions":">=3.0.0"},{"fix":"Review the documentation for `Experiment` initialization parameters like `auto_output_logging`, `auto_metric_logging`, `log_code`, `log_git_metadata` to explicitly enable or disable automatic logging features as needed for your specific use case.","message":"Automatic logging features: Comet ML automatically logs many aspects (e.g., environment details, code, git data, common metrics like loss/accuracy from popular ML frameworks). This can be helpful but might log more than desired or conflict with manual logging if not understood. For example, `auto_output_logging` can capture stdout/stderr.","severity":"gotcha","affected_versions":"All versions"}],"env_vars":null,"last_verified":"2026-04-11T00:00:00.000Z","next_check":"2026-07-10T00:00:00.000Z"}