ode
ContinuousDynamics(flow, label=None)
dataclass
Reusable continuous dynamics definition.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
flow
|
Callable[..., Derivative]
|
Dynamics function returning the state derivative. Scalar derivative returns are accepted only for single-state systems, both during solver evaluation and when derivatives are captured on the returned trace grid. |
required |
label
|
str | None
|
Optional display label. |
None
|
CrossingDirection
Bases: IntEnum
Direction in which an event surface must cross zero.
Event(time, source_location, target_location, event_surface, reset, state)
dataclass
Transition event information for a trace.
EventSurface(fn, direction=CrossingDirection.EITHER, label=None)
dataclass
Scalar event surface defining a simulated transition event.
Flowcean transitions fire when fn reaches zero in direction.
This is event-surface semantics, not Boolean guard-region semantics.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
fn
|
Callable[..., float]
|
Root function; transitions when it crosses zero. |
required |
direction
|
CrossingDirection
|
Crossing direction. Defaults to either direction. |
EITHER
|
label
|
str | None
|
Optional display label. |
None
|
EventSurfaceFunction
Bases: Protocol
Scalar event-surface callback.
FlowFunction
Bases: Protocol
Continuous dynamics callback.
HybridSystem(locations, transitions, initial_location, initial_state, parameters=dict())
dataclass
Hybrid system with locations and transitions.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
locations
|
Sequence[Location]
|
Location objects in this system. |
required |
transitions
|
Sequence[Transition]
|
Transition list defining event surfaces and resets. |
required |
initial_location
|
Location
|
Starting location object. |
required |
initial_state
|
State
|
Initial state vector. |
required |
parameters
|
Parameters
|
Global parameter map passed to callbacks. |
dict()
|
transitions_from(location)
Return transitions leaving the given location.
Source code in src/flowcean/ode/hybrid_system.py
292 293 294 295 296 297 298 | |
Location(dynamics, *, label=None, parameters=None)
dataclass
Location(
dynamics: ContinuousDynamics,
*,
label: str | None = None,
parameters: Parameters | None = None,
)
Location(
dynamics: Callable[..., Derivative],
*,
label: str | None = None,
parameters: Parameters | None = None,
)
Discrete hybrid-automaton location.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
dynamics
|
ContinuousDynamics | Callable[..., Derivative]
|
Continuous dynamics or bare flow callback active here. |
required |
label
|
str | None
|
Optional display label. |
None
|
parameters
|
Parameters | None
|
Location-local parameter map. |
None
|
Source code in src/flowcean/ode/hybrid_system.py
117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 | |
Reset(fn, label=None)
dataclass
State reset applied on a transition.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
fn
|
Callable[..., State]
|
Reset function applied at the event time. |
required |
label
|
str | None
|
Optional display label. |
None
|
ResetFunction
Bases: Protocol
State reset callback.
Trace(t, x, location, events, u=None, dx=None)
dataclass
Simulation trace with time, state, and location labels.
as_dict()
Return a dictionary view of the trace.
Source code in src/flowcean/ode/hybrid_system.py
365 366 367 368 369 370 371 372 373 374 | |
Transition(source, target, event, reset=None)
dataclass
Discrete event-triggered transition between locations.
event is a scalar zero-crossing surface.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
source
|
Location
|
Source location. |
required |
target
|
Location
|
Target location. |
required |
event
|
EventSurface | Callable[..., float]
|
Event surface that triggers the transition. |
required |
reset
|
Reset | Callable[..., State] | None
|
Optional reset applied upon transition. |
None
|
Source code in src/flowcean/ode/hybrid_system.py
203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 | |
IntegrationError()
Bases: Exception
Error while integrating an ODE.
This exception is raised when an error occurs while integrating an ordinary differential equation.
Initialize the exception.
Source code in src/flowcean/ode/ode_environment.py
20 21 22 | |
OdeEnvironment(system, *, dt=1.0, map_to_dataframe)
Bases: IncrementalEnvironment
Environment governed by an ordinary differential equation.
This environment integrates an OdeSystem to generate a sequence of states.
Initialize the environment.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
system
|
OdeSystem[X]
|
ODE system. |
required |
dt
|
float
|
Time step. |
1.0
|
map_to_dataframe
|
Callable[[Sequence[float], Sequence[X]], DataFrame]
|
Function to map states to a DataFrame. |
required |
Source code in src/flowcean/ode/ode_environment.py
142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 | |
OdeState
Bases: ABC
State of a differential equation.
This class represents the state of a differential equation. It provides methods to convert the state to and from a numpy array for integration.
as_numpy()
abstractmethod
Convert the state to a numpy array.
Returns:
| Type | Description |
|---|---|
NDArray[float64]
|
State as a numpy array. |
Source code in src/flowcean/ode/ode_environment.py
32 33 34 35 36 37 38 | |
from_numpy(state)
abstractmethod
classmethod
Create a state from a numpy array.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
state
|
NDArray[float64]
|
State as a numpy array. |
required |
Returns:
| Type | Description |
|---|---|
Self
|
State instance. |
Source code in src/flowcean/ode/ode_environment.py
40 41 42 43 44 45 46 47 48 49 50 | |
OdeSystem(t, state)
Bases: ABC
System governed by an ordinary differential equation.
This class represents a continuous system. The system is defined by a differential flow function \(f\) that governs the evolution of the state \(x\).
The system can be integrated to obtain the state at a future time.
Attributes:
| Name | Type | Description |
|---|---|---|
t |
float
|
Current time. |
state |
X
|
Current state. |
Initialize the system.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
t
|
float
|
Initial time. |
required |
state
|
X
|
Initial state. |
required |
Source code in src/flowcean/ode/ode_environment.py
75 76 77 78 79 80 81 82 83 | |
flow(t, state)
abstractmethod
Ordinary differential equation.
Compute the derivative of the state \(x\) at time \(t\).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
t
|
float
|
Time. |
required |
state
|
NDArray[float64]
|
State. |
required |
Returns:
| Type | Description |
|---|---|
NDArray[float64]
|
Derivative of the state. |
Source code in src/flowcean/ode/ode_environment.py
85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 | |
step(dt)
Step the environment forward in time.
Step the environment forward in time by integrating the differential equation for a time step of dt.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
dt
|
float
|
Time step. |
required |
Returns:
| Type | Description |
|---|---|
tuple[Sequence[float], Sequence[X]]
|
Tuple of times and states of the integration. |
Source code in src/flowcean/ode/ode_environment.py
103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 | |
save_traces_csv(traces, path, *, trace_metadata=None)
Write traces to a directory with one CSV file per trace.
Source code in src/flowcean/ode/io.py
106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 | |
save_traces_parquet(traces, path, *, trace_metadata=None)
Write traces to a directory with one Parquet file per trace.
Source code in src/flowcean/ode/io.py
88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 | |
trace_to_polars(trace, *, state_names=None, derivative_names=None, input_names=None)
Convert a single trace into a Polars DataFrame.
Source code in src/flowcean/ode/io.py
124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 | |
traces_to_polars(traces, *, state_names=None, derivative_names=None, input_names=None)
Convert traces into per-trace Polars DataFrames.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
traces
|
Sequence[Trace]
|
Sequence of traces to convert. |
required |
state_names
|
Sequence[str] | None
|
Optional names for state dimensions. |
None
|
derivative_names
|
Sequence[str] | None
|
Optional names for derivative dimensions. |
None
|
input_names
|
Sequence[str] | None
|
Optional names for input dimensions. |
None
|
Returns:
| Type | Description |
|---|---|
list[DataFrame]
|
List of per-trace DataFrames in trace order. |
Source code in src/flowcean/ode/io.py
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 | |
plot_phase(trace, x_dim=0, y_dim=1, *, location_colors=None, show_location_legend=True, show=False, ax=None)
Plot phase portrait segments colored by location.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
trace
|
Trace
|
Trace to visualize. |
required |
x_dim
|
int
|
State index on the x-axis. |
0
|
y_dim
|
int
|
State index on the y-axis. |
1
|
location_colors
|
Mapping[str, str] | None
|
Optional color mapping for locations. |
None
|
show_location_legend
|
bool
|
Whether to show location labels in legend. |
True
|
show
|
bool
|
Whether to call matplotlib show(). |
False
|
ax
|
Axes | None
|
Optional axis to draw into. |
None
|
Returns:
| Type | Description |
|---|---|
Axes
|
Matplotlib axes containing the plot. |
Source code in src/flowcean/ode/plotting.py
74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 | |
plot_trace(trace, dims=None, *, location_colors=None, show_locations=True, show_location_labels=False, show_events=True, show_event_labels=True, show=False, ax=None)
Plot state trajectories with location shading and event markers.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
trace
|
Trace
|
Trace to visualize. |
required |
dims
|
Sequence[int] | None
|
State indices to plot. |
None
|
location_colors
|
Mapping[str, str] | None
|
Optional color mapping for locations. |
None
|
show_locations
|
bool
|
Whether to shade location regions. |
True
|
show_location_labels
|
bool
|
Whether to label locations above the trace. |
False
|
show_events
|
bool
|
Whether to show transition events. |
True
|
show_event_labels
|
bool
|
Whether to label transition events. |
True
|
show
|
bool
|
Whether to call matplotlib show(). |
False
|
ax
|
Axes | None
|
Optional axis to draw into. |
None
|
Returns:
| Type | Description |
|---|---|
Axes
|
Matplotlib axes containing the plot. |
Source code in src/flowcean/ode/plotting.py
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 | |
generate_traces(system, t_span, initial_states, *, input_stream=None, capture_inputs=None, capture_derivatives=False, max_jumps=256, rtol=1e-07, atol=1e-09, max_step=None, dense_output=False, sample_times=None, sample_dt=None)
Simulate a batch of traces for a set of initial states.
The input stream and capture semantics match :func:simulate, including
the requirement that capture_derivatives=True assumes pure flow
callbacks under repeated evaluation on the returned trace grid. Scalar
derivative returns are accepted only for single-state systems.
Source code in src/flowcean/ode/simulator.py
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 342 343 344 345 346 347 | |
simulate(system, t_span, x0=None, location0=None, *, input_stream=None, capture_inputs=None, capture_derivatives=False, max_jumps=256, rtol=1e-07, atol=1e-09, max_step=None, dense_output=False, sample_times=None, sample_dt=None)
Simulate a hybrid system and return a trace.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
system
|
HybridSystem
|
Hybrid system to simulate. |
required |
t_span
|
tuple[float, float]
|
Start and end time for integration. |
required |
x0
|
Iterable[float] | None
|
Optional initial state override. |
None
|
location0
|
Location | None
|
Optional initial location override. |
None
|
input_stream
|
InputStream | None
|
Optional input stream accessor for callbacks. |
None
|
capture_inputs
|
bool | None
|
Input capture mode. If |
None
|
capture_derivatives
|
bool
|
Whether to re-evaluate |
False
|
max_jumps
|
int
|
Maximum number of transitions allowed. |
256
|
rtol
|
float
|
Relative tolerance for the solver. |
1e-07
|
atol
|
float
|
Absolute tolerance for the solver. |
1e-09
|
max_step
|
float | None
|
Optional maximum step size. |
None
|
dense_output
|
bool
|
Whether to build a continuous solution per segment. |
False
|
sample_times
|
Iterable[float] | None
|
Monotone time grid to sample from the dense solution. |
None
|
sample_dt
|
float | None
|
Fixed sampling interval to generate a time grid. |
None
|
Returns:
| Name | Type | Description |
|---|---|---|
Trace |
Trace
|
The simulation trace with location labels and events. |
Source code in src/flowcean/ode/simulator.py
70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 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 | |