Skip to content

hybrid_system

Hybrid System.

This module provides the definition of a hybrid system, which is a dynamical system that can switch between different modes of operation. Each mode is defined by a differential equation and a transition function that determines the next mode based on a current input.

DifferentialMode(t, state)

Bases: OdeSystem[X]

Differential mode of a hybrid system.

This class represents a mode of a hybrid system by extending an OdeSystem with a transition function that determines the next mode.

Initialize the system.

Parameters:

Name Type Description Default
t float

Initial time.

required
state X

Initial state.

required
Source code in src/flowcean/environments/ode_environment.py
75
76
77
78
79
80
81
82
83
84
85
86
87
def __init__(
    self,
    t: float,
    state: X,
) -> None:
    """Initialize the system.

    Args:
        t: Initial time.
        state: Initial state.
    """
    self.t = t
    self.state = state

transition(i) abstractmethod

Transition to the next mode.

Determine the next mode based on the current input. This method should return the current mode if no transition is needed.

Parameters:

Name Type Description Default
i Input

Input.

required

Returns:

Type Description
DifferentialMode[X, Input]

Next mode.

Source code in src/flowcean/environments/hybrid_system.py
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
@abstractmethod
def transition(
    self,
    i: Input,
) -> "DifferentialMode[X, Input]":
    """Transition to the next mode.

    Determine the next mode based on the current input. This method should
    return the current mode if no transition is needed.

    Args:
        i: Input.

    Returns:
        Next mode.
    """

HybridSystem(initial_mode, inputs, map_to_dataframe)

Bases: IncrementalEnvironment

Hybrid system environment.

This environment generates samples by simulating a hybrid system. The system is defined by a set of differential modes and a sequence of inputs that determine the transitions between the modes.

Initialize the hybrid system.

Parameters:

Name Type Description Default
initial_mode DifferentialMode[X, Input]

Initial mode of the system.

required
inputs Iterator[tuple[float, Input]]

Timeseries of inputs (time, input).

required
map_to_dataframe Callable[[Sequence[float], Sequence[Input], Sequence[X]], DataFrame]

Function to map times, inputs and states to a DataFrame.

required
Source code in src/flowcean/environments/hybrid_system.py
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
def __init__(
    self,
    initial_mode: DifferentialMode[X, Input],
    inputs: Iterator[tuple[float, Input]],
    map_to_dataframe: Callable[
        [Sequence[float], Sequence[Input], Sequence[X]],
        pl.DataFrame,
    ],
) -> None:
    """Initialize the hybrid system.

    Args:
        initial_mode: Initial mode of the system.
        inputs: Timeseries of inputs (time, input).
        map_to_dataframe: Function to map times, inputs and states to a
            DataFrame.
    """
    super().__init__()
    self.mode = initial_mode
    self.inputs = inputs
    self.map_to_dataframe = map_to_dataframe
    self.last_t = 0.0
    self.data = pl.DataFrame()