Model Loader
spx_core/system/model.py defines the Model class that the server instantiates for every YAML document. It is responsible for:
Holding top-level containers (
attributes,actions,communication, etc.).Spinning up dedicated
Timer,Polling, andScenarioschildren when those sections appear in YAML.Driving the lifecycle (
prepare,start,run) for the entire simulation.
Configuration Example
model:
name: plant
timer:
step: 0.1
polling:
interval: 0.05
scenarios:
voltage_drift:
enabled: true
duration: 5.0
actions:
- noise:
output: "#attr(voltage)"
std: 0.01
attributes: { ... }
actions: [ ... ]
communication: { ... }
{
"model": {
"name": "plant",
"timer": {
"step": 0.1
},
"polling": {
"interval": 0.05
},
"scenarios": {
"voltage_drift": {
"enabled": true,
"duration": 5.0,
"actions": [
{
"noise": {
"output": "#attr(voltage)",
"std": 0.01
}
}
]
}
},
"attributes": { "...": "..." },
"actions": [ "..." ],
"communication": { "...": "..." }
}
}
Key behaviors
Automatic extraction: The loader pulls
timer,polling, andscenariosfrom the model definition before instantiating other containers. This keeps the YAML tidy—no need to declare those sections separately.Unique identifier: Each model gets a
uid(UUID string) you can query through the API for observability.Real-time flag:
model.real_timecontrols whether the polling loop runs continuously (true) or waits for manual ticks (false). You can flip it through the API for deterministic testing.
Lifecycle expectations
prepare()is called on every child (attributes, actions, communication, timer, polling, scenarios).start()launches timer/polling threads whenreal_timeis true.run()is driven by either the polling loop or manual API calls (POST /run).
Practical tips
Always keep
attributes,actions, andcommunicationat the top level—nested models inherit the same pattern.Use the SDK to validate the structure before deploying; the server loader relies on the same class registry.
To disable real-time execution in tests, call
PATCH /models/<id>with{ "real_time": false }and then triggerrun()steps manually.
Last updated

