Minimal Hybrid System
This example builds and simulates a small two-location thermostat with the object-based hybrid-system API. It is intended as the shortest complete example of defining locations, flows, event surfaces, and transitions directly in Python.
Run it from the repository root:
uv run --directory ./examples/hs-simple python main.py
The reusable build_thermostat() function returns a HybridSystem assembled from these objects:
Locationrepresents a discrete mode of the system, hereheatingandcooling.ContinuousDynamicsstores the derivative function for a location.EventSurfacedefines when a transition is enabled.CrossingDirectionrestricts an event to rising or falling crossings.Transitionconnects a source location to a target location.simulateruns the hybrid system over a time interval and returns a trace.plot_tracerenders the simulated state, locations, and events.
The thermostat starts in the heating location at temperature 19.0. It switches to cooling when the too_hot event surface is crossed upward at 21.0, and switches back to heating when the too_cold event surface is crossed downward at 19.0.
The script prints the number of recorded events and writes a plot artifact to examples/hs-simple/outputs/hs-simple.png.