Skip to content

Project

mllabs.Project

Root of a project directory.

Layout::

{path}/
  project.db          ProjectStore — what this project manages
  trials.db           TrialStore (definitions + execution history)
  data.pkl            the dataset everything here is built against
  ext_data/           named external data (ExtDataProvider) — {name}.pkl each.
                       aug_data lives here too now — register it under a
                       name and pass '@ext:name' as aug_data= to
                       add_experimenter/add_trainer; Project has no
                       aug_data storage of its own
  pipeline/           pipeline.db — the working copy, which is the
                       builder itself and never a version — plus
                       v{n}.pkl and v{n}_builder.pkl per published one
  exp/{name}/         Experimenter — its own store, Pipeline copy,
                       NodeStore and Collectors, all self-contained
  trainers/{name}/    Trainer (same, own NodeStore)
  inferencers/{name}/ saved Inferencers

Project holds what is project-wide — the dataset, the pipelines, the TrialStore, the shared cache — and keeps the components it hands out, so asking for the same name twice gives the same object rather than a second one over the same directory. Everything about an individual Experimenter or Trainer — its splitters, the Pipeline it adopted, its node artifacts and history, its Collectors — still belongs to its own directory, so it can be reopened without a Project at all.

The dataset is the exception that makes the rest work: it is the one thing they cannot restore from their own directories, so without it here every question about the project needs the caller to bring a dataframe.

There is no save(). Each component writes through as it changes, and a second place to persist from would be a second source of truth.

Parameters:

Name Type Description Default
path str | Path

Project root. Created if missing.

required
data

Dataset for this project. Stored under data.pkl and handed to every Experimenter/Trainer that does not override it.

None
cache_maxsize int

Stage-output cache size in bytes, shared by every Experimenter/Trainer in the project. Default 4 GB.

4 * 1024 ** 3

data property

The project dataset, read from disk on first use (None if unset).

experimenters property

This project's Experimenters, by name.

The objects, opened on demand — which needs the project's data, that being the one thing an Experimenter cannot read back from its own directory. :meth:list_experimenters answers the cheaper question of which names this project manages.

Only names not already held are opened, so one added through :meth:add_experimenter comes back as the very object that call returned. Two live Experimenters over one directory would each hold their own Collectors and node caches, and a change through one would be invisible to the other.

pipeline property

This project's :class:~mllabs.PipelineBuilder — the working copy.

One per project. The builder is the open version: it is the only editable state there is, and building it publishes whatever it currently says (see :meth:PipelineBuilder.build). Asking twice gives the same object rather than a second builder over the same db, which would let two in-memory copies of the definitions drift apart.

trainers property

This project's Trainers, by name. Opened like :attr:experimenters.

add_experimenter(name, data=None, pipeline_version=None, aug_data=None, **kwargs)

Add a new Experimenter named name, under {project}/exp/{name}.

An addition, so a taken name raises rather than being written over. Constructing an Experimenter splits the data afresh and resets its provenance, which over an existing one is damage rather than a reopen; reach for that one through :attr:experimenters.

Its name is its identity: it is both the directory and the key used in :class:~mllabs.TrialStore history.

Parameters:

Name Type Description Default
name str

Experimenter name.

required
data

Dataset for it. Defaults to the project's.

None
pipeline_version int

Version for it to adopt. Omitted, it adopts the published one — version 0, the empty Pipeline, until something has been built. Adopting an unpublished edit is a separate act: build it first.

None
aug_data

External data appended at DataSource level to inner train splits — a live dataset, or an '@ext:name' string resolved against self.ext_data (register it there first). No project-level default any more: omitted, there is none.

None
**kwargs

Passed to :class:~mllabs.Experimenter (sp, sp_v, splitter_params, title, data_key, ...).

{}

Raises:

Type Description
ValueError

If this project already manages name, or something else already occupies its directory.

add_trainer(name, data=None, pipeline_version=None, aug_data=None, **kwargs)

