Package: project#

The public face of HydroModPy. api.py holds the fifteen verbs that hydromodpy and hmp expose: open, run, check, calibrate, spinup, replay, stop, status, trash, compare, show, export, publish, example and doctor. A verb takes text, numbers, paths and mappings and gives back a value with to_dict, a path or diagnostics, so a server sends what it gets. A reference is a path, a name read in workspace, or the object itself, and nothing is looked for above the working directory. kept_readers.py keeps read, index and Catalog at the top level beside the verbs.

Project is one object that holds a validated configuration, builds the model once and runs it as often as asked. It is no execution engine, because it calls the workflow layer, so the interactive route and the TOML route share the same steps. launch/ runs a [sites] project as one process per case, exchange/ publishes, installs and replays a copy of a run, dispatch/ binds a workflow name to the call that runs it, and examples/ serves hmp example. lab.py holds Lab, which plays the steps of a run one by one in memory so a model can be built, looked at and changed from Python.

It sits above the layer matrix and reads every layer below it. Only the package root, cli and hydromodpy_server read it. One global crosses to a lower layer, the trial pipeline of calibration/runners/trial.py, which fill_trial_pipeline fills here.

The page of the package in the developer docs lists the modules and tells how the folders fit together and where to add what.

Modules#

top level

Module

What it does

Lines

accessors.py

Read-only views of a project, its sessions and its workspace.

589

api.py

The fifteen public verbs of HydroModPy, the ones hydromodpy and hmp expose.

1 498

calibrate.py

The routing of a calibration: which runner a declaration goes to.

796

check_source.py

What check reads in a configuration: a document, a file and its chain, a [sites] project.

347

compare.py

Compare sealed runs of one site: what differs, when, where, and against the gauge.

553

credentials.py

The reader of credentials.toml, the file that holds one identity per address prefix.

229

data_cache.py

The data cache seen from a project: the lockfile, and what a prune must keep.

219

deliver.py

Deliver the export files of a sealed run to folders and remote servers.

902

doctor.py

What this machine runs: Python, HydroModPy, the packages and the solver executables.

654

environment.py

The environment of one verb call: its credentials file and its bounds.

158

facade.py

High-level Project API for interactive Python usage.

1 219

kept_readers.py

The three readers the top level keeps beside the verbs: read, index and Catalog.

58

lab.py

Build a model step by step in memory, look at it, change it and solve it again.

571

old_paths.py

The old public paths the top level refuses, with what answers in their place.

174

phases.py

Model-phase adapter verbs used by Project.

404

processes.py

The processes this build runs by id, each one in the job directory a caller staged.

68

replay.py

Replay a sealed run or a published copy: hmp replay REF.

261

report.py

The reports of a sealed run and of a calibration session.

322

request.py

The request of a run: one form for a TOML file, a dict, JSON, a server and Docker.

688

run_overrides.py

The set= of a run, as changes of its configuration.

62

runner.py

Run-phase orchestration for hydromodpy.project.facade.Project.

969

show.py

What show reads, one line per value of what, and the function that draws.

674

spinup.py

Cyclic spin-up driver: repeat a forcing window until the state stabilizes.

301

state.py

Mutable state container for hydromodpy.project.facade.Project.

109

trial_pipeline.py

Trial pipeline implementation backed by the project and workflow packages.

116

windows.py

Cut a long transient run into windows and play them one after the other.

401

dispatch/

Module

What it does

Lines

rerun.py

Run a sealed configuration again through the public Project facade.

62

workflow.py

Workflow dispatch adapters that bind launchers to Project.

817

examples/

Module

What it does

Lines

blobs.py

Content-addressed cache for the files an example needs.

176

generate.py

Generate catalog.toml from the examples of the repository.

182

install.py

Write cataloged examples into a scaffolded workspace.

168

manifest.py

The example catalog that ships inside the wheel.

189

rows.py

The plain rows that hmp example list and hmp example show print.

