Project#
- class hydromodpy.project.Project(config, *, solver=None, headless=False, no_display=False)[source]#
Bases:
objectSetup-once, run-many interface for HydroModPy simulations.
Project(config)is cheap: it validates the configuration and builds an empty runtime context. The heavy model phase (geographic, data, mesh) is built lazily on the firstsimulate()(or eagerly viaprepare()or the per-phase verbsbuild_geographic/load_data/build_mesh). Run many simulations with parameter overrides; inspect past runs throughrunsand inputs throughdata.Parameters#
- configstr, Path, HydroModPyConfig, dict, or JSON str
A TOML path, a fully-built
HydroModPyConfig, adictpayload, or a JSON string (auto-detected).- solverstr, optional
Flow solver name. Auto-detected from the config, defaults to
"modflow_nwt".- headlessbool, optional
Disable display and postprocess runners (useful for calibration loops where generating figures per iteration is wasteful).
- no_displaybool, optional
Skip display generation for later run phases.
Examples#
>>> import hydromodpy as hmp >>> project = hmp.Project("project.toml") >>> run = project.simulate(Sy=0.05) >>> project.close()
- param config:
- type config:
- param solver:
- type solver:
- param headless:
- type headless:
- param no_display:
- type no_display:
Validate
configand build an empty runtime context (cheap).No heavy I/O: geographic delineation, data download and meshing are deferred to the first
simulate()(orprepare()).- param config:
- type config:
- param solver:
- type solver:
- param headless:
- type headless:
- param no_display:
- type no_display:
- prepare()[source]#
Eagerly build the model phase (geographic, data, mesh). Returns self.
- Return type:
- classmethod rerun(run, *, name=None, config_overrides=None, solver=None, headless=False, no_display=False, **overrides)[source]#
Launch a new simulation from a persisted run snapshot.
runremains a read-only result view; this Project-level helper owns the orchestration required to rebuild the configuration, execute the workflow, and record the new run withparent_sim_idpointing to the original simulation.- Return type:
Run- Parameters:
Parameters#
- run
Persisted run to use as the reproducible source snapshot.
- name
Optional name for the derived run.
- config_overrides
Deep-merge patch applied to the stored config snapshot. Keys must match
HydroModPyConfigtop-level fields; the merged payload is validated by Pydantic, so unknown keys raise.- solver, headless, no_display
Options forwarded to the derived
Project.- overrides
Flow parameter overrides forwarded to
Project.simulate().
Returns#
- Run
Persisted run view for the derived simulation.
Raises#
- ConfigMissingError
If
runhas no persisted config snapshot.- PipelineError
If the derived pipeline produces no new Run, e.g.
dry_runmode.
- setup_workspace()[source]#
Bootstrap shared runtime state for the project session.
This Project-level verb prepares the workspace/catalog anchor and the shared geographic/domain/process objects used by later data, mesh, and solver phases. It is not a standalone Pipeline step; Pipeline runs get the same setup through
BuildGeographicStep.- Return type:
- build_geographic(*, reuse_dem=False)[source]#
Mark geographic/domain runtime ready and invalidate downstream state.
- rebuild_geographic(*, reuse_dem=False)[source]#
Rerun the geographic pipeline and invalidate the mesh.
- build_mesh(**overrides)[source]#
Build the catchment mesh from the current geographic context.
- Return type:
- property config: HydroModPyConfig#
Validated configuration driving this project (read-only).
- property data: ProjectDataAccessor#
Accessor for the input-data cache scoped to this project.
- property runs: ProjectRunsAccessor#
Accessor for the simulation catalog scoped to this project.
- property geographic: CatchmentDelineation | None#
Geographic runtime object (DEM, watershed, CRS). Triggers build.
- property time_grid: ResolvedSimulationTimeGrid | ResolvedSteadySimulationTimeGrid | None#
Resolved simulation time grid.
- property loaded_data: LoadedDataContext#
Loaded data context (recharge, geology, hydrometry, etc.). Triggers build.
- property workflow_context: WorkflowContext#
Mutable workflow runtime state threaded through workflow steps.
- simulate(*, name=None, resume=None, from_step=None, until_step=None, dry_run=False, frozen=False, no_display=False, parallel=True, **overrides)[source]#
Run one simulation through the configured workflow and return its result.
Builds the model phase on first call (lazy), then runs the Pipeline. Flow parameter overrides (
Sy,K,Ss) and the special keysthickness,first_clim,propertiesare applied to the plan before the Pipeline runs. Call once per point to sweep a parameter.- Return type:
Run|None- Parameters:
Parameters#
- name
Optional run name persisted in the catalog.
- resume
Existing run identifier to resume from the workflow journal.
- from_step, until_step
Optional step bounds for partial workflow execution.
- dry_run
Build and validate the workflow without executing solver work.
- frozen
Require frozen input-data references.
- no_display
Skip display rendering for this run.
- overrides
Parameter overrides applied to the simulation plan.
Returns#
- Run or None
Persisted run view for simulation workflows. Dry runs and some non-simulation workflows may return
None.
Raises#
- PipelineError
If a workflow step fails during execution.
- SolverError
If the configured solver crashes or fails to converge.
- ResumeError
If
resumereferences an incompatible journal state.
Examples#
>>> run = project.simulate(Sy=0.05, name="probe") >>> run.summary()
See Also#
- hydromodpy.run
Functional facade for one-off TOML execution.
- hydromodpy.results.run.Run
Per-simulation result view returned by successful runs.
- param name:
- type name:
- param resume:
- type resume:
- param from_step:
- type from_step:
- param until_step:
- type until_step:
- param dry_run:
- type dry_run:
- param frozen:
- type frozen:
- param no_display:
- type no_display:
- param parallel:
- type parallel:
- calibrate(*, config_path=None, parameters=None, outputs=None, objective_blocks=None, method=None, max_iter=None, save_runs=None, seed=None, phase=None, **kwargs)[source]#
Run a calibration campaign on this project.
Three modes are supported:
TOML mode (
config_pathsupplied): delegate torun_calibration_cliwith the given TOML path. Extra keyword arguments are forwarded.Python mode (
parameterssupplied): build aCalibrationConfigin memory from the declarations and run the same loop.Embedded mode (neither supplied): use the
[calibration]section carried by this project’s config, so a fully in-memoryHydroModPyConfigcalibrates without re-declaring parameters.
A configuration declaring
[[calibration.phases]]routes torun_staged_calibration()in TOML mode, and in embedded mode when this project was built from a file. An embedded declaration on a project built in memory is refused: each phase forks a fresh configuration from the source file, and there is none. Python mode declares its own parameter space, so the phases of the project config do not apply to it.Parameters#
- config_path
Calibration TOML path for TOML mode.
- parameters
Python-mode parameter declarations.
- outputs
Python-mode output declarations.
- objective_blocks
Python-mode objective block declarations.
- method
Optimizer method name.
- max_iter
Maximum number of optimizer iterations.
- save_runs
Policy controlling which trial runs remain persisted.
- seed
Optional optimizer seed.
- phase
Run only the named phase of a staged calibration.
- kwargs
Extra options forwarded to the calibration runner.
Returns#
- CalibrationReport or StagedCalibrationReport or Any
Structured calibration report when
return_reportis true, otherwise the runner-specific result.
Raises#
- ConfigMissingError
Raised when neither
config_pathnorparametersis supplied.- ConfigError
Raised when
phaseis given andconfig_pathcannot be read, because the answer is what the file says.- CalibrationError
Raised when
[[calibration.phases]]cannot be run as declared, and whenphasenames a phase no configuration declares.
- param config_path:
- type config_path:
- param parameters:
- type parameters:
- param outputs:
- type outputs:
- param objective_blocks:
- type objective_blocks:
- param method:
- type method:
- param max_iter:
- type max_iter:
- param save_runs:
- type save_runs:
- param seed:
- type seed:
- param phase:
- type phase:
- spinup(*, spinup=None, name_prefix='spinup')[source]#
Run the cyclic spin-up loop on this project.
Restarts the representative window each cycle from the previous cycle’s state until the aquifer heads and the lake stage converge. Defaults to the
[spinup]section of this project’s config; passspinupto override it in memory. Feedresult.restart_fromto a production run’s[flow] restart_from.- Return type:
SpinupResult- Parameters:
spinup (SpinupConfig | None)
name_prefix (str)
Parameters#
- spinup
Spin-up settings override.
Noneusesconfig.spinup.- name_prefix
Prefix for the per-cycle run names recorded in the catalog.
Returns#
- hydromodpy.project.spinup.SpinupResult
The loop outcome (converged state,
restart_fromhandle).