Skip to content

ModelParser

class ModelParser(config_path: str | pathlib.Path)

ModelParser reads a given YAML configuration file (see configuration guide) and parses the contents into a ModelConfig object.

Parameters:

Name Type Description
config_path str \| pathlib.Path Path to the YAML config file.
raw_data dict[str, Any] The authored YAML mapping, retained for canonical re-emission.
parsed ParsedConfig Parsed model/kalman config pair populated at initialization.

 

Methods:

Signature Return Type Description
ModelParser.from_string(text) ModelParser Classmethod. Builds a parser from YAML text instead of a path (routed through the same parse pipeline).
.from_yaml() tuple[dict, ParsedConfig] Reads the file and populates ModelParser.raw_data / .parsed. Runs at __init__.
.get() ModelConfig Returns the currently parsed model config.
.get_all() ParsedConfig Returns the currently parsed model/kalman config pair.
.to_yaml(config=None, *, digits=3) str Emits the authored configuration as canonical YAML text. When config is supplied, its calibration is baked in (rounded to digits).
.update_calibration_parameters(new_config, digits=3, output_path=None) io.StringIO Convenience wrapper over to_yaml that bakes new_config's calibration and optionally writes the result to output_path.
ParsedConfig

ParsedConfig is an unpack-able dataclass holding ParsedConfig.model: ModelConfig and ParsedConfig.kalman: KalmanConfig

Serialization round-trip

to_yaml re-dumps raw_data, so the (t)/(t+1) equation grammar and any kalman: block are preserved verbatim; ModelParser.from_string(...) re-parses that text back into an equivalent ParsedConfig. The Kalman configuration is not serialized as an object — it rides inside the emitted YAML, and the parser re-derives the (model-dependent) measurement-noise machinery on load. This pairing is what the .sdsge bundle uses to carry a model's configuration as text.

Calibration Completeness

Parsing enforces that every declared parameter has a calibration value, and every parameter referenced in shock/Kalman sections is declared and calibrated.