Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions changelog.d/ITL-1387.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
### Added

- `job.register(*streams, **named_streams)` (also on `Pipeline`) brings streams built while
exploring into a job: each comes in with its pod and every upstream step down to its
sources, so the job has the same nodes, hashes, stored tables and results as the same
pipeline written in a `with` block. A keyword names that stream's node. A node of another
job is taken in with its steps; a step of a loaded job whose function is not attached is
refused, naming the step, with a pointer to `as_source()` for its stored results.

### Changed

- A stream built before a job and used by a step inside a `with` block comes in with its
pod and every upstream step, as `register` does. It used to become a source slot named
`<label>:<hash>` that stored none of its steps (or was refused when it lay over a join). A
stream becomes a source only when you make it one: a source object, or a node's
`as_source()`.
- `SourceNode.from_stream` and `SourceJobNode.from_stream` need an explicit `name` for a
stream made by a pod.
- A `with` block whose body or compilation raises leaves the job as it was when the block
was entered (its recorded steps, its nodes and its bindings); a refused step no longer
stays recorded and fails the next block.
46 changes: 44 additions & 2 deletions docs/concepts/pipeline-job.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,9 @@ The three stages:

1. **Create** the job with a `name` and a `database`.
2. **Record** inside the `with` block. Pods and operators applied there are not executed;
the job notes which step is applied to which stream. Sources may be created inside or
outside the block.
the job notes which step is applied to which stream. Sources, and any other step, may be
created inside or outside the block (see
[Streams built before the job](#streams-built-before-the-job)).
3. **Run** with `job.run()`. The recorded steps execute in dependency order and each
function result is written to the database. `run()` returns a `RunSummary` (also kept as
`job.last_run`) that counts, per function node, the rows computed, read from the database
Expand All @@ -68,6 +69,47 @@ the run then does is undefined (ITL-1369). `load_only=True` fills the nodes
from what is already stored and computes nothing; see
[Loading without computing](function-pods.md#loading-without-computing-runload_onlytrue).

## Streams built before the job

Steps you applied while exploring, before any job existed, need not be written again. Give
the streams to a job with **`job.register(...)`**: each comes in with its pod and every step
above it, down to its sources, exactly as if those steps had been written inside a `with`
block (the same nodes, hashes, stored tables and results). A keyword names that stream's node;
a positional stream keeps the label its step was given.

```python
@function_pod(output_keys="ratio")
def weight_per_height(weight: float, height: float) -> float:
return weight / height


explored = mice(cohort_a)
bmi = compute_bmi.pod(explored, label="bmi")
ratios = weight_per_height.pod(explored)

later = PipelineJob(name="explored", database=database)
later.register(bmi, ratio=ratios)
later.run()
print(sorted(later.nodes))
# ['bmi', 'mice', 'ratio']
```

A stream built before the job can also be used by a step inside a `with` block; it comes in
the same way. Steps the job already holds are not added again, so registering a stream built
on one of the job's nodes adds only its new steps, and a node of another job brings that
job's steps with it. Registering computes nothing and stores nothing; `run()` does.

**Cutting a pipeline into parts.** Nothing becomes a source unless you make it one. To start
a pipeline from what another job stored, rather than from its steps, make the cut explicit:
`job.nodes["bmi"].as_source()` is a source over the node's stored results, and a pipeline
built on it begins there (see [Sources](sources.md)). A stream that is not a node becomes a
source only when you build one from it, for example an `ArrowTableSource` over its table with
a `source_id` you choose.

The job that runs an absorbed step determines where its results are stored. By default,
jobs share stored function results when they use the same database and job name. Jobs can
also share function results by using the same `result_database`.

## Nodes

Each recorded step, and each source, is a **node**. `job.nodes` maps a node's name to the
Expand Down
6 changes: 4 additions & 2 deletions docs/concepts/sources.md
Original file line number Diff line number Diff line change
Expand Up @@ -772,8 +772,10 @@ forms: its identity may change in a later release.
[`PipelineJob`](function-pods.md#pipelinejob-database-backed-cached-execution) that has run
and presents them as a new source. You get one by calling `as_source()` on the node, for
example `job.nodes["bmi"].as_source()`. This is useful for chaining pipeline stages: run a
job, then use one of its outputs as the input of a new pipeline. The `as_source()` of a node
downstream of a `Join` or `MergeJoin` of two sources cannot yet be bound as a source of a new
job, then use `as_source()` to start the next pipeline from a stored output. Passing a node
directly brings its steps with it; see
[Streams built before the job](pipeline-job.md#streams-built-before-the-job).
The `as_source()` of a node downstream of a `Join` or `MergeJoin` of two sources cannot yet be bound as a source of a new
`PipelineJob`: its schema is the node's, which declares a pair of system tags for each joined
source, and binding accepts exactly one pair, so it is refused with `SourceSpecMismatchError`
(support is planned, ITL-1127).
Expand Down
22 changes: 22 additions & 0 deletions docs/dev/design_issues/ITL-1389-NO1.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
## `src/orcapod/pipeline/base.py` — node names of a pipeline or job

### NO1 — A job's node names follow recording order
**Status:** open
**Severity:** medium
**Issue:** ITL-1389

A node's name is its key in `job.nodes`, its attribute name and its key in a saved job.
ITL-1436 made the labels and ordering of a fixed graph deterministic. Labels can still change
as the graph grows:

- **Suffixes are given at every compile.** A label held by several nodes becomes
`<label>_1`, `<label>_2`, ... in content-hash order, recomputed by every `compile()`. A job
with one unlabelled `MapData` that gains a second one (by reopening `with job:` or by
`register`) has `MapData_1` and `MapData_2`: the first node is renamed. The names never
depend on the order within one compile, but they are not stable as the job grows.
- **One step with a new, smaller label can be renamed.** The same step (one content hash)
recorded as `label="x"` and `label="y"` in a `with` block keeps `x` in either order.
Reopening a job that held only `y` and recording `x` renames it.

Labels enter no hash and no stored path. Found while designing ITL-1387
(`docs/dev/specs/itl-1387-job-from-streams.md`, sections 1.2 and 1.4).
Loading
Loading