Mental model and design choices#
This page explains why HydroModPy is split into several layers instead of collapsing everything into one execution object. Use it when the question is not only “what is this object?” but also “why does this boundary exist?”. The page ends with the files to open first for each kind of change.
At a glance#
The main execution path is:
TOML
-> workflow
-> Project
-> SimulationPlanner
-> SimulationPlan (ProcessRun...)
-> Pipeline
-> SimulationRunner
-> SolverAdapter
-> concrete solver
-> Catalog
-> Run
The main input-data path is:
TOML
-> DataLoadPlan
-> Variable
-> Source
-> file and sidecar in data/
The first path answers: “how does a configuration become a persisted result?”
The second path answers: “where do the input data come from, and how are they cached?”
Why so many layers?#
The short answer is: different parts of the system evolve at different speeds.
TOML contracts evolve with user workflows and frontend needs.
Planners and pipelines evolve with orchestration needs.
Solver integrations evolve with backend-specific constraints.
Input data sources evolve with APIs, formats, and preprocessing rules.
Result reading evolves with post-processing and comparison workflows.
If these concerns all live in one place, small changes propagate too far. The current split tries to reduce that coupling.
Why Project exists#
Project is the user-facing facade.
It exists to provide:
one simple Python entry point,
one common language across CLI, scripts, and notebooks,
one place that composes planning, execution, and persistence.
Without this facade, most users would need to directly manipulate lower level objects that exist for orchestration, not for ergonomic use.
Three distinctions that matter#
workflow vs SimulationPlan vs Pipeline#
These three concepts answer different questions:
workflow: which user-facing mode was requested?SimulationPlan: which execution units must run, and in what logical order?Pipeline: how does the technical execution advance, step by step?
This separation matters because it prevents the CLI contract from being tightly bound to one specific internal implementation.
ProcessRun vs Run#
ProcessRun is a planned execution unit before runtime.
Run is a read handle over a persisted simulation result.
Keeping these separate avoids ambiguity between:
something that still has to be executed,
something that has already been written and can be queried again.
Catalog vs the sidecars of data/#
HydroModPy keeps two persistent memories because they do not have the same lifecycle:
The sidecars of
data/are the cache of input data that many runs may reuse. They are files next to the data, with no database.Catalogtracks outputs that belong to particular runs.
The important relation between them is provenance, not identity.
Another distinction worth preserving#
Variable and Source also solve different problems:
Variable: what kind of scientific data is needed, and what loading policy applies to it (grids, stations or files)?Source: where does the concrete data come from?
This lets HydroModPy change a provider without renaming the scientific concept, or change the loading policy without changing the source contract.
Hydrographic network naming#
The hydrographic-network work is a good example of why HydroModPy keeps separate concepts for:
loaded input data,
generated geographic products,
persisted run features,
downstream display and comparison views.
The canonical persisted names are now:
hydrographic_network_referencefor the network loaded fromdata.hydrographyhydrographic_network_reference_permanentfor the reaches of that network that flow all year, when the loader can tell themhydrographic_network_generatedfor the network derived fromgeographic.river_network
The feature-store contract keeps only the canonical names. Historical filenames may still exist on disk, but they are not feature aliases:
river_network.shpremains the generated-network vector filename.river_network_summary.jsonremains the generated-network summary filename.streams.shpremains the reference vector filename, andstreams_permanent.shpthe permanent reaches beside it.hydrography_streamsis the canonical reference forcing-raster name.
This split is intentional. A variable may still write a historical filename on disk, while the runtime and comparison layers rely on the canonical feature names to avoid ambiguity.
Hydrographic network class structure#
The hydrographic-network stack is intentionally split across several classes because they do not answer the same question.
The key distinction is:
HydrographicNetworkis the canonical cross-layer concept for one network.HydrographicNetworksis only a bundle of available roles for one site/run.HydrographicNetworkComparisonis the result of comparing two networks.RiverNetworkProductsremains the technical output bundle of thegeographic.river_networkpreprocessing step.
Put differently:
one loaded reference network becomes
HydrographicNetwork(role="reference")one DEM-derived network becomes
HydrographicNetwork(role="generated")the roles are
reference,reference_permanent,generated,mesh_constraintandsimulated_activethe preprocessing code may still first emit
RiverNetworkProductsthe runtime then groups available roles in
HydrographicNetworksthe
Runfacade exposes reading and comparison operations over the persisted networksmesh_constraintis never stored: theRunrebuilds it on read from theriverschains of the stored mesh
This is why HydroModPy does not use one “god object” for hydrographic networks. It keeps:
one class for the canonical concept,
one class for the role bundle,
one class for the comparison result,
one technical class for the low-level generated artifacts.
The display layer stays separate. Figures consume the canonical networks and comparison payloads, but rendering is not embedded in the data classes themselves.
The simulated active network#
The hydrographic-network contract reserves a third role, simulated_active,
for the network that emerges from simulated drainage. It exists in the type
contract (HydrographicNetworks.simulated_active) and no workflow step stores
it as a vector feature. What HydroModPy computes from the
drain_accumulation_flux field are lazy views of the run: run.drainage_density(),
run.persistence(), run.cell_field_active_mask(),
run.cell_field_active_metrics(), run.cell_field_network_overlap_metrics()
and run.cell_field_network_distance_metrics(), and the figure of the variable
simulated_active_network.
They live in hydromodpy.results.derive.views and read fields, mesh geometry
and the stored roles without changing the catalog.
Supports and the simulated network states
what each view returns.
Where to start reading#
For a package, open its page under Packages: the README of the package, the table of its modules, then the parts, the import rules and where to add what. For a path through the code, start here.
One TOML to solver outputs
hydromodpy/cli/commands/run.py, thenhydromodpy/project/api.py(run) andhydromodpy/project/dispatch/workflow.py;hydromodpy/project/facade.py(Project);hydromodpy/solver/base/planner.py;hydromodpy/solver/base/runner.py;hydromodpy/solver/base/registry.py, thesolversinstance ofhydromodpy/core/plugin_registry.py;one adapter under
hydromodpy/solver/<backend>/adapters/;the backend package under
hydromodpy/solver/.
A mesh
hydromodpy/workflow/steps/mesh.py(step_mesh);hydromodpy/mesh/planning/plan.py(plan_mesh_request);hydromodpy/mesh/port.pyandregistry.py, then the engine inhydromodpy/mesh/engines/;hydromodpy/mesh/planar/planar_cell_mesh.py(PlanarCellMesh);the pages of Mesh engines.
A calibration
hydromodpy/calibration/runners/cli_runner.pyandsearch.py;hydromodpy/calibration/optim/engine.py;hydromodpy/calibration/runners/trial.py, the prepare-once and evaluate-many primitive;the pages of Calibration internals.
Where backend-specific logic starts
hydromodpy/solver/modflow_common/flow_run.py, the lifecycle shared by the MODFLOW adapters;hydromodpy/solver/modflow6/adapter.pyorhydromodpy/solver/modflow_nwt/adapter.py;hydromodpy/solver/modflow_common/for the shared MODFLOW code;hydromodpy/solver/boussinesq/for the in-house backend.
Next#
Layered architecture for the import rules between packages.
Data scopes and schema evolution for the three databases.
From TOML to solver outputs for the same path with the objects named.