Add a new Trainer named name, under {project}/trainers/{name}.

Same shape as :meth:add_experimenter, and the same rule: a taken name raises. pipeline_version defaults the same way too — the latest published version. Any published version is adoptable, and this never hands over a draft, which is the one thing set_pipeline refuses.

chain_trial(src_name, name=None, pipeline_version=None, **overrides)

Author a Trial derived from an already-registered one.

Looks up src_name in :attr:trials, derives the successor via Trial.chain, and registers it through :meth:set_trial — so the freeze gate and version stamping apply exactly as they would to any other authored Trial.

Parameters:

Name Type Description Default
src_name str

Name of the registered source Trial.

required
name str

Name for the new Trial. Left unset, one is minted from self.trials.next_name(src_name) — a fresh number under src_name's own prefix.

None
pipeline_version, **overrides

Passed straight to Trial.chain.

required

Returns:

Type Description

str | None: The new Trial's name, or None if nothing

changed (see :meth:set_trial).

Raises:

Type Description
KeyError

If src_name is not registered.

collect_errors(experimenter=None, collectors=None)

Collection failures across the project, one dict each.

The third error read beside :meth:error_trials and Experimenter.error_nodes, and the only one that has to go through an Experimenter: a Collector's history belongs to the registry that owns it, and the registry is per-Experimenter. So this asks each one via Experimenter.collect_errors rather than reading a store of its own, and adds the experimenter key that collect_hist deliberately has no column for — which one it was is answered by whose db it is.

Parameters:

Name Type Description Default
experimenter str

Only this Experimenter's failures. None reads every one's.

None
collectors str | list[str]

Registered Collector names. None reads every one of them.

None

Returns:

Type Description

list[dict]: Experimenter.collect_errors rows with

experimenter added. Empty when clean.

error_trials(experimenter=None)

Failed folds of Trial execution, one dict each.

The Trial counterpart of Experimenter.error_nodes, and it lives here for the same reason that one lives there: a failure is read from whoever owns the history it is recorded in. Node history is the Experimenter's; Trial history is the project's, keyed by experimenter.

Parameters:

Name Type Description Default
experimenter str

Only this Experimenter's failures. None reads every one's.

None

Returns:

Type Description

list[dict]: trial_name, experimenter, outer_idx,

inner_idx, pipeline_version and the flattened failure

(type, message, traceback). Empty when clean.

list_experimenters()

Names of every Experimenter this project manages.

list_pipeline_versions()

Every published version: {version, path, builder_path} rows.

No status among them: being listed here is what published means, and a draft never reaches the store.

list_trainers()

Names of every Trainer this project manages.

load_pipeline(version=None)

A published version by number; without one, the latest.

A read, and only a read. It used to build :attr:pipeline when given no version, which publishes — so a call that reads like "load" minted a version, and adding an Experimenter did too. Minting now happens in one place, :meth:PipelineBuilder.build, where it is what you asked for.

There is always something to return: a project publishes the empty Pipeline as version 0 when it is created.

make_trials(name, generator, pipeline_version=None)

Author a batch of Trials from generator, registering all of them.

generator (e.g. :class:~mllabs.GridTrials) enumerates what each Trial should contain — it exposes combos() -> list[dict] of Trial constructor kwargs (processor/edges/method/adapter/params/ tag), nothing about names. This is where each combo becomes an identity: a name from self.trials.next_name(name) — assign, never derive, so growing or shrinking the batch never renames a sibling — and registration through :meth:set_trials, so the freeze gate and version stamping apply exactly as they would to any other authored Trial.

Parameters:

Name Type Description Default
name str

Prefix passed to next_name for every combo.

required
generator

Anything exposing combos() -> list[dict].

required
pipeline_version int

Applied to every Trial in the batch before registration. Left unset, set_trial fills in the latest published version per Trial — pass it to author the whole batch against an older one.

None

Returns:

Type Description

