Collectors¶
Registry and history¶
mllabs.Collectors
¶
Registry that owns Collector instances and their storage.
One registry belongs to one Experimenter — it builds its own over
{exp path}/collectors and hands it out as Experimenter.collectors.
Everything a Collector writes is keyed by node name and nothing more
(MetricCollector's PK is (node, idx, inner_idx, split); the
file-based ones use {path}/{node}...), so the path is what keeps two
Experimenters apart. Sharing one registry between them would have them overwrite
each other's results for every Trial whose name they have in common —
silently, and precisely when the results were worth comparing.
Registration persists immediately when the registry has a path: a
:class:CollectorEntity row goes into {path}/collectors.db and the
constructor params into {path}/__params/{name}.pkl. Constructing a
registry over that path rebuilds every Collector registered before from
those two halves — the instance itself is never stored.
hist is the :class:~mllabs.CollectHist over the same path — one row
per (collector, node, fold) describing what that collect call did. It has
no experimenter column because the registry holding it already belongs
to one.
Turning a stored CollectorEntity/params pair into a live instance is
this class's job, not the store's — _build is the one place that
happens, using an injected :class:~mllabs.Resolver. CollectorStore
only ever hands back entities and params, never an instance.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
path
|
str | Path
|
Base directory. A Collector registered
without an explicit |
None
|
resolver
|
Resolver
|
Turns a stored spec into live objects.
Defaults to a bare |
None
|
match(node_attrs, names=None)
¶
Collectors among names whose Connector matches node_attrs.
remove_results(node_name)
¶
Drop everything collected for node_name — data and history both.
The registry is the only thing that sees both halves: hist records
what each collect call did, while the result itself is inside whichever
Collector produced it. Removing one without the other leaves a history
row pointing at data that is gone, or data no history accounts for.
Definitions are untouched — this removes what a node produced, not the Collectors that were watching for it.
resolve(names)
¶
Collector instances for names (None → every registered one).
Raises:
| Type | Description |
|---|---|
KeyError
|
If a name is not registered — a silent miss would look exactly like "this collector produced nothing". |
set_collector(name, collector, connector, path=None, params=None, exist='skip')
¶
Build and register a Collector from its parts.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str
|
Collector name — what an Experiment refers to it by. |
required |
collector
|
str
|
|
required |
connector
|
|
required | |
path
|
str | Path
|
Storage directory. Defaults to
|
None
|
params
|
dict
|
Remaining constructor parameters (everything after
|
None
|
exist
|
str
|
|
'skip'
|
Returns:
| Name | Type | Description |
|---|---|---|
Collector |
The registered collector. |
Raises:
| Type | Description |
|---|---|
TypeError
|
If collector/connector/params hold a live object rather than plain data or a ref spec. |
mllabs.CollectHist
¶
Per-fold outcome of every collect call, for one Experimenter's registry.
Lives beside the :class:~mllabs.Collectors registry that owns it, which
is one Experimenter's — so a row is identified by
(collector_name, node_name, outer_idx, inner_idx) alone and nothing
here needs an experimenter column, the same way node_hist needs no
run_name.
It is a log, not a gate: nothing is skipped on the strength of a row here. What it does make visible is a fold recorded 'built' before a Collector was attached — that fold is skipped without dispatch, so it collects nothing, and the absence of a row is the only trace of it.
mllabs.CollectorStore
¶
Persistence for Collector definitions — storage only.
Reads and writes CollectorEntity/params, nothing more. Turning those
back into a live Collector instance is Collectors' job (see
_registry.py's _build, using an injected Resolver) — this
class never imports or instantiates anything itself.
params is a TEXT column (serialize_to_json/deserialize_from_json),
same shape as connector and the same mechanism PipelineBuilder
uses for node/group params — not the separate pickle file it used to be.
That was only ever needed because a live object (ProcessCollector's
ext_data, say) could slip through unvalidated; Collectors.set_collector
now rejects one with _validate_params the same way PipelineBuilder
does, and an '@ext:name' string (see Resolver) is how that data
gets in instead.
mllabs.CollectorEntity
¶
of(name, collector, connector, path)
classmethod
¶
collector/connector are already validated spec values by the
time this is called (see Collectors.set_collector) — this just
assembles them, no conversion left to do.