Tracking

class endgame.tracking.ExperimentLogger[source]

Bases: ABC

Abstract base for experiment logging backends.

All loggers implement this interface, enabling consistent tracking across MLflow, console, or custom backends.

Supports context manager usage:

with MyLogger() as logger:
    logger.log_params({"lr": 0.01})
    logger.log_metrics({"acc": 0.95})
abstractmethod start_run(run_name=None, tags=None)[source]

Start a new tracking run.

Parameters:
  • run_name (str, optional) – Human-readable name for this run.

  • tags (dict, optional) – Tags to associate with the run.

Return type:

Text

Returns:

str – Run identifier.

abstractmethod end_run(status='FINISHED')[source]

End the current run.

Parameters:

status (str, default="FINISHED") – Final status: “FINISHED”, “FAILED”, “KILLED”.

Return type:

None

abstractmethod log_params(params)[source]

Log parameters for the current run.

Parameters:

params (dict) – Parameter key-value pairs. Nested dicts are flattened with dot notation (e.g., {"model.lr": 0.01}).

Return type:

None

abstractmethod log_metrics(metrics, step=None)[source]

Log metrics for the current run.

Parameters:
  • metrics (dict) – Metric key-value pairs.

  • step (int, optional) – Step number for time-series metrics (e.g., epoch).

Return type:

None

abstractmethod log_artifact(local_path, artifact_path=None)[source]

Log a local file as an artifact.

Parameters:
  • local_path (str) – Path to the local file.

  • artifact_path (str, optional) – Subdirectory within the artifact store.

Return type:

None

abstractmethod log_model(model, artifact_path='model', **kwargs)[source]

Log a trained model as an artifact.

Parameters:
  • model (Any) – Trained model (sklearn, pytorch, etc.).

  • artifact_path (str, default="model") – Subdirectory for the model artifact.

  • **kwargs – Backend-specific options.

Return type:

None

abstractmethod set_experiment(name)[source]

Set the active experiment.

Parameters:

name (str) – Experiment name.

Return type:

None

class endgame.tracking.ConsoleLogger(log_file=None, verbose=True)[source]

Bases: ExperimentLogger

Simple console/file logger with no external dependencies.

Prints experiment tracking information to the console and optionally writes a JSON log file. Useful for lightweight tracking without MLflow.

Parameters:
  • log_file (str or Path, optional) – Path to a JSON log file. If provided, all events are appended.

  • verbose (bool, default=True) – Whether to print to console.

Examples

>>> logger = ConsoleLogger()
>>> with logger:
...     logger.log_params({"lr": 0.01, "epochs": 10})
...     logger.log_metrics({"accuracy": 0.95})

With file logging:

>>> logger = ConsoleLogger(log_file="experiment_log.json")
>>> logger.start_run("my_experiment")
>>> logger.log_metrics({"f1": 0.92})
>>> logger.end_run()
start_run(run_name=None, tags=None)[source]

Start a new run.

Return type:

Text

Parameters:
end_run(status='FINISHED')[source]

End the current run.

Return type:

None

Parameters:

status (str)

log_params(params)[source]

Log parameters.

Return type:

None

Parameters:

params (dict[str, Any])

log_metrics(metrics, step=None)[source]

Log metrics.

Return type:

None

Parameters:
log_artifact(local_path, artifact_path=None)[source]

Log an artifact path.

Return type:

None

Parameters:
  • local_path (str)

  • artifact_path (str | None)

log_model(model, artifact_path='model', **kwargs)[source]

Log a model (records type name only).

Return type:

None

Parameters:
  • model (Any)

  • artifact_path (str)

set_experiment(name)[source]

Set the active experiment name.

Return type:

None

Parameters:

name (str)

endgame.tracking.get_logger(backend='console', **kwargs)[source]

Factory function to get a logger instance.

Parameters:
  • backend (str, default="console") – Logging backend: “console”, “mlflow”.

  • **kwargs – Arguments passed to the logger constructor.

Return type:

ExperimentLogger

Returns:

ExperimentLogger – Logger instance.