Configuration¶
configuration
¶
Representations of parsed configuration files.
AxesGroupModel = dict[IdentifierString, AxisModel]
module-attribute
¶
Type alias for the axes block in a configuration file.
AxisModel = Annotated[ContinuousAxisModel | CategoricalAxisModel, Field(discriminator='kind')]
module-attribute
¶
Discriminated union of all axis configuration models.
ModuleConfigurationValue = ModuleBase | str
module-attribute
¶
A module configuration value, either expanded config or shorthand text.
ModuleGroupModel = Annotated[dict[IdentifierString, ModuleConfigurationValue], BeforeValidator(_to_default_dict)]
module-attribute
¶
Module group configuration model for flepimop2.
ParameterConfigurationValue = Annotated[ModuleConfigurationValue, BeforeValidator(_coerce_parameter_configuration_value)]
module-attribute
¶
A parameter value, including bare numeric shorthand for fixed parameters.
ParameterGroupModel = Annotated[dict[IdentifierString, ParameterConfigurationValue], BeforeValidator(_to_default_dict)]
module-attribute
¶
Parameter group configuration model for flepimop2.
CategoricalAxisModel
¶
Bases: BaseModel
Configuration model for a categorical axis.
Attributes:
| Name | Type | Description |
|---|---|---|
kind |
Literal['categorical']
|
Discriminator field; always |
labels |
tuple[str, ...]
|
Ordered sequence of string category labels. |
values |
tuple[int, ...]
|
Integer values associated with each label (e.g. for ordinal data
or spline interpolation). Must be the same length as |
Examples:
>>> from flepimop2.configuration._axes import CategoricalAxisModel
>>> CategoricalAxisModel(labels=("foo", "bar", "baz"))
CategoricalAxisModel(kind='categorical', labels=('foo', 'bar', 'baz'), values=(1, 2, 3))
ConfigurationModel
¶
Bases: YamlSerializableBaseModel
Configuration model for flepimop2.
This model serves as the parent container for a parsed configuration file.
Attributes:
| Name | Type | Description |
|---|---|---|
name |
str | None
|
An optional name for the configuration. |
engines |
ModuleGroupModel
|
A dictionary of engine configurations. |
systems |
ModuleGroupModel
|
A dictionary of system configurations. |
backends |
ModuleGroupModel
|
A dictionary of backend configurations. |
process |
ModuleGroupModel
|
A dictionary of process configurations. |
parameters |
ParameterGroupModel
|
A dictionary of parameter configurations. |
simulate |
dict[IdentifierString, SimulateSpecificationModel]
|
A dictionary of simulation configurations. |
patch(other, *, conflict=PatchConflictMode.ERROR)
¶
Patch this configuration with another configuration.
This method treats other as the incoming patch. Top-level sections are
merged entry-by-entry; when both entries are ModuleBase instances their
patch() implementations are used.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
other
|
Self
|
The patch to apply to this configuration. |
required |
conflict
|
PatchConflictMode
|
How to handle duplicate top-level entry names. |
ERROR
|
Returns:
| Type | Description |
|---|---|
Self
|
The patched configuration. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If there are sub-top level key conflicts and |
Source code in src/flepimop2/configuration/_configuration.py
236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 | |
to_yaml_data()
¶
Convert the configuration into its normalized YAML representation.
This preserves parsing/patching semantics while allowing the emitted YAML to use a more compact, user-facing structure.
Returns:
| Type | Description |
|---|---|
object
|
A YAML-ready representation of the configuration. |
Source code in src/flepimop2/configuration/_configuration.py
ContinuousAxisModel
¶
Bases: BaseModel
Configuration model for a continuous (float) axis.
Attributes:
| Name | Type | Description |
|---|---|---|
kind |
Literal['continuous']
|
Discriminator field; always |
domain |
tuple[float, float]
|
A |
size |
int
|
Number of evenly-spaced points. Required for continuous axes. |
spacing |
Literal['linear', 'log']
|
Whether points are spaced |
Examples:
>>> from flepimop2.configuration._axes import ContinuousAxisModel
>>> ContinuousAxisModel(domain=(0.0, 12.0), size=5, spacing="linear")
ContinuousAxisModel(kind='continuous', domain=(0.0, 12.0), size=5, spacing='linear')
SimulateSpecificationModel
¶
Bases: BaseModel
Model for specifying a simulation for flepimop2.
Attributes:
| Name | Type | Description |
|---|---|---|
engine |
IdentifierString
|
The name of the engine to use for the simulation. |
system |
IdentifierString
|
The name of the system to simulate. |
backend |
IdentifierString
|
The name of the backend to use for the simulation. |
times |
RangeSpec
|
A list of time points at which to perform the simulation. |
params |
dict[str, float] | None
|
Optional dictionary of parameters for the simulation. |
scenario |
IdentifierString | None
|
Optional name of the scenario to use for the simulation. |
t_eval
property
¶
Get the evaluation times as a NumPy array.
Returns:
| Type | Description |
|---|---|
Float64NDArray
|
A NumPy array of evaluation times. |
to_yaml_data()
¶
Convert the simulation specification into YAML-ready Python objects.
Returns:
| Type | Description |
|---|---|
object
|
A YAML-ready representation of the simulation specification. |
Source code in src/flepimop2/configuration/_simulate.py
YamlSerializableBaseModel
¶
Bases: BaseModel
Base model with YAML serialization support.
Example
class DemoModel(YamlSerializableBaseModel): ... name: str payload = DemoModel(name="demo").safe_dump() print(payload, end="") name: demo DemoModel.safe_load(payload) DemoModel(name='demo')
from_yaml(file, encoding='utf-8', **kwargs)
classmethod
¶
Deserialize a YAML file to an instance of the model.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
file
|
Path
|
Path to the YAML file to read. |
required |
encoding
|
str
|
Encoding of the YAML file. |
'utf-8'
|
**kwargs
|
Any
|
Additional keyword arguments to pass to |
{}
|
Returns:
| Type | Description |
|---|---|
Self
|
An instance of the model. |
Source code in src/flepimop2/configuration/_yaml.py
safe_dump()
¶
Serialize the model to a YAML document.
Returns:
| Type | Description |
|---|---|
str
|
The serialized YAML document. |
Examples:
>>> class DemoModel(YamlSerializableBaseModel):
... name: str
>>> print(DemoModel(name="demo").safe_dump(), end="")
name: demo
Source code in src/flepimop2/configuration/_yaml.py
safe_load(contents)
classmethod
¶
Deserialize YAML text to an instance of the model.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
contents
|
str
|
The YAML document to deserialize. |
required |
Returns:
| Type | Description |
|---|---|
Self
|
An instance of the model. |
Examples:
>>> class DemoModel(YamlSerializableBaseModel):
... name: str
>>> DemoModel.safe_load("name: demo")
DemoModel(name='demo')
Source code in src/flepimop2/configuration/_yaml.py
to_yaml(file, encoding='utf-8', **kwargs)
¶
Serialize the model to a YAML file.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
file
|
Path
|
Path to the YAML file to write. |
required |
encoding
|
str
|
Encoding of the YAML file. |
'utf-8'
|
**kwargs
|
Any
|
Additional keyword arguments to pass to |
{}
|
Source code in src/flepimop2/configuration/_yaml.py
to_yaml_data()
¶
Convert the model into YAML-ready Python objects.
Subclasses can override this method to control both the serialized representation and any YAML style wrappers used by the project dumper.
Returns:
| Type | Description |
|---|---|
object
|
A YAML-ready representation of the model. |
Examples:
>>> class DemoModel(YamlSerializableBaseModel):
... name: str
... dims: tuple[int, int]
>>> DemoModel(name="demo", dims=(1, 2)).to_yaml_data()
{'name': 'demo', 'dims': [1, 2]}
Source code in src/flepimop2/configuration/_yaml.py
yaml_mapping(values=(), *, flow_style=None)
¶
Wrap a mapping with YAML style metadata.
Module authors can return this from to_yaml_data() when a specific
subtree should use flow style, e.g. {a: 1, b: 2}.
Returns:
| Type | Description |
|---|---|
YamlFormattedMapping[K, V]
|
A mapping wrapper carrying the requested YAML flow-style hint. |
Examples:
>>> wrapped = yaml_mapping({"kind": "demo"}, flow_style=True)
>>> dict(wrapped)
{'kind': 'demo'}
>>> wrapped.flow_style
True
Source code in src/flepimop2/configuration/_yaml.py
yaml_sequence(values=(), *, flow_style=None)
¶
Wrap a sequence with YAML style metadata.
Module authors can return this from to_yaml_data() when a specific
subtree should use flow style, e.g. [a, b, c].
Returns:
| Type | Description |
|---|---|
YamlFormattedSequence[T]
|
A sequence wrapper carrying the requested YAML flow-style hint. |
Examples:
>>> wrapped = yaml_sequence(("a", "b"), flow_style=True)
>>> list(wrapped)
['a', 'b']
>>> wrapped.flow_style
True