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:

  1. Register the adapter via @register_optimizer("name").

  2. Declare a config class here with method: Literal["name"] and one field per accepted constructor kwarg.

  3. List the new class in CalibrationMethodConfig.

Module attributes

CalibrationMethodConfig

Discriminated union of calibration method configs, keyed by method.

Functions

validate_method_kwargs(method, optimizer_kwargs)

Validate (method, optimizer_kwargs) against the discriminated union.