Pipeline¶
mllabs.PipelineBuilder
¶
Node graph that describes an ML workflow.
Holds groups (:class:_PipelineGroup) and nodes (:class:_PipelineNode).
The implicit DataSource node is stored as nodes[None].
Attributes:
| Name | Type | Description |
|---|---|---|
grps |
dict[str, _PipelineGroup]
|
All registered groups. |
nodes |
dict[str | None, _PipelineNode]
|
All nodes, keyed by name.
|
build()
¶
Resolve group inheritance and return an immutable, published :class:Pipeline.
This is the hand-off point to Experimenter/Trainer/Inferencer: they take
the built Pipeline, never the builder, so later set_grp/set_node
calls do not reach into work already in progress.
Building publishes. A version appears here, and exactly when the
definition changes — an unchanged builder returns the version it
already has rather than a duplicate of it. There is no separate publish
step, and :meth:draft is the only way to get an unnumbered snapshot,
so anything that can be adopted can name itself and every history row
can name the definition it ran on.
Returns:
| Name | Type | Description |
|---|---|---|
Pipeline |
Snapshot with every node's inherited values resolved, |
|
|
carrying |
Raises:
| Type | Description |
|---|---|
ValueError
|
If this builder has no db to publish into. Such a
builder can still produce a snapshot — that is :meth: |
check_data_compatibility(data)
¶
Verify data contains every column declared in the DataSource schema.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
data
|
DataWrapper
|
Wrapped dataset to check. |
required |
Raises:
| Type | Description |
|---|---|
ValueError
|
If any schema column is missing from data. |
copy()
¶
Return a deep copy of the entire pipeline.
Returns:
| Name | Type | Description |
|---|---|---|
PipelineBuilder |
New pipeline with all groups and nodes copied. |
copy_nodes(node_names)
¶
Return a copy containing the specified nodes and all their ancestors.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
node_names
|
list[str]
|
Target node names. Their upstream Stage dependencies are included automatically. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
PipelineBuilder |
Minimal pipeline needed to run node_names. |
desc_node(node_name, direction='TD', show_params=False)
¶
특정 노드까지의 연결 구조를 Mermaid Markdown으로 반환
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
node_name
|
대상 노드 이름 |
required | |
direction
|
그래프 방향 ('TD': Top-Down, 'LR': Left-Right) |
'TD'
|
|
show_params
|
True이면 노드의 파라미터 정보를 표시 (default: False) |
False
|
desc_pipeline(max_depth=None, direction='TD')
¶
파이프라인 구조를 Mermaid Markdown으로 반환
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
max_depth
|
최대 표시 깊이 (None이면 무제한) |
None
|
|
direction
|
그래프 방향 ('TD': Top-Down, 'LR': Left-Right) |
'TD'
|
draft()
¶
The same snapshot :meth:build makes, unregistered.
version is None and status is 'draft', because being
stored is what publishing is and this was not. Use it to look at what
the working copy currently says — Project.stale_nodes asks what
adopting the current edits would cost — without that question being
what commits them.
A draft cannot be adopted: set_pipeline refuses it on both
Experimenter and Trainer. An unnumbered definition would leave runs
unable to say what they ran against, which is the whole reason
build() publishes.
Returns:
| Name | Type | Description |
|---|---|---|
Pipeline |
Snapshot with every node's inherited values resolved, |
|
|
unnumbered. |
get_node_names(query)
¶
Resolve a node query to a list of node names.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
query
|
|
required |
Returns:
| Type | Description |
|---|---|
|
list[str]: Matching node names (DataSource |
|
|
str/list queries). |
get_node_spec(name)
¶
Fully resolved :class:ProcessorSpec for a node (group hierarchy merged).
Stage nodes only — the DataSource (name=None) has no spec; reach
its schema/targets via builder.datasource.get_attrs().
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str
|
Node name. |
required |
Returns:
| Type | Description |
|---|---|
|
ProcessorSpec |
set_datasource(schema, targets=None)
¶
Define the input data schema and target columns.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
schema
|
dict[str, str]
|
{col_name: var_type}. var_type must be one of 'numerical', 'ordinal', 'nominal', 'text', 'binary', 'datetime'. |
required |
targets
|
list[str]
|
Target column names. Must all exist in schema. |
None
|
Returns:
| Name | Type | Description |
|---|---|---|
str |
|
Raises:
| Type | Description |
|---|---|
ValueError
|
If any type is invalid or any target column is not in schema. |
set_grp(name, processor=None, edges=None, method=None, parent=None, adapter=None, params=None, desc=None, exist='diff')
¶
Create or update a group.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str
|
Group name. Cannot contain |
required |
processor
|
|
None
|
|
edges
|
dict
|
Edge definitions |
None
|
method
|
str
|
Processor method name (e.g. |
None
|
parent
|
str
|
Parent group name, or |
None
|
adapter
|
ModelAdapter instance, a |
None
|
|
params
|
dict
|
Constructor parameters for the processor. A value of
the form |
None
|
exist
|
str
|
Conflict resolution — |
'diff'
|
Returns:
| Name | Type | Description |
|---|---|---|
dict |
|
|
|
|
Raises:
| Type | Description |
|---|---|
ValueError
|
If name is invalid or edges form a cycle. |
set_node(name, grp, processor=None, edges=None, method=None, adapter=None, params=None, desc=None, exist='diff')
¶
Create or update a node.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str
|
Node name. |
required |
grp
|
str
|
Group the node belongs to. |
required |
processor
|
|
None
|
|
edges
|
dict
|
Edge definitions |
None
|
method
|
str
|
Method name override. |
None
|
adapter
|
|
None
|
|
params
|
dict
|
Constructor parameter overrides. Plain data only; a
value of the form |
None
|
exist
|
str
|
Conflict resolution — |
'diff'
|
Returns:
| Name | Type | Description |
|---|---|---|
dict |
|
Raises:
| Type | Description |
|---|---|
TypeError
|
If processor/adapter/params hold live objects instead of string refs or ref specs. |
ValueError
|
If the resolved processor or method is missing, edges are invalid, or a cycle would be created. |
sync()
¶
Update in-memory PipelineBuilder state to match the SQLite DB.
DB is always the source of truth. Each element is compared and overwritten if different. After applying all changes, children, grp.nodes, and output_edges are fully rebuilt.
Returns:
| Name | Type | Description |
|---|---|---|
dict |
{ 'datasource': 'updated' | 'skip', 'grps': {'added': [...], 'removed': [...], 'updated': [...]}, 'nodes': {'added': [...], 'removed': [...], 'updated': [...]}, |
|
|
} |
Raises:
| Type | Description |
|---|---|
ValueError
|
If PipelineBuilder has no DB path. |
mllabs.Pipeline
¶
Immutable node graph produced by :meth:PipelineBuilder.build.
Holds only what running the graph needs: nodes with every group-inherited
value already resolved, plus the DataSource schema. Groups do not survive
the build, and a node's originating group name is kept as label.
A Pipeline holds Stages only; Heads are now :class:~mllabs.Trial objects
handed to Experimenter.exp.
Consumers (Experimenter, Trainer, Inferencer) hold one of these rather than a builder, so later edits to the builder cannot silently change work that is already under way.
Attributes:
| Name | Type | Description |
|---|---|---|
nodes |
dict[str | None, _BuiltNode]
|
Nodes keyed by name. |
pipeline_id |
str
|
Identity of the builder this was built from. |
build_id |
str
|
Identity of this particular build. |
version |
int | None
|
The number this Pipeline is stored under, set by
:meth: |
status |
str
|
|
is_empty
property
¶
No nodes at all — only the DataSource, which nodes always holds.
What it means depends on which side of an adoption you are on: as the Pipeline being adopted, nothing to build; as the one being replaced, nothing that was ever adopted, so nothing a switch could invalidate.
check_data_compatibility(data)
¶
Verify data contains every column declared in the DataSource schema.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
data
|
DataWrapper
|
Wrapped dataset to check. |
required |
Raises:
| Type | Description |
|---|---|
ValueError
|
If any schema column is missing from data. |
descendants(name)
¶
Names of every node downstream of name.
diff_from(old)
¶
Names whose output would differ from old — i.e. what is now stale.
Walks this Pipeline from the DataSource downwards. A node is unchanged only if it exists in old under the same name, its definition matches, and every node it reads is itself unchanged; otherwise it is stale, and so is everything downstream of it (which falls out of the walk, since the walk is in topological order).
Names that existed in old but are gone here are reported too, so their artifacts can be cleaned up rather than left orphaned.
A DataSource whose schema or targets changed only stales a node if the DataSource-origin variables its own edges actually pull differ between the two schemas — a node that never reads the changed column(s) stays put.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
old
|
Pipeline
|
The previously adopted Pipeline. |
required |
Returns:
| Type | Description |
|---|---|
|
set[str]: Node names to reset. |
empty(pipeline_id=None)
classmethod
¶
A Pipeline with no nodes — "there is nothing to build", as an object.
Having no pipeline is a legitimate state, not a missing one: Trials
read the DataSource directly, so an Experimenter with no nodes at all
still runs. Saying that with an empty Pipeline rather than None
means every consumer stays branch-free — build() finds no jobs,
topo_order() is empty, check_data_compatibility passes
vacuously — instead of each one guarding for absence.
Inside a Project this is version 0, published at creation, so the empty
state is a real row rather than a fabricated object. This constructor
is for the standalone case, where there is no store to mint from, and
what it returns is a draft for exactly that reason: it never came from
one. It is the only Pipeline an Experimenter or Trainer holds without
having adopted it, and set_pipeline replaces it before anything
runs.
get_node_names(query=None)
¶
Resolve a node query to a list of node names.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
query
|
|
None
|
Returns:
| Type | Description |
|---|---|
|
list[str]: Matching node names (DataSource |
|
|
str/list queries). |
get_node_spec(name)
¶
This node's :class:ProcessorSpec — see :meth:_BuiltNode.get_spec.
Stage nodes only. The DataSource (name=None) has no spec — reach
its schema/targets via pipeline.datasource.
subset(node_names)
¶
Return a new Pipeline with node_names and all their ancestors.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
node_names
|
list[str]
|
Target node names. Upstream dependencies
referenced through |
required |
Returns:
| Name | Type | Description |
|---|---|---|
Pipeline |
Minimal pipeline needed to run node_names. |
topo_order()
¶
Node names ordered from the DataSource downwards (DataSource excluded).
Computed once at build time — the graph cannot change afterwards.
mllabs.ProcessorSpec
¶
Everything needed to build one Processor and feed it — nothing else.
The single shape both executable node kinds resolve to: a Stage
(_BuiltNode/_PipelineNode) and a :class:~mllabs.Trial. Whoever
consumes one — the executor, Connector, the describers, Inferencer
— sees the same six fields regardless of which produced it.
Five of them are the Processor constructor's own arguments (name,
processor, method, adapter, params — see
_node_processor.py). edges is not: it is the input wiring the
flow uses to decide what to feed the processor, resolved lazily
against real data at execution time. "Spec" rather than "attrs" because
nothing here is resolved yet — processor/adapter/params stay
raw declarations until a Processor is actually constructed.
Display-only fields deliberately do not appear: a Stage's label (its
originating group) and a Trial's desc/tag are reachable on the
source object itself and were never read through this shape.
Treat instances as immutable.
mllabs.ColSelector
¶
Deferred column selector for processor params (e.g. cat_features).
Holds a DSL string only (see _edge_dsl) — resolved against real data
at fit time by _node_processor._resolve_col_selectors via
eval_expr(parse(dsl_string), data), the same lazy-resolution
principle as edges[key].