quantlab.runs.trained_run#
Trained runs: the files a training run leaves on disk, and how they are read back.
Training writes one directory per trained unit, a run of the run layer
(quantlab.runs.directory): it holds its files and, written last,
run.json, which describes the unit under the shared header. There are
three kinds:
"model": one checkpoint, theconfig.jsonthat rebuilds the model, and, when the fit was evaluated, the per-bar IC seriesic_series.csvand the test-segment predictionstest_predictions.zarr.run.jsonholds the training window as configured and as fitted after the purge, the test window, what the model was trained on, the metrics and, for a library model that reports them, the hyperparameters the library actually trained with,resolved_hyperparameters."ensemble": its members, each a"model"unit inmember_{k}/, and the evaluation files of the combined prediction.run.jsonholds the members (directory and seed), the three windows and the metrics. Its load-mode checkpoint is itsrun.json."walk_forward": its folds, each a"model"or"ensemble"unit infold_{i}/.run.jsonholds the folds (directory, index, three windows, metrics) and the fold means of the metrics,cv_mean.
Every unit’s run.json also holds data_fingerprint: what the unit’s
collect() read, as its DataRecorder recorded it, keyed by component
path within the model; and code, the code record of the model
(quantlab.runs.record). Only the top unit records them: the trained
model, or the ensemble or walk-forward unit; its members and folds hold none.
An ensemble or walk-forward unit assembled from members trained separately
(BaseEnsemble.assemble) also records assembled_from: each source
run’s directory and code record.
train writes a unit at {model_save_dir}/{Class}_trial_{timestamp}/,
train_cv a "walk_forward" unit there. Paths inside run.json are
relative to the unit, so a unit copied elsewhere still opens.
TrainedRun.open (or quantlab.runs.directory.open_run) is how a run
is read: from the unit’s directory, its run.json, or a model’s
checkpoint; members and folds are opened with it, as child TrainedRun
objects. A unit without run.json, or written in another
format_version, is refused with a message to retrain it. The writing
functions are for the model layer.
This module imports no quantlab module outside quantlab.utils and the run
layer.
Examples#
>>> run = TrainedRun.open("models/MyHead_trial_20240601_120000_000000")
>>> run.kind, run.checkpoint.name
('model', 'MyHead_total.joblib')
>>> run.train_window, run.fitted_train_window
(('2024-01-01', '2024-02-09'), ('2024-01-01', '2024-02-07T00:00:00.000000000'))
A walk-forward run opens the same way; its folds are units of their own:
>>> cv = TrainedRun.open("models/MyHead_trial_20240601_130000_000000")
>>> cv.kind, len(cv.folds), cv.folds[0].kind, cv.folds[0].index
('walk_forward', 4, 'model', 0)
Classes
One trained unit, as its |
Functions
Return where a unit's per-bar IC series and test-segment predictions are written. |
|
Return where fold |
|
Return where member |
|
Return a fresh, absolute |
|
Write the |
|
Write the |
|
Write the |
|
Write the |