list[str]: Names of the Trials added or changed (see

meth:set_trials) — the work list for the next exp().

pending_trials(experimenter=None)

Registered Trials that errored or have not run.

The work list: a Trial with an 'error' fold, and one with no history at all, both still have to be executed and are indistinguishable in what they need. Written by hand this filter tends to catch only the second — the notebook's version did, so an errored Trial silently dropped out of the list of things left to do.

Deliberately coarse: a Trial interrupted partway through the folds is not reported, because deciding that means comparing history against a fold grid this store does not know. Running the returned names is safe either way — exp() skips the folds that are done.

Parameters:

Name Type Description Default
experimenter str

Judge against this Experimenter's history. None asks whether a Trial ran anywhere in the project.

None

Returns:

Type Description

list[str]: Trial names, in registration order.

publish_pipeline(experimenters=True, trainers=False, dry_run=False)

Build the working copy, move Experimenters and Trainers onto it, and report what that cost.

The sequence this exists for is: build, propagate, then author. It has to hold, because the pieces enforcing it are not the ones that would notice it broken. :meth:set_trial stamps a Trial with the latest published version, adopting is what gives an Experimenter a version to compare against, and exp() refuses a stamp that is not the adopted one. Build without propagating and the Trials authored next carry a version nothing holds — which surfaces as a refusal at exp(), some distance from the omission that caused it. One call spanning the project is the only place that ordering can live: an Experimenter knows nothing of its siblings, and a store knows nothing of either.

Trainers stay out unless asked for. The two sides do not pay the same price. An Experimenter loses node artifacts, which the next build() makes again. A Trainer loses trained models: adopting retires every Predictor whose inputs changed, and retirement is terminal. Work usually moves the other way round anyway — experiment, read the results, then promote into a Trainer — so a publish during experimentation should not reach into what has already been trained.

Leaving one behind strands nothing. A Trainer keeps its own Pipeline copy and its Predictors carry the version they were trained against, so it goes on working at the version it holds; train() refuses a mismatch rather than quietly doing the wrong thing. Moving it forward stays available as its own decision, here or through trainer.set_pipeline(project.load_pipeline()).

Building an unchanged definition returns the version it already has, so calling this out of habit costs nothing and moves nothing.

What comes back is the cost, not just the number: afterwards there is nothing left to ask, the artifacts being gone and the staleness consumed in deciding to delete them. The two losses are reported apart because they are not the same loss (see :meth:Trainer.retiring_predictors).

Propagation is sequential and not atomic: if one raises, the ones before it have already adopted. Repeating the call is the repair, adoption being idempotent once the version is held.

Parameters:

Name Type Description Default
experimenters bool

Propagate to this project's Experimenters. Default True.

True
trainers bool

Propagate to its Trainers. Default False — see above. Left False, they are neither adopted into nor opened, and are absent from the report.

False
dry_run bool

Report the cost and adopt nothing. Uses :meth:PipelineBuilder.draft rather than building, so asking what a publish would cost does not perform one — the same reason :meth:stale_nodes does. Pair it with trainers=True to price a Trainer before committing to it.

False

Returns:

Name Type Description
dict

{'version', 'experimenters', 'trainers'}, where

experimenters is {name: [node...]} and trainers is

{name: {'nodes': [...], 'retired': [...]}}. version is

None for a dry run — a draft carries no number.

remove_experimenter(name)

Delete the Experimenter named name — its directory, and its Trial history.

The history goes because the name is what keys it. Left behind, it would attach to whatever is added under that name next, and exp() would skip folds it had never actually run — the silent kind of wrong. Trial definitions are untouched: those belong to the project.

Raises:

Type Description
KeyError

If this project manages no Experimenter named name.

remove_pipeline_version(version)

Delete a published version. Not the latest one.

The latest is what :meth:load_pipeline and add_experimenter / add_trainer resolve to when given no number, so removing it would move that pointer silently. Any older one goes freely: nothing that ran against it breaks, since every Experimenter and Trainer holds its own Pipeline copy. What is lost is what their provenance points at.

