Experimenter¶
mllabs.Experimenter
¶
Executes and manages a Pipeline experiment on a single dataset.
Splits data using sp (outer) and optionally sp_v (inner), then runs node builds and Trial experiments fold-by-fold.
No Project dependency, and nothing to inject but a cache: an
Experimenter owns its own :class:~mllabs.ExperimenterStore, built from
path, and everything needed to reopen it lives in that directory.
Project only supplies the path and records the name in its index.
Constructing is creating. It splits the data and writes a fresh state,
so pointing it at an existing directory starts over rather than
resuming — :meth:load_experimenter is how an existing one comes back.
A Pipeline is never a constructor argument either way; adopt one with
:meth:set_pipeline, which saves it as this Experimenter's pipeline.pkl.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
path
|
Its own base directory ( |
required | |
name
|
str
|
Experimenter name. This is its identity — the directory above and the key used in TrialStore history. |
required |
data
|
Input dataset (pandas DataFrame, polars DataFrame, or numpy array). |
required | |
data_names
|
list[str]
|
Column names override. |
None
|
sp
|
Outer splitter (sklearn splitter API). Default
|
ShuffleSplit(n_splits=1, random_state=1)
|
|
sp_v
|
Inner splitter for nested cross-validation. |
None
|
|
splitter_params
|
dict
|
Maps splitter keyword args to column
names in data, e.g. |
None
|
title
|
str
|
Human-readable experiment title. |
None
|
data_key
|
str
|
Identifier verified on reload to prevent data mismatch. |
None
|
cache
|
DataCache
|
Shared LRU cache. |
None
|
trial_store
|
TrialStore
|
Where this Experimenter reads the
Trials it is asked to run and records what they did. Injected once,
like cache, rather than re-supplied per call — a project has
exactly one and it does not change over an Experimenter's life. It
is not persisted: a |
None
|
resolver
|
Resolver
|
Resolves a stored spec's params into
live objects — used both by |
None
|
Attributes:
| Name | Type | Description |
|---|---|---|
cache |
DataCache
|
Shared LRU cache, or |
collectors |
Collectors
|
This Experimenter's own Collector registry, over
|
pipeline |
Pipeline
|
The adopted Pipeline, kept as this Experimenter's own
|
Note
build, exp and other node-graph-aware methods use
self.pipeline — call :meth:set_pipeline first.
pipeline_version
property
¶
The adopted Pipeline's version — None only for an in-memory build.
Read off :attr:pipeline rather than kept beside it, so there is no
second copy to fall out of step with it.
build(nodes=None, rebuild=False, n_jobs=1, gpu_id_list=None, logger=None)
¶
Build Stage nodes.
Staleness is settled when a Pipeline is adopted (:meth:set_pipeline),
so anything still on disk when this runs is current — it only builds
what is missing.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
nodes
|
Node query — |
None
|
|
rebuild
|
bool
|
If |
False
|
n_jobs
|
int
|
Number of parallel workers. Default 1 (sequential). |
1
|
gpu_id_list
|
list
|
GPU IDs to use for GPU-enabled nodes. |
None
|
logger
|
Logger instance. Default: shared |
None
|
close_os_log()
¶
Stop OS-level stdout/stderr capture started by :meth:open_os_log.
collect_errors(collectors=None)
¶
Collection failures recorded in this Experimenter's registry.
The read half of what :meth:remove_trial_result writes: a Collector's
history is this Experimenter's, so asking the project about it means
coming through here (Project.collect_errors).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
collectors
|
str | list[str]
|
Registered Collector names.
|
None
|
Returns:
| Type | Description |
|---|---|
|
list[dict]: |
|
|
|
|
|
— |
|
|
of the four points broke), |
|
|
Empty when nothing failed. |
|
|
here — that is |
error_nodes(nodes=None)
¶
Failed folds of this Experimenter's Pipeline nodes, one dict each.
Pipeline nodes only, as the name says. Error detail does not live on
the artifact (see NodeStore) — it is in this Experimenter's own
node_hist — so this reads history rather than walking fold
directories. Trial errors are the project's to report, since that is
where their history lives: Project.error_trials(experimenter=).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
nodes
|
list[str]
|
Node names to check. |
None
|
Returns:
| Type | Description |
|---|---|
|
list[dict]: |
|
|
|
|
|
|
|
|
a node's |
|
|
is |
exp(trials, collectors=None, n_jobs=1, gpu_id_list=None, logger=None)
¶
Run trials against the Stage graph and invoke matching Collectors.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
trials
|
list[str]
|
Trial names, out of :attr: |
required |
collectors
|
list[str]
|
Names to collect with, out of
this Experimenter's own :attr: |
None
|
n_jobs
|
int
|
Number of parallel workers. Default 1 (sequential). |
1
|
gpu_id_list
|
list
|
GPU IDs to use for GPU-enabled trials. |
None
|
logger
|
Logger instance. Default: shared |
None
|
Names, not Trials. A Trial belongs to the project, and this reads
it out of :attr:trial_store rather than taking a definition in.
Running was previously also how a Trial got registered, which put
authoring inside execution — you could not add one to the project
without executing it, and an exp() call could silently redefine a
name another Experimenter had already used. Authoring is Project.set_trial now,
and this only executes what is already there.
Every fold that actually runs records its outcome in the store as it
finishes (see :class:~mllabs._tracker.TrialHistTracker). Folds
skipped as already built produce no new row — their result was
recorded when they ran.
Raises:
| Type | Description |
|---|---|
RuntimeError
|
If this Experimenter has no |
KeyError
|
If a name is not registered in it. |
get_objs(node_name, outer_idx=0, inner_idx=0)
¶
(obj, result) for one built Pipeline node in one fold.
Nodes only — a Trial's fitted model is never written anywhere, so
naming one here raises FileNotFoundError. What a Trial produced
is whatever its Collectors kept.
get_status(node_name)
¶
Return the disk status of a Pipeline node across all folds.
One :class:NodeStore covers this whole Experimenter, every fold sharing the
same instance (told apart by outer_idx/inner_idx). Returns
the common status if all folds agree, or 'inconsistent' if they
differ.
Nodes only. A Trial persists nothing, so it is always None here
no matter how many times it has run — its per-fold status lives in
TrialStore.get_status(trial_name, experimenter).
Returns:
| Type | Description |
|---|---|
|
|
get_worker_logs(worker=None)
¶
Native (OS-level stdout/stderr) output captured while OS log
capture was open (see :meth:open_os_log/:meth:os_log).
Multi-worker build/exp (n_jobs > 1) redirect each worker's
stdout/stderr to {path}/__worker_logs/worker_{i}.log, capturing
native library chatter (TensorFlow, LightGBM, CatBoost, cuDNN/XLA) that
would otherwise pollute the console. This process's own (master)
output goes to worker_logs/master.log. Each execution overwrites
the previous.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
worker
|
|
None
|
Returns:
| Type | Description |
|---|---|
|
dict mapping worker index ( |
|
|
text, or a single string if worker is given. Empty if nothing |
|
|
was captured. |
load_experimenter(path, data, data_key=None, aug_data=None, cache=None, trial_store=None, resolver=None)
staticmethod
¶
Reopen the Experimenter rooted at path.
Everything comes out of that directory — meta and splitters from its
__exp.db, the Pipeline from its pipeline.pkl — so no Project
is involved and no pipeline_version is resolved.
The name is the directory's own.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
path
|
The Experimenter's base directory. |
required | |
data
|
Dataset to attach. Must match the original data shape. |
required | |
data_key
|
str
|
Must match the saved value, if one was given when the Experimenter was created. |
None
|
aug_data
|
optional
|
External data appended to inner train splits.
A live dataset, or an |
None
|
cache
|
DataCache
|
Shared LRU cache. |
None
|
trial_store
|
TrialStore
|
Not saved on disk, so a reopened Experimenter has one only if it is given one here. |
None
|
resolver
|
Resolver
|
Turns a Collector's stored spec
into live objects (see |
None
|
Returns:
| Name | Type | Description |
|---|---|---|
Experimenter |
The reopened Experimenter. |
Raises:
| Type | Description |
|---|---|
KeyError
|
If path holds no saved Experimenter. |
ValueError
|
If data_key does not match the saved value. |
open_os_log(log_path=None)
¶
Start capturing this process's OS-level stdout/stderr — native library chatter (TensorFlow, LightGBM, CatBoost, cuDNN/XLA) written directly to fd 1/2, which would otherwise pollute the console.
This only toggles OS-level log capture, independent of anything else on the Experimenter. While open:
build/expwithn_jobs=1run in this same process, so their native chatter is captured directly by this redirect — no separate handling needed per call.build/expwithn_jobs>1additionally redirect each worker's own native chatter to{path}/__worker_logs/worker_{i}.logfor the duration of that call. When log capture is not open, workers do not redirect at all (matches pre-existing behavior).
Call :meth:close_os_log to stop and restore the console. See also
:meth:os_log for a context-manager form.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
log_path
|
File to write to. Default:
|
None
|
os_log(log_path=None)
¶
Context manager form of :meth:open_os_log/:meth:close_os_log.
Usage::
with e.os_log():
e.build(n_jobs=1)
e.exp(n_jobs=4)
remove_trial_result(name)
¶
Drop what this Experimenter has of Trial name — its results and its history.
A Trial leaves no artifact, so its result is whatever its Collectors
kept, held in this Experimenter's own registry;
:meth:Collectors.remove_results clears that along with the matching
CollectHist rows. Its experiment_hist rows go too, which is what
makes the next exp() run the Trial again: folds are skipped on the
strength of a recorded 'built' status and nothing else, so the
history is the only thing holding one back.
Only this Experimenter's rows go — another Experimenter's record of the
same Trial is its own — and the definition stays, since it belongs to
the project. Removing that too is Project.remove_trial.
The history half is skipped when there is no :attr:trial_store,
leaving only the collected results to remove.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str
|
Trial name. |
required |
reset_nodes(nodes)
¶
Reset Pipeline nodes to init state.
Removes node objects and clears cache entries for the affected nodes.
Pipeline nodes only — the artifacts a build produced. A Trial has
none to remove; :meth:remove_trial_result is its counterpart.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
nodes
|
list[str]
|
Node names to reset. |
required |
set_pipeline(pipeline)
¶
Adopt an already-loaded Pipeline. It must be a published version.
Takes the Pipeline object directly rather than a version number —
this class has no way to load one by version itself (see the class
docstring); Project.add_experimenter() resolves that before
calling this. self.pipeline_version is read straight off
pipeline (its .version), so it's never tracked as a separate,
possibly-diverging value.
The same gate as Trainer.set_pipeline, and any published version
passes. This used to accept a draft too, on the grounds that
experimenting against a definition under edit is the point of
experimenting — but a Trial carries the version it was authored
against and is refused unless this Experimenter holds it, and an
adopted draft holds nothing to compare with. Publishing costs nothing
anyway: an unchanged definition builds to the number it already has.
The Pipeline is written to this Experimenter's own pipeline.pkl,
which is what the constructor reads back — reopening needs only this
directory, never a Project. Persisting requires an
experimenter_store; without one this Experimenter keeps the
Pipeline in memory only, the same way it skips saving its meta.
Moving between versions diffs the two Pipelines (:meth:Pipeline.diff_from)
and drops exactly the Stage artifacts the change invalidates: Stages
whose definition or inputs differ, everything downstream of them, and
Stages that no longer exist. Trials are left as-is — a Trial's
artifact and its TrialStore.experiment_hist row document the
pipeline version it actually ran against, which stays valid even
after a newer version is adopted; rerunning it is a separate,
explicit action.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
pipeline
|
Pipeline
|
Already-built, already-published Pipeline. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
Pipeline |
pipeline, unchanged. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If pipeline is a draft. |
stale_nodes(pipeline)
¶
Nodes whose artifacts adopting pipeline would drop.
The answer :meth:set_pipeline acts on, available before acting — that
call resets exactly this list, because it is this method's caller. One
implementation, so a preview cannot drift from the act it previews.
Asked before rather than after because adoption spends the answer:
staleness is derived by comparing two Pipelines
(:meth:Pipeline.diff_from) and immediately turned into deletions, so
afterwards there is no stale artifact left to find. Pass the published
Pipeline instead of a draft and the same call answers whether this
Experimenter is behind, and what catching up would cost.
Nothing is stale while nothing is adopted: the empty Pipeline is the absence of a prior definition, not a claim that nothing was built, and diffing against it would name every node here.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
pipeline
|
Pipeline
|
The candidate, already built. Building is what mints a version, so build first and then ask — this never builds, and so never publishes. |
required |
Returns:
| Type | Description |
|---|---|
|
list[str]: Node names, sorted. Names, not a claim that each has an |
|
|
artifact here — |
|
|
something to drop. |
uncollected_trials(collectors=None)
¶
Trials a Collector matches but has no result for, per Collector.
Answers the one question about this Experimenter that no single store
can: whether a Trial that ran here left the Collector anything.
experiment_hist knows what ran (project-wide, so this Experimenter's
rows are keyed by its name), collect_hist knows what was collected
(registry-local), and which Collectors even apply comes from matching
their Connectors against the Trial spec. All three meet here because
trial_store is injected and the registry is ours.
Written by hand the join tends to lose two things. A Trial that has no
history row at all reads as "collected" unless absence is checked for
separately, and a Trial that never ran reads as a collection failure —
which then invites remove_trial_result on history that was fine.
So only folds recorded 'built' here are considered, and a Trial is
reported when any of them lacks a 'collected' row: an 'error', an
'empty' (usually a misconfigured output_var) and a missing row
all fall on the same side, since all three mean nothing was kept.
A Trial that has not run is not a collection problem — that is
Project.pending_trials.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
collectors
|
str | list[str]
|
Registered Collector names.
|
None
|
Returns:
| Name | Type | Description |
|---|---|---|
dict |
|
|
|
Collector, empty list when it has everything. |
mllabs._cache.DataCache
¶
LRU cache shared by every Experimenter/Trainer in a Project.
Key is (scope, node, typ) — no outer_idx/inner_idx. scope
is a random id a TrainDataFlow generates for itself in its own
constructor (2026-08-01; was str(NodeStore.path) before — a real
collision risk once Experimenter/Trainer became constructible standalone
with an externally-supplied cache, since a bare Path string isn't
resolved to absolute and two different directories could coincide). A
TrainDataFlow instance is one specific (outer_idx, inner_idx) fold —
one gets constructed per fold, never shared — so its own scope id already
uniquely identifies which Experimenter/Trainer and which fold, without needing to fold path
strings or numeric coordinates into the key at all. The one thing this
trades away: a fresh reload (new Python objects, e.g. via
Project.load_experimenter) gets fresh scope ids, so cached entries
from a previous instance are never hit again — acceptable, since a cache
miss here just means recomputing, not wrong data.