Trials & Predictors¶
A Trial is a candidate the Experimenter evaluates; a
Predictor is one the Trainer commits to training. Both resolve
to the same ProcessorSpec — what differs is the question each answers.
mllabs.Trial
¶
One concrete configuration to evaluate — what used to be a Head node.
A Trial carries the same definition a Head node carried (processor, method,
adapter, params, edges) but is handed straight to Experimenter.exp
rather than declared on a :class:~mllabs.PipelineBuilder.
name is the identity: human-readable, stable, and used as the on-disk
artifact directory and the :class:~mllabs.TrialStore key — the same role
the Head node name played. Redefining a name overwrites both the artifact
and its TrialStore row.
pipeline_version is part of the definition, not a note about it. A
Trial's own fields say nothing about the preprocessing it reads, and it
does not live in the pipeline, so the graph cannot tell it that its inputs
changed; naming the version it was authored against is how it says which
definition it means. Experimenter.exp refuses to run it against any
other version, so the same name can never accumulate results from two
different pipelines. Experimenter.set_pipeline still does not cascade
into Trials — adopting a new version leaves their history alone, and what
the version stamp adds is that they simply stop running there.
Project.set_trial fills it in with the latest published version when it
is left unset, so authoring one by hand does not mean tracking versions by
hand.
The Trainer side makes the opposite call, which is why it has its own
:class:~mllabs.Predictor rather than reusing this class: a Trainer keeps
no past executions to preserve, so a model trained against a since-changed node is
just stale and Trainer.reset_nodes cascades into it.
Attributes:
| Name | Type | Description |
|---|---|---|
name |
str
|
Identifier, also the artifact directory name. |
processor |
str
|
|
method |
str
|
Processor method ( |
adapter |
|
|
params |
dict
|
Constructor params — plain data or ref specs only. |
edges |
dict
|
|
desc |
str
|
Human-readable description. Display-only, like
|
tag |
list[str]
|
Selection tags. |
pipeline_version |
int | None
|
The Pipeline version this was authored
against. |
src_trial |
str | None
|
Name of the Trial this one was chained from,
if any. Reference only — no foreign key, no validation, and no
staleness: it is never checked against what |
chain(name, pipeline_version=None, **overrides)
¶
A new Trial derived from this one, with src_trial recorded.
Every field not named in overrides is inherited verbatim, except
params and edges, which never fully replace — params is
merged over self.params (only the given keys change) and
edges is combined per key the same way a Pipeline node's own
edges extend its group's: a value starting with '+'/'-'
continues self's (already-resolved) string for that key, anything
else replaces it outright, and a key left out of overrides
inherits unchanged.
Overrides are read by presence, not by value — adapter=None in
overrides clears the adapter, which a plain keyword default could
not distinguish from "not given".
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str
|
Name for the new Trial. Required: |
required |
pipeline_version
|
int
|
|
None
|
**overrides
|
Any of |
{}
|
Returns:
| Type | Description |
|---|---|
|
Trial |
get_spec()
¶
This Trial's :class:~mllabs._pipeline.ProcessorSpec.
The same shape Pipeline.get_node_spec returns for a Stage, so
Connectors, the executor, and Collectors treat the two identically.
desc/tag are display/selection metadata and stay on the Trial
itself rather than riding along in the spec.
node_names()
¶
Names of the Pipeline nodes this Trial's edges read.
Only direct references are needed: callers intersect this against a
set of reset/stale node names that is already transitively closed
(Pipeline.diff_from cascades through output_edges before
checking Trials), so the chain is covered without this method walking
it itself.
mllabs.GridTrials
¶
Cartesian-product param sweep over one fixed processor.
A generator for :meth:~mllabs.Project.make_trials — it enumerates what
a batch of Trials should contain (processor/method/adapter/params/
edges/tag), not what they are named. Naming is assign-based
(TrialStore.next_name) and lives entirely on the Project side, on
purpose: a name derived from grid position — as the old free-function
make_trials did — renames every sibling combo when the grid grows,
or worse, silently repoints a name at a different combo when an axis
gains a value in the middle of the sort order. Keeping this class
unaware of names is what makes that defect structurally impossible
here, not just avoided by convention.
Every combo shares processor/method/adapter/edges; params holds the
values constant across the sweep and param_grid ({param: [values]})
is expanded as a cartesian product::
gen = GridTrials(
processor='lightgbm.LGBMClassifier',
edges={'X': 'scaler:(*)', 'y': '{target}'},
params={'random_state': 42},
param_grid={'max_depth': [3, 5], 'learning_rate': [0.05, 0.1]},
)
project.make_trials('lgbm', gen)
Order is deterministic (grid keys sorted, values in the order given), so the same instance always produces the same sequence of combos.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
processor
|
str
|
|
required |
edges
|
dict
|
|
required |
method
|
str
|
Processor method. Default |
'predict'
|
adapter
|
|
None
|
|
params
|
dict
|
Params fixed across the sweep. |
None
|
param_grid
|
dict
|
|
None
|
tags
|
list[str]
|
Tags applied to every combo. |
None
|
combos()
¶
Every combo as Trial constructor kwargs, minus name.
Returns:
| Type | Description |
|---|---|
|
list[dict]: each with |
|
|
|
mllabs.Predictor
¶
The terminal output node a :class:~mllabs.Trainer trains.
Structurally a Predictor carries the same execution definition a
:class:~mllabs.Trial does (processor, method, adapter, params, edges) —
both become a :class:~mllabs._pipeline.ProcessorSpec the executor
cannot tell apart. What differs is what the definition means:
- A Trial is a candidate being evaluated. Many are run per Experimenter,
across folds, and their point is comparison — hence the project-wide
:class:
~mllabs.TrialStorecollecting definitions and per-fold outcomes from every Experimenter in one place. - A Predictor is a choice already made. It is trained on the real splits
to be shipped, so what matters is provenance (
src_trial/src_experimenter— which evaluated candidate justified it) rather than comparability, and its registry is per-Trainer.
Keeping them separate is what lets the Trainer side own that provenance
and its own storage without widening Trial/TrialStore, which stay
exactly as the Experimenter uses them.
name is the identity: the artifact directory under the Trainer's
predictor store and the :class:~mllabs.PredictorStore key. Redefining a
name overwrites both.
Attributes:
| Name | Type | Description |
|---|---|---|
name |
str
|
Identifier, also the artifact directory name. |
processor |
str
|
|
method |
str
|
Processor method ( |
adapter |
|
|
params |
dict
|
Constructor params — plain data or ref specs only. |
edges |
dict
|
|
desc |
str
|
Human-readable description. Display-only. |
tag |
list[str]
|
Selection tags. |
src_trial |
str
|
Name of the Trial this was promoted from, if any. |
src_experimenter |
str
|
Name of the Experimenter that evaluated
|
pipeline_version |
int | None
|
The Pipeline version this is defined
against — copied from the Trial by :meth: |
from_trial(trial, name=None, experimenter=None)
classmethod
¶
Promote an evaluated trial into a Predictor.
The execution definition is copied verbatim — the promoted Predictor
trains exactly what was evaluated — and the Trial's name is recorded
as src_trial even when name overrides the Predictor's own.
pipeline_version is part of that verbatim copy, so the Predictor
requires the version its candidate was evaluated against and
Trainer.train refuses to train it under any other. Adopt that
version in the Trainer — every published version is adoptable, and
nothing else would be training what was actually measured. No separate
provenance field records it, because this one already does.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
trial
|
Trial
|
The evaluated candidate to promote. |
required |
name
|
str
|
Name for the Predictor. Defaults to the Trial's own name. |
None
|
experimenter
|
str
|
Name of the Experimenter that
evaluated trial, recorded as |
None
|
Returns:
| Type | Description |
|---|---|
|
Predictor |
get_spec()
¶
This Predictor's :class:~mllabs._pipeline.ProcessorSpec.
The same shape Pipeline.get_node_spec returns for a Pipeline node
and Trial.get_spec for a Trial, so the executor treats all three
identically. desc/tag and the src_* provenance are
metadata and stay on the Predictor itself.
node_names()
¶
Names of the Pipeline nodes this Predictor's edges read.
Only direct references, for the same reason as Trial.node_names:
callers intersect this against an already transitively closed set of
stale node names.
mllabs.PredictorStore
¶
Registry of one Trainer's Predictor definitions.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
path
|
Directory holding the store — the Trainer's predictor
directory, shared with the |
required |
get_by_name(name)
¶
Stored :class:~mllabs.Predictor for name, or None.
get_status(name)
¶
Stored status for name, or None if it is not registered.
has(predictor)
¶
Whether predictor's exact definition is the one stored under its name.
pipeline_version counts, for the same reason it does in
TrialStore.has: it decides which Trainer state the definition may
be trained under, so the same fields against another version are
another definition.
list_names(status=None)
¶
Stored names, optionally only those in status.
list_predictors()
¶
Every stored Predictor, in the order they were registered.
Returns :class:~mllabs.Predictor objects rather than dicts — this
is what :meth:Trainer.load hands straight back to
:meth:Trainer.set_predictors.
list_status()
¶
{name: status} for every stored Predictor.
One query, so a caller deciding across the whole registry — which to build Jobs for, which to restamp — does not ask per name.
register(predictor)
¶
Store predictor's definition under its name.
An upsert that writes every definition field and leaves status
alone, rather than INSERT OR REPLACE, which would silently return
a Predictor to :data:INIT every time its row is rewritten —
including on Trainer.train's re-registration of what it was just
handed, and on the restamp that follows adopting a version. Status
changes only through :meth:set_status, where something decided it.
register_all(predictors)
¶
Register every Predictor in predictors.
replace_all(predictors)
¶
Make predictors the entire stored selection.
Names no longer selected are dropped, so what comes back from
:meth:list_predictors is always the current selection rather than
everything a Trainer ever trained. Insertion order is preserved.
set_status(name, status)
¶
Move name to status. No-op if the name is not stored.
Comparing specs¶
compare_specs diffs any {name: ProcessorSpec} mapping — most often Trial
specs ({t.name: t.get_spec() for t in trials}), but Pipeline node specs work
the same way since both resolve to ProcessorSpec.
mllabs.compare_specs(specs)
¶
Common and differing elements across a group of ProcessorSpecs.
Specs are grouped by processor (same processor = comparable apples to apples). Within each group:
method/adapterare binary — a scalar value either agrees everywhere or it does not. It lands incommonunder that name when every spec agrees, otherwise indiffas apd.Serieskeyed by name — present in exactly one of the two, never both, never neither.paramssplits per key: a key whose value is identical across the whole group joinscommon['params']; any other key becomes a column ofdiff['params'](a DataFrame, index=name), holding each spec's own value for it.edgessplits the same way, but per(edge key, source-node segment)rather than per whole-key, and unlike a scalar param the overlap can be partial: the intersection of variables — even when it is not everyone's whole set — goes intocommon['edges'][key][source], and each spec's remaining variables (the intersection subtracted out) become a column ofdiff['edges']. A segment identical everywhere ends up entirely incommon, with no column indiffat all — nothing left over once the shared part is subtracted.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
specs
|
dict[str, ProcessorSpec]
|
|
required |
Returns:
| Type | Description |
|---|---|
|
dict[str, dict]: |
|
|
Both |
|
|
|
|
|
respectively) even when empty; |
|
|
whichever of the two actually has something to say. |