remove_trainer(name)

Delete the Trainer named name — its directory, Predictors included.

Nothing outside it to clean up: a Trainer's history lives in its own stores rather than in a project-wide one.

Raises:

Type Description
KeyError

If this project manages no Trainer named name.

remove_trial(name)

Drop name from the project — definition, history and collected data.

A Trial leaves no artifact, so everything it produced is spread across stores that deliberately don't know about each other: its definition and per-fold history in the project's TrialStore, and — inside every Experimenter that ran it — the collected data and the CollectHist rows describing it. Project is the only thing that sees all of them, so removing a Trial belongs here.

Every Experimenter, with no way to ask for a subset. Leaving one out would leave results behind for a Trial the project no longer defines, and nothing afterwards would say which one still had them.

The definition and the whole of its history go in one statement each; the rest is a pass over :attr:experimenters, delegating to :meth:Experimenter.remove_trial_result. That opens the ones not already held, which is what makes the removal reach a Collector answering from an in-memory cache (ModelAttrCollector/ SHAPCollector) — a registry reopened from disk would not be the instance holding that cache.

Parameters:

Name Type Description Default
name str

Trial name. Removing one that was never registered is a no-op, not an error.

required

Raises:

Type Description
ValueError

If this project has no dataset, which opening an Experimenter needs.

set_collector(experimenter, name, collector, connector, path=None, params=None, exist='skip')

Register a Collector on experimenter's own registry.

A thin proxy, not ownership — Project holds no Collector registry of its own (a Collectors registry has to stay per-Experimenter, since everything it writes is keyed by node name only; see Experimenter.collectors). This just saves the caller from reaching through project.experimenters[experimenter].collectors by hand for the common case of registering one by name, the same way :meth:chain_trial saves a reach through self.trials.

Parameters:

Name Type Description Default
experimenter str

Name of the Experimenter to register it on.

required
name, collector, connector, path, params, exist

Passed straight to Collectors.set_collector — see there for what each means and what gets validated.

required

Returns:

Name Type Description
Collector

The registered collector.

Raises:

Type Description
KeyError

If this project manages no Experimenter named experimenter.

set_data(data)

Store data as this project's dataset.

set_trial(trial)

Add or update one Trial definition. Returns its name if anything changed.

Authoring a Trial is a project-level act, separate from running one. Registration used to be a side effect of Experimenter.exp(), which meant a Trial could not enter the project without being executed, and that one Experimenter could redefine a name another had already used.

A name that has already succeeded somewhere is frozen. The history is keyed by name, and a Trial leaves no artifact, so a redefinition would silently attach the old results to a definition that never produced them — the rows would look like one Trial's record and be two. Changing such a Trial means either a new name, or :meth:remove_trial to give up the results with it.

The version is stamped here. A Trial with no pipeline_version gets the latest published one, this being the only place that both knows the registry and owns the definition. Pass one explicitly to author against an older version; it has to exist, since a number no version answers to would be refused by every Experimenter with nothing to say why.

Stamping interacts with the freeze on purpose: after the pipeline moves on, re-registering a name that already succeeded is a changed definition, so it raises instead of quietly re-pointing results at a version that did not produce them. Give it a new name.

Parameters:

Name Type Description Default
trial Trial

Definition to store.

required

Returns:

Type Description

str | None: trial's name if it was added or changed, None if

the stored definition already matched — so the return value is the

work list for the next exp().

Raises:

Type Description
ValueError

If the name has a 'built' fold in experiment_hist and the definition differs from the stored one, or if trial names a version this project has never published.

set_trials(trials)

:meth:set_trial for many. Returns the names that were added or changed.

Nothing is written until every Trial has been checked, so a batch holding one frozen name changes nothing at all rather than leaving half of itself registered. Stamping comes first for the same reason — an unstamped Trial and the stored one differ in a field, so comparing before stamping would call every Trial changed.

