hydromodpy.workflow.internals.step#

Pipeline step protocol.

A step is a callable with a stable name that transforms an input PipelineState into an output state.

The protocol is generic over the input/output payload types TIn and TOut so that statically-checked steps can declare:

class ResolveStep:
    name = "resolve"
    tin: ClassVar[type] = ValidatedState
    tout: ClassVar[type] = ResolvedState
    config_sections: ClassVar[tuple[str, ...]] = ("workspace", "simulation")

    def run(
        self, state: PipelineState[ValidatedState]
    ) -> PipelineState[ResolvedState]: ...

Steps may also declare a config_sections class variable listing the dotted TOML subtrees they read from. The attribute is optional on the Step protocol (absent steps are treated as consuming nothing) and is consumed by hydromodpy.workflow.internals.dependencies.earliest_affected_step() to decide which steps must re-run when a calibration overrides a specific field.

Resume hooks#

A persistent step (one that writes durable artefacts) implements two extra methods checked by the runner via hasattr:

artifacts(state_out)

Return workspace-relative POSIX paths of durable outputs produced by the step. The runner hashes these to compute outputs_hash in the workflow_steps journal. Returning an empty tuple is equivalent to not implementing the method: the step is in-memory and gets re-executed at resume.

rebuild_state(prior_state, workspace, run_id)

Rebuild the output PipelineState from disk artefacts only. Called by the runner at resume when the step is journal-completed; must not execute the heavy operation again (solver run, large extraction).

The runtime-checkable Step protocol only enforces name and run. The ResumableStep protocol documents the persistent contract.

Classes

ResumableStep(*args, **kwargs)

Optional contract for steps that persist durable artefacts.

Step(*args, **kwargs)

Canonical pipeline step contract.