quantlab.tracking.mlflow.MlflowTracker#
- class quantlab.tracking.mlflow.MlflowTracker(*, project=None, tracking_uri=None)[source]#
Bases:
TrackerSend 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;
Nonekeeps the caller’s default.- tracking_uristr, optional
Where the experiments live: a server (
http://host:5000), a database (sqlite:///mlflow.db, which needs the fullmlflowpackage) or a local directory (file:/path/to/mlruns). MLflow 3 opens a local directory only withMLFLOW_ALLOW_FILE_STOREset; naming afile:URI here sets it totruefor the process unless it is already set.Noneuses mlflow’s own default,MLFLOW_TRACKING_URIwhen 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
configaModelConfigbuilt 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