stale_nodes(pipeline=None, experimenter=None, trainer=None)

What adopting a definition would cost, before adopting — both sides.

Delegates to Experimenter.stale_nodes and Trainer.stale_nodes, the same code each set_pipeline resets by — a preview of the real thing, not a second opinion about it.

The two are reported under separate keys rather than in one mapping because exp/{name} and trainers/{name} are separate namespaces: one name can exist in both, and a flat dict would drop whichever came second without saying so.

Nodes only, on both sides — and that understates a Trainer. A node named here comes back on the next build() / train(), whereas adopting also retires every Predictor whose inputs changed, which is terminal. For the whole price of a publish, ask publish_pipeline(dry_run=True, trainers=True); this stays about nodes, as its name says.

Defaults to the working copy as a :meth:PipelineBuilder.draft, which is a snapshot and not a publication. Asking what an edit would cost must not be what commits the edit: add_experimenter / add_trainer adopt the latest version by default, so a mere preview would change what the next call adopts.

Pipeline nodes only. A Trial is never reset by adoption — its experiment_hist row records the version it ran against and stays a true record of it, so rerunning is a separate, explicit act.

Parameters:

Name Type Description Default
pipeline Pipeline

The candidate. None uses the working copy as it stands. Pass :meth:load_pipeline output instead to ask the other direction — how far behind the published definition each Experimenter is.

None
experimenter str

Ask only this Experimenter.

None
trainer str

Ask only this Trainer.

None

Naming either narrows to exactly what was named: with neither given every Experimenter and Trainer answers, with one given the other side comes back empty rather than silently answering in full.

Returns:

Name Type Description
dict

``{'experimenters': {name: [node...]},

'trainers': {name: [node...]}}``, an empty list for one the

change does not touch.

uncollected_trials(experimenter=None, collectors=None)

Trials that ran but left a matching Collector nothing.

A Collector cannot answer this alone — it is keyed by node name and knows nothing of the project — so the question is asked here and delegated to Experimenter.uncollected_trials, which has the project's trial_store injected and owns the registry.

Parameters:

Name Type Description Default
experimenter str

Ask only this one. None asks every Experimenter in the project.

None
collectors str | list[str]

Registered Collector names. None asks about every one of them.

None

Returns:

Name Type Description
dict

{experimenter_name: {collector_name: [trial_name, ...]}} —

nested rather than flattened so the answer stays readable when a

Trial name appears under more than one Experimenter.

mllabs.TrialStore

Bases: ArtifactStore

Registry of Trial definitions plus a per-fold execution history.

Inherits :class:~mllabs._store.ArtifactStore's method shape but does not override any of it — it never persists obj/result artifacts, only definitions (trials) and execution history (experiment_hist). See ArtifactStore for why the interface is shared anyway.

stores_artifacts is left at the base class's False, which is what lets Experimenter.exp() hand this store to the executor the same way build() hands it a NodeStore: the executor asks the store whether there is anything to persist, and this one says no.

get_by_name(name)

Stored definition for name as a :class:~mllabs.Trial, or None.

get_hist(trial_name=None, experimenter=None, pipeline_version=None, status=None)

History rows matching whichever filters are given.

Each row's info is decoded back into a dict (None if it was never recorded).

get_info(trial_name, experimenter)

{(outer_idx, inner_idx): info} for one trial in one experimenter.

get_status(trial_name, experimenter)

{(outer_idx, inner_idx): status} for one trial in one experimenter.

has(trial)

Whether trial's exact definition is the one stored under its name.

False when nothing is stored under the name at all, so a caller guarding a redefinition does not have to check for absence separately. Compares what execution depends on; desc/tag/src_trial are display and provenance metadata and do not make a definition a different one.

pipeline_version is compared. It decides where the Trial is allowed to run, so the same fields against a different version are a different definition — which is what makes Project.set_trial refuse to re-point a name that has already succeeded, rather than leaving the rule to convention.

