hydromodpy.calibration.method_config#
Discriminated union for the calibration method + optimizer kwargs.
The legacy schema accepted method: str together with a free-form
optimizer_kwargs: dict[str, Any]. Mismatches between the two only
surfaced at runtime, in the depths of an optimizer adapter, and made TOML
authoring fragile (method = "cma_es" with optimizer_kwargs = {"n_trials": 50}
silently validates and crashes later).
This module exposes one BaseModel per registered optimizer and a
CalibrationMethodConfig discriminated union keyed by method. A
helper validate_method_kwargs() converts the legacy
(method, optimizer_kwargs) pair into a typed config so callers detect
unknown keys eagerly.
Adding a new optimizer requires three steps:
Register the adapter via
@register_optimizer("name").Declare a config class here with
method: Literal["name"]and one field per accepted constructor kwarg.List the new class in
CalibrationMethodConfig.
Module attributes
|
Discriminated union of calibration method configs, keyed by |
Functions
|
Validate |