quantlab.tracking.mlflow.MlflowTracker#

class quantlab.tracking.mlflow.MlflowTracker(*, project=None, tracking_uri=None)[source]#

Bases: Tracker

Send tracking runs to MLflow.

mlflow is imported when a run opens; see the module docstring for how a run maps onto MLflow.

Attributes:
projectstr, optional

The MLflow experiment every run goes to, created when missing; None keeps the caller’s default.

tracking_uristr, optional

Where the experiments live: a server (http://host:5000), a database (sqlite:///mlflow.db, which needs the full mlflow package) or a local directory (file:/path/to/mlruns). MLflow 3 opens a local directory only with MLFLOW_ALLOW_FILE_STORE set; naming a file: URI here sets it to true for the process unless it is already set. None uses mlflow’s own default, MLFLOW_TRACKING_URI when set.

Raises:
ImportError

When a run opens without mlflow installed; the message names the extra to install.

Examples

A model trains into a local MLflow store when only the tracker of its config changes. With config a ModelConfig built earlier:

>>> import dataclasses, tempfile
>>> from pathlib import Path
>>> from mlflow import MlflowClient
>>> from quantlab.model.predefined.xgb import XGBoostRegressor
>>> store = f"file:{Path(tempfile.mkdtemp()) / 'mlruns'}"
>>> tracker = MlflowTracker(tracking_uri=store)
>>> model = XGBoostRegressor(dataclasses.replace(config, tracker=tracker))
>>> checkpoint = model.collect().train()
>>> client = MlflowClient(tracking_uri=store)
>>> (run,) = client.search_runs(
...     [client.get_experiment_by_name("XGBoostRegressor").experiment_id]
... )
>>> from quantlab.runs.trained_run import TrainedRun
>>> group = TrainedRun.open(checkpoint).path.name
>>> run.info.run_name, run.info.status, run.data.tags["group"] == group
('XGBoostRegressor_total', 'FINISHED', True)
>>> "test_ic" in run.data.metrics
True
config_cls#

alias of MlflowTracker