next_name(name_or_prefix)

A fresh {prefix}{seq} name derived from name_or_prefix.

name_or_prefix may be a bare prefix ('lgb') or an existing Trial's own name ('lgb5') — either way, the prefix is its leading non-digit run. The number is this store's next global sequence value (see :meth:next_seq), never derived from what already exists under that prefix, so it stays stable even after a prefix's highest existing number is removed.

Two calls never collide with each other, though a caller is still free to hand-pick a name that does — Project.set_trial's freeze gate is what would catch that, the same as any other redefinition.

next_seq()

This TrialStore's next global naming sequence value.

A plain persisted auto-increment counter — the same role PipelineStore's MAX(version) + 1 plays for Pipeline versions, just backed by its own table rather than derived from the rows it names, since a Trial name (unlike a version) is never reused.

record(trial_name, experimenter, outer_idx, inner_idx, pipeline_version=None, status=None, info=None)

Upsert one fold's outcome.

Parameters:

Name Type Description Default
trial_name str

Trial name — also its artifact directory.

required
experimenter str

The Experimenter's name.

required
outer_idx int), inner_idx (int

Fold coordinates.

required
pipeline_version int

The Pipeline version this ran against (the Experimenter's pipeline_version).

None
status str

'built' or 'error'.

None
info dict

Everything _process()/_write_prep_error produced besides status — build_id, definition, fit_time, edges, train_shape, warnings, and, on failure, error. JSON-encoded.

None

register(trial)

Store trial's definition under its name.

name is the row's identity, so redefining a name overwrites its row exactly as it overwrites the artifact on disk.

Parameters:

Name Type Description Default
trial Trial

Trial to register.

required

register_all(trials)

Register every Trial in trials.

remove(name)

Delete the definition stored under name.

The definition only — experiment_hist is left alone, so what ran stays readable after the definition it ran is gone. Dropping a Trial from the project entirely spans this store, CollectHist and the Collectors' own data, which no single store can see: that is Project.remove_trial(name).

mllabs.ExtDataProvider

Named registry of external data, persisted one pickle per name.

Nothing is held in memory between calls — get reads straight off disk every time, register writes and forgets. A registry that cached would trade an unbounded number of entries against a byte budget it would then have to police, the way DataCache does for computed node outputs. Reading fresh instead means nothing here is ever evicted — appropriate because this data is not recomputable, it is exactly what the caller handed in — at the cost of a disk read per request. That cost is cheap where it is paid: a Collector reads this once per fold, not in a hot loop.

Parameters:

Name Type Description Default
path str | Path

Base directory — one file per registered name, created if missing.

required

get(name)

name's data, read fresh from disk.

Raises:

Type Description
KeyError

If nothing is registered under name.

names()

Every registered name, sorted.

register(name, data)

Persist data under name, overwriting whatever was there.

remove(name)

Delete name's file. No-op if nothing was registered under it.

size(name)

name's file size in bytes, or None if unregistered.

sizes()

{name: bytes} for every registered name.

mllabs.Resolver

ext_data (ExtDataProvider, optional): Backs '@ext:name' param values. Left unset, encountering one raises rather than silently passing the literal string through.

instance(spec)

String ref / {'__ref__': ...} spec -> instance (adapter, connector).

params(params)

Every value in params, resolved via :meth:value.

{'__ref__': ...}/{'__callable__': ...} specs resolve via resolve_ref_values exactly as they do for a Processor. '@ext:name' strings resolve against :attr:ext_data. Plain dicts/lists are recursed into so an @ext: reference nested inside one is still found; a value already inside a __ref__/ __callable__ spec is handed to resolve_ref_values whole; it does not by itself understand @ext:.

processor(processor)

"module.ClassName" string -> class.

value(value)

One value, resolved — what :meth:params maps over a dict with, and what anything holding a bare '@ext:name' outside of a params dict (Experimenter/Trainer's aug_data, say) calls directly instead of hand-rolling the same @ext: check.