Package: config#
The root of the configuration. HydroModPyConfig is the one Pydantic model that aggregates every section of a project TOML file, and anything a user can write in a project file must load through it and round-trip. The package is thin on purpose. Each section model lives next to the code it configures, and this package is the only place where the section types of the other packages are imported together. Every other layer refers to its own section model, never to the root.
loading.py is the one place that reads a configuration, from a path, a mapping or JSON text, and it applies the same migration and the same refusals to each form. check.py gives every diagnostic of a document at once, and from_toml is that check followed by the building of the root. cross_checks.py holds the rules that read several sections, including the checks of a document against the traits that its flow solver supports. config_migration.py loads a file written against an earlier grammar.
config reads every layer it composes and nothing above them. Only the root facade, workflow, project and cli read it. A lower layer receives the root model or class as an argument, and calibration loads configuration through trial_pipeline().
The page of the package in the developer docs lists the modules and tells how a TOML file becomes a validated object, which section is owned by which package and where to add what.
Modules#
top level
Module |
What it does |
Lines |
|---|---|---|
check.py |
The check of a configuration document, section by section, with every diagnostic at once. |
295 |
config_migration.py |
How a file written against an earlier grammar still loads. |
1 247 |
cross_checks.py |
The checks that cross a document with the flow solver it runs on, and the pairs of keys that spoil each other. |
1 272 |
data_reads.py |
Which data families each section of a project reads, so the data plan loads them. |
32 |
data_types.py |
Keep in |
21 |
hydromodpy_config.py |
Top-level Pydantic configuration object for HydroModPy. |
834 |
input_headers.py |
Read the header of each input file a configuration names, and nothing else. |
366 |
loading.py |
The one loader of a configuration, and the one reader of a TOML file. |
342 |
section_loader.py |
How a raw document becomes its validated sections, with every fault it holds. |
1 387 |
sites.py |
Models of the |
699 |
solver_supports.py |
What the solver supports: trait uses, flow and transport refusals, time-window and native-step refusals, the mesh engine. |
726 |
toml_examples.py |
Flow example blocks for the TOML template. |
79 |
user_files.py |
The user files the configurations of a project declare, listed and hashed. |
136 |
workflow_mode.py |
The three workflows a file runs, and the one its sections imply. |
27 |
Inside the package#
How a TOML file becomes a config#
hmp run file.toml calls load(path, base) of loading.py.
read_documentfollows thebase_configchain, reads each file once, merges, detects cycles, then applies the overlays and the dotted changes. The migration ofconfig_migration.pyruns on the document in memory and leaves the file untouched._from_payloadworks on a copy of the document. It resolves the old forms of a key, the retired sections, the default[workspace], the calibration protocol and defaults and the gauge.validate_sectionshas one loader per section and keeps every fault, with the same walk thatcheck.pyuses. The root takes its name from the file name when[simulation].nameis empty.Every row of
CROSS_RULESruns once, in the order of the table. The first fault is raised, and it carries every diagnostic. A refusal leaves_from_payloadas aConfigValidationErrorthat names the section, never as a bare Pydantic error.
Relative paths are read from one folder, the base. A file gives its own, the folder that holds
project.toml at or above it, else the folder of the root file of its base_config chain,
and a base= given to load wins. A mapping or JSON text has no folder, so load,
from_dict, from_json and check refuse it without a base. So a file two folders down,
such as plan/<hash>/<case>.toml, names a path of [data] the same way project.toml
does. No environment variable moves the base. [workspace].project_root is never a key of a
file, because the loader sets it from the base.
A run request in JSON is read by project/request.py, and the runner passes its document to
load with the base it was given. The name of a run is checked when the run takes its folder
(core/state/names.py) and never by the configuration.
A document can be checked before it is whole. check(document, partial=True) gives a
to_fill diagnostic for each required key not written yet. partial=False turns each
into an error, and a run asks for it.
Each section model is defined in the package it configures. HydroModPyConfig has one field
per top-level section, and this package holds only [workflow] (WorkflowMode) and
[sites]. Each model derives from HydroModelBase, which sets extra="forbid", so a
typo in a key is refused. Each field has a Profile, a unit alias from core/units for a
quantity, and a Field description that becomes its card in the reference.
The solver rows of CROSS_RULES come after the rules of the data and the soil, and the
rules of the layers and the mesh come after them. A key that the file uses and that the flow
solver leaves out of supports raises IncompatibleCapabilitiesError, with the solvers
that honour it. On a sealed run the rules that check the run only warn, so an old run still
loads.
Where to add what#
A field in an existing section goes on the model of that section, with a
Profile, a unit alias for a quantity and a description. The parameter reference follows at the next build, andtests/unit/docs/test_docs_config_consistency.pycompares the committed JSON Schema with the model. The steps are in Add a config field.A new top-level section is a model in the package it configures, a field on
HydroModPyConfigand its row inSECTIONSofsection_loader.py.A renamed or moved key is a
[[migration]]row ofschema/changes.toml, with a test.A retired key is refused by the model with the key to write. A retired section is a row of
RETIRED_SECTIONS.A cross-section rule is one row of
CROSS_RULES, only when the rule needs two sections.
Reading path#
Start with hydromodpy_config.py, then _from_payload, then check.py, then
loading.py and core/toml_io/loader.py for the base_config chain.