Simulation Target
simulation
¶
Resolve a preset name or a configuration file into the settings a run needs.
The CLI and :class:~gwmock_pop.simulators.graph.GraphSimulator both start from
one --config-shaped value: a packaged preset name or a path to a YAML/TOML
file. Resolving it in one place is what keeps the structured configuration tree
attached to the code that runs: a file's run and output blocks are read
here, so they cannot be silently dropped on the way to the simulator.
Classes¶
SimulationTarget
dataclass
¶
SimulationTarget(graph_config: dict[str, Any], configuration: MainConfiguration, source_type: str | None, preset: str | None = None, config_path: Path | None = None)
Everything one --config value resolves to.
Attributes:
| Name | Type | Description |
|---|---|---|
graph_config |
dict[str, Any]
|
The validated parameter graph. |
configuration |
MainConfiguration
|
The simulation configuration declared alongside the graph,
with every default filled in. Its |
source_type |
str | None
|
Source type declared by the preset or the file, or |
preset |
str | None
|
Canonical name of the packaged preset, when the target is one. |
config_path |
Path | None
|
Path of the configuration file, when the target is one. |
Functions:¶
simulation_target_from_file
¶
simulation_target_from_file(config_path: str | Path, *, encoding: str = 'utf-8') -> SimulationTarget
Resolve a configuration file into a simulation target.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
config_path
|
str | Path
|
Path to a YAML/TOML configuration file. |
required |
encoding
|
str
|
Encoding of the file. |
'utf-8'
|
Returns:
| Type | Description |
|---|---|
SimulationTarget
|
The resolved target. |
Raises:
| Type | Description |
|---|---|
ConfigValidationError
|
If the parameter graph fails validation. |
simulation_target_from_preset
¶
simulation_target_from_preset(preset_name: str, *, encoding: str = 'utf-8') -> SimulationTarget
Resolve a packaged preset name into a simulation target.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
preset_name
|
str
|
Name or compatibility alias of a packaged preset. |
required |
encoding
|
str
|
Encoding of the packaged file. |
'utf-8'
|
Returns:
| Type | Description |
|---|---|
SimulationTarget
|
The resolved target, carrying the preset's canonical name rather than the |
SimulationTarget
|
temporary path the packaged resource was read from. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If no packaged preset has that name. |
resolve_simulation_target
¶
resolve_simulation_target(config: str, *, encoding: str = 'utf-8') -> SimulationTarget
Resolve a preset name or configuration-file path into a simulation target.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
config
|
str
|
Packaged preset name or path to a YAML/TOML configuration file. |
required |
encoding
|
str
|
Encoding of a configuration file. |
'utf-8'
|
Returns:
| Type | Description |
|---|---|
SimulationTarget
|
The resolved target. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If the path is not a file, its suffix is unsupported, or the value names neither a preset nor an existing path. |
FileNotFoundError
|
If the value looks like a configuration-file path but no such file exists. |