60

exchange/

Module

What it does

Lines

install.py

Install a package into a workspace: its files under data/, its rows, its sites.

676

replay.py

Replay a published run copy from its own bytes: hmp replay <copy>.

241

share.py

Share a run with its data: the install index of a run, and its installation elsewhere.

316

launch/

Module

What it does

Lines

children.py

The cases of a plan as the launcher sees them, and the processes it starts.

321

env.py

The environment of a launched case, and the thread budget its worker applies.

102

journal.py

The folder of one launch, jobs/<stamp>-<scheduler>/, and its journal.

252

lease.py

The lease of the launcher: one launcher per project at a time.

221

local.py

The local launcher of a [sites] project: plan, prepare, launch, count, index.

532

lockfile.py

Write the reproducibility lockfile of a project from the sidecars of its data folder.

96

plan.py

The plan of a [sites] project: sites x recipes resolved into cases, then written once.

1 575

prepare.py

The prepare phase: fetch the inputs of every case before any case solves.

258

sacct.py

What sacct says of the tasks of the SLURM array jobs of a project.

155

selection.py

Which cases a launch starts, with which flags, within which budget.

273

slurm.py

SLURM array jobs for the plan of a [sites] project.

479

slurm_script.py

The text of the SLURM scripts: #SBATCH directives, walltime, worker block.

97

status.py

Where each case of the current plan stands, read from the disk alone.

379

summary.py

Collect a project of N cases into summary/: tables, figures, exports, a page.

472

summary_exports.py

Write the [[sites.export]] requests of a project under summary/exports/.

148

summary_tables.py

Build the tables by_case and by_site of a campaign summary.

503

Inside the package#

The fifteen verbs of api.py are the whole public surface. Each verb resolves its source or its reference, calls the function of the package that does the work and returns a typed value. The Python reference of the docs is built from their docstrings. show reads one line of show.SHOWN, so a new value of what is a line of that table.

The trial pipeline is the one global that crosses to a lower layer. Calibration cannot import workflow or project, so it defines the TrialPipeline protocol and trial_pipeline.py implements it. Each entry that reads the pipeline fills it first, which is why the command line fills nothing. No other adapter is wired through a global.

dispatch/ holds the adapters that need the public Project and that lower layers must not import. dispatch/workflow.py binds a workflow name to the call that runs it for hmp run, and rerun.py reruns a recorded run for hmp catalog rerun. They are the one place in project that imports Project outside TYPE_CHECKING, and only inside functions. launch/ and exchange/ never import it. exchange/ carries a run between workspaces (share.py to publish, install.py to install, replay.py to replay), so it needs to see both the run and the data of a workspace.

The launcher of a [sites] project plans many cases once, prepares them once, solves them as separate processes and collects them into summary/. The plan is written once under plan/<hash>/, and it is the same plan for local.py and for SLURM (slurm.py). So a rule that picks cases or sets a worker flag lives in selection.py only, and the two launchers agree. prepare.py fetches the data of every case before any solve. status.py reads the disk and never the index, and summary.py regenerates summary/ from the run directories.

Where to add what#

A new verb is a function of api.py, and the command line calls it (see Add a CLI command). A workflow name is a run_* function and an entry of DISPATCH in dispatch/workflow.py, with the name in KNOWN_WORKFLOWS of workflow/dispatch.py. A kind of file that a published run carries goes to exchange/share.py, a check when installing to exchange/install.py and a check before a replay to exchange/replay.py. In the launcher, a table format or a binding rule of the plan goes to plan.py, a variable of a case environment to env.py, a state that a case can be in to status.py and a column of by_case or by_site to summary_tables.py. A command that a SLURM script calls is a function of slurm.py, a branch of its main and a line of the template, and the module path stays. A folder NN_name of examples/projects/ with a project.toml and a README.md enters the example catalog at the next python -m tools.dev examples manifest, with no line of code.