quantlab.tracking.mlflow#
The MLflow tracker; the only module that imports mlflow (ADR 0015).
mlflow is an optional extra (uv sync --extra mlflow or
pip install 'quantlab-py[mlflow]') and is imported only when an
MlflowTracker opens a run, so the library imports, and a config naming
an MlflowTracker is rebuilt, without it.
A run maps onto MLflow as follows. The project is an experiment, created
when missing. The group is a group tag on the run, not a parent run, so
the runs of one trial stay flat and are filtered with
tags.group = '<trial>'. The name is the run name. Step metrics are
metrics logged at their step; summary values are metrics logged once, at the
last step logged so far, so they are the latest value of their key. The
config becomes params, flattened to outer/inner keys, with every value
that is not a string written as JSON and cut to the 6000 characters MLflow
takes; the whole config, values uncut, is also kept as the artifact
run_config.json. MLflow refuses to change a param once logged, so
update_config logs new keys as params, and a key logged before with
another value is changed only in run_config.json. A table is the JSON
artifact tables/<name>.json ({"columns": [...], "data": [...]}, the
format of mlflow.log_table); no bar chart is drawn. A file is an artifact
at the root of the run. Leaving the run sets it FINISHED or FAILED.
Every param and metric key is cleaned of the characters MLflow refuses
(whole/Total Return [%] is logged as whole/Total Return ___, see
_mlflow_key).
Every call goes through an MlflowClient bound to the tracker’s
tracking_uri, never through mlflow’s global active run, so runs opened one
inside another stay apart. Credentials (MLFLOW_TRACKING_USERNAME,
MLFLOW_TRACKING_PASSWORD, MLFLOW_TRACKING_TOKEN) are read by mlflow
from the environment, never from the config.
Classes
A tracking run backed by one MLflow run; opened by |
|
Send tracking runs to MLflow. |