calibration#
hydromodpy.calibration runs the ask/tell loop that estimates
parameters against observations. It sits on top of the simulation
layer and reuses the prepare-once / evaluate-many primitive in
hydromodpy/simulation/execution/trial.py.
Sub-modules#
calibration/cli_runner.py– CLI driver (run_calibration_cli). Loads the TOML, prepares the trial context, runs the engine, persists iterations, optionally promotes best trials.calibration/programmatic_runner.py– in-process driver used byhmp.calibrateand the regional_lab pipeline.calibration/runners/– per-method runner variants (twin experiments, trial helpers, contracts).calibration/promotion.py– top-N promotion of best trials to full simulations.calibration/state.py– in-memory session state shared between ask/tell loops and the persistence layer.calibration/engine.py–CalibrationEnginedrives the ask/tell loop until convergence ormax_iter. Returns aCalibrationSession.calibration/adapters/– one adapter per optimizer (Grid,RandomSearch,ScipyNelderMead,ScipyDE,Optunawith TPE / CMA-ES samplers,CmaEs,GpMapping,DaMhGp, plus prior sampling).calibration/cases/– runnable analytical benchmarks that the loop can exercise end-to-end without MODFLOW (recession_brutsaert,groundwater_1d).calibration/lumped/– lumped-model helpers reused by the cases.calibration/metrics.py– trial-side metric extractor (build_metric_extractor).calibration/objective.py–Objectiveaggregates one or more weighted metrics into a scalar loss.calibration/persistence.py– DuckDB writes forcalibration_sessionsandcalibration_iterations.calibration/report.py– HTML report assembly.calibration/diagnostics.py–convergence_rate,parameter_correlation, and other post-loop helpers.
Ask / tell flow#
load TOML -> CalibrationConfig
prepare_trials() runs steps [0..earliest) once
for iter in range(max_iter):
suggestion = optimizer.ask()
result = run_trial_light(trial_ctx, suggestion, ...)
optimizer.tell(result)
persist iteration to DuckDB
if save_runs != "none":
promote selected trials to full simulations
earliest is computed by
hydromodpy/workflow/internals/dependencies.earliest_affected_step
from the dotted paths in [calibration.parameters.*]. Steps
[0..earliest) are shared across every trial; steps
[earliest..8] re-run lightweight per trial; steps
[9..11] only run when promote_trial is invoked after the
loop.
Storage rule#
RAM only inside the loop (aligned simulated vector + scalar metrics).
DuckDB rows for the trace (
calibration_iterations.sim_idstays NULL by default).Zarr / Parquet only for promoted trials (
save_runs = "best_n"or"all"), withsim_idback-filled.
The ParamsHashCache (SHA-256 of canonical parameter JSON)
deduplicates trials across sessions when use_cache = true
(default).
Key public symbols#
hydromodpy.calibration.cli_runner.run_calibration_clihydromodpy.calibration.programmatic_runner.run_calibration_programmatichydromodpy.calibration.engine.CalibrationEnginehydromodpy.calibration.adapters.{Grid, RandomSearch, ScipyNelderMead, ScipyDE, OptunaAdapter, CmaEsAdapter, GpMappingAdapter, DaMhGpAdapter}hydromodpy.calibration.metrics.build_metric_extractorhydromodpy.calibration.objective.Objectivehydromodpy.calibration.diagnostics.{convergence_rate, parameter_correlation}
Recommended reading path#
hydromodpy/calibration/__init__.pyfor the public surface.hydromodpy/calibration/cli_runner.pyhydromodpy/calibration/engine.pyhydromodpy/simulation/execution/trial.pyone adapter (
hydromodpy/calibration/adapters/optuna_adapter.pyis the most generic).one case (
hydromodpy/calibration/cases/recession_brutsaert.py).
Layer-matrix neighbours#
Allowed targets:
core,schema,physics,data,spatial,solver,simulation,calibration,results.Allowed sources:
config,workflow,projectandcli.
See also#
Calibration Architecture – package map plus every UML view.
Calibration Guide – full operational reference.
Add a Calibration Method – step-by-step recipe.
Calibration Workflow – user-facing hub.