Package: workflow#

The order in which a project is built and run. A file such as project.toml becomes thirteen steps, from validation to the seal of the run. Each step takes an immutable PipelineState, does its part and returns the next one. A Pipeline chains the steps, records them in the journal of the run and can resume a run from the artifacts of the steps already done. The Project facade and every workflow launcher, simulation or calibration, call these steps, so one file always drives one lifecycle.

A run writes its own directory and nothing else. It never opens the index of the project, and nothing here imports hydromodpy.project. steps/ holds the thirteen steps and steps/prepare_solver/ the step that opens the run. record/ holds what a run writes about itself: the claim of its directory, its outcome, the step journal and the resume plan. The modules at the root hold the state, the step protocol, the pipeline, the step graph and the choice of a workflow from a file.

It reads every layer below it and nothing reads it but project, cli and the package root. A lower layer that needs a workflow function receives it as an argument, as calibration does through the TrialPipeline protocol.

The page of the package in the developer docs lists the modules, tells how a run goes through the steps and says where to add what.

Modules#

top level

Module

What it does

Lines

cited_inputs.py

The cached files a run or a lockfile of a workspace cites, which no cleanup may remove.

96

dag.py

Workflow DAG built from declared step dependencies.

129

dispatch.py

Which workflow a configuration file runs.

111

overview.py

Data-overview launcher - “watershed identity card” workflow.

763

parallel.py

Cohort executors of the workflow pipeline.

95

products.py

The one place workflow asks the product store, and the table of products.

273

replay_checks.py

What a replay of a sealed run checks before it runs: its inputs, then its producer.

339

runner.py

Pipeline orchestrator.

711

solution_key.py

The request id and the solution key of a case, told before or during its run.

202

state.py

Pipeline state - the object that flows between pipeline steps.

89

step.py

Pipeline step protocol.

99

window.py

The window of steps a run executes: from_step, until_step and the model phase.

84

record/

Module

What it does

Lines

attempt.py

One attempt of a run, from the claim of its directory to its outcome.

225

journal.py

The step journal of a run: <run>/.hmp/checkpoints/steps.json.

296

manifest.py

Resolved run manifest used to validate pipeline resume, and the config it signs.

405

resume.py

Resume planner driven by the step journal of the run directory.

240

run_store.py

The store of a run, opened for the span of one caller.

86

steps/

Module

What it does

Lines

data.py

Data step - load external forcings, bind to runtime, expose LoadDataStep.

897

data_description.py

What a data load read, and the document that says so.

338

dependencies.py

Compute which pipeline step is the earliest affected by a set of overrides.

125

derive.py

Step 9 - what a run derives once its fields are in the store.

119

display.py

Step 13 - draw the [[display.figure]] tables of the config, after the seal.

240

export.py

Export step - clean the solver files and the scratch; the exports follow the seal.

563

extract.py

Extract step - solver result extraction, observation ingestion, modpath helpers.

178

mesh.py

Mesh step: plan one request, build the cell mesh with the chosen engine, store it.

312

mesh_inputs.py

Gather what the mesh planner reads besides [mesh] from the run context.

293

planning.py

Planning step - build a SimulationPlan and decide the per-cell budget it keeps.

166

resolve.py

Step 1 - resolve workspace paths, create the workflow context.

122

run_outputs.py

What happens to the solver outputs of a run once it is solved.

345

run_solver.py

Run-solver step - execute the plan, record solver output locations and the time of each solve.

215

sequence.py

The canonical order of the thirteen steps of a run.

56

setup.py

Setup step - structural bootstrap, geographic, spatial supports, process objects.

490

validate.py

Step 0 - config validation.

124

steps/prepare_solver/

Module

What it does

Lines

dispatch.py

Concern 3 of PrepareSolverStep: opening the run and freezing what it was built from.

545

facts.py

Concern 2 of PrepareSolverStep: the facts of the run and its artifact paths.

213

forcings.py

Concern 5 of PrepareSolverStep: persisting the input forcings of a run.

405

freeze.py

Concern 4 of PrepareSolverStep: freezing the configuration a run was built from.

173

model.py

step_build_model: freeze the Flow of a run into the Model its solver reads.

396

prepare.py

Concern 1 of PrepareSolverStep: persistence helpers.

376

resolved.py

config.resolved.toml: the whole configuration a run used, and what a replay compares.

456

restart.py

[flow] restart_from by reference: a run name, a sim_id or a path.

251

step.py

PrepareSolverStep: plans the simulation and opens the run it will execute.

251

Inside the package#

The steps#

standard_steps() of steps/sequence.py returns the thirteen steps in order, with the names of core/pipeline_steps.py. Each step declares the step it depends on, so the graph is a chain and every cohort holds one step. The order is validate, resolve, build_geographic, load_data, build_mesh, setup_process, prepare_solver, run_solver, extract, derive, export, seal and display. prepare_solver freezes the configuration into config.toml and config.resolved.toml. seal writes the seal from the facts of the run. The data exports and the views (step_after_seal of steps/export.py) and the figures come after it and carry its label.

How a run goes through it#

  1. The launcher claims the directory of the case under runs/ through record/attempt.py, before the first step. outcome.json says running and a heartbeat pulses.

  2. Pipeline builds the graph from depends_on() and runs it with Pipeline.run(state, resume_from=..., parallel=..., heartbeat=...). Each step is state.advance(...) over the shared PipelineState, whose main member is the WorkflowContext. window.py bounds the steps with from_step and until_step.

  3. Each step is recorded in <run>/.hmp/checkpoints/steps.json with the hash of its artifacts. ResolvedRunManifest and the facts of the run (RunFacts) sit beside it in <run>/.hmp/. A step that writes durable artifacts implements artifacts(state_out) and rebuild_state(...). At resume the runner rebuilds the state of a completed step from disk and does not run it again, as Pipeline resume from artifacts tells. There is no pickle layer.

  4. Before each cohort the runner reads the stop flag .hmp/stop.json and raises StopRequested when it is there. The step that a stop interrupts is marked aborted, so a resume plays it again from its start, run_solver included.

  5. After the seal, the attempt protocol flips the outcome to completed and removes <run>/.hmp/. A render that raises after the seal leaves the run sealed and completed, because close_sealed_attempt closes it and the error goes up. A run that stops before the seal keeps failed, aborted or, for a window ended by --until, partial.

A calibration trial skips the shared steps, because it asks earliest_affected_step of steps/dependencies.py for the first step that an override reaches, from the config_sections of the steps.

Import rules#

record/ imports state and step and never steps. A step’s reads and writes are exact, because tests/unit/architecture/test_run_path.py derives both from the source of the step and fails when a declaration and the code disagree. A step never opens the index of the project. It writes through run_store(ctx) into the directory of the run, and the launcher derives the index once the worker has returned.

Where to add what#

  • A step is described in the docstring of steps/__init__.py, with its name in core/pipeline_steps.py.

  • Something that a run records about itself goes to record/. A fact of the run is a field of RunFacts in results/storage/run_facts.py and the block of the seal it feeds in results/storage/sealing.py.

  • A derived field is a row of VIRTUAL_FIELD_ROWS in results/derive/virtual_fields.py, rebuilt on read and never written by a step.

  • A workflow mode is a name in KNOWN_WORKFLOWS and its adapter in project/dispatch/workflow.py.

  • A standalone launcher is a class next to overview.py, built on the steps it needs. A check at replay is a function of replay_checks.py.