Add a process#
A process is a kind of run of the plan of a simulation, with the solvers and the options
that serve it. Two ship, flow and transport. This page shows what a third one
touches, with flow as the process that carries a runtime payload and transport as
the one that does not.
Most additions are not a new process. A new solver for flow or transport is an
adapter, see Add a solver. Add a process only when the runs themselves are new, with
their own options, reads and requires.
The shape of a process#
A process holds a configuration, a process entry and registered solvers. The
configuration is a HydroModelBase under model/<name>/<name>_config.py that declares
what the process reads. Transport declares one validated block per solver, under the name
the solver registry uses, [transport.modflow6] for instance.
One process also carries a runtime payload, an object built once by the
pipeline and read by its adapters. flow does: the Flow of
model/flow.py. A process that does not, like transport, needs nothing
built for it. Its adapters work from the arguments the runner passes,
build(model, options, slot, upstream), where model is the frozen
Model of the upstream run the process follows, options its own table,
and upstream[0] the SolverRun that produced what reads declares.
A transport works in the folder of that upstream run.
Files to create#
hydromodpy/model/transport/ is the smallest complete example. It holds a docstring-only
__init__.py and transport_config.py with TransportConfig and one parameter
block per solver. The solvers of the process live with their backends, in the file of the
engine they drive, as the MT3DMS adapter is in
hydromodpy/solver/modflow_nwt/mt3dms/mt3dms.py. hydromodpy/model/flow_config.py is
the large case. Read transport first.
Register#
Search the tree for transport to find every site. These make it a process and not
just a package:
File |
What it does for the process |
|---|---|
|
The Pydantic model, with one block per solver that serves the process,
read through |
|
A field on |
|
A |
|
The registry refuses a |
|
One adapter and one extractor per solver in |
|
The refusals derived from what the process declares: every name in
|
|
The public exports of the process, if it belongs to the public API. |
|
A member of |
|
The step that builds the payload into |
Order of work#
Write the configuration first, with a Profile, a unit and a description on every field
(Add a config field). Declare the section on HydroModPyConfig and add the
<Name>ProcessConfig to the union. Then bind a solver: the adapter declares
process_type = "<name>", reads and requires, as
Modflow6GwtTransportAdapter requires ("flow", "modflow6"), so the planner refuses a
transport run that comes before its flow run (Add a solver). Last, refuse impossible
combinations in config/solver_supports.py from what the backends declare, without
naming a backend. A process with a payload adds its runtime class, its member on
SetupContext and the step that builds it.
Test#
Unit under
tests/unit/model/<name>/, in the style oftest_transport_config.py: the config loads, a block is checked by theoptionsclass of a solver, an unknown key is refused.Unit for the planner: a
[[simulation.process]]entry of the new type expands into one run per solver and respectsrequires.Contract on the port, in
tests/ports/test_solver.py: the new solver answers the members a backend of its process type answers.Scenario in
tests/scenarios/: one chain of the process behind the run it reads, played byhmp run. The transport chains oftest_transport_chains.pyare the worked example.Validation with an analytical reference when the process carries non-trivial mathematics, so tolerances are explicit from the start (Add a test).
Run python -m pytest tests/unit/architecture -q after the first import you add. The
imports the layer matrix allows are in Layer graph. Solver code stays in
solver/<backend>/, never in model/.
See also#
Package: model for the model package map.
Add a solver for the adapter side.
Add a config field for the configuration side.
Processes and boundaries for the runtime handoff.