Skip to content

mode_cycle

Scalable location-cycle benchmark with clock resets.

mode_cycle(modes=4, dimension=4, dwell_time=0.5, initial_state=None)

Create a scalable hybrid system that cycles through locations.

The system has modes locations, each with linear dynamics active for dwell_time. A clock state is appended and reset on each transition, making the number of locations and state dimension scalable for benchmarking.

Parameters:

Name Type Description Default
modes int

Number of locations in the cycle.

4
dimension int

Dimension of the continuous state (excluding the clock).

4
dwell_time float

Time to stay in each location.

0.5
initial_state ndarray | None

Optional initial state (length dimension + 1).

None

Returns:

Type Description
HybridSystem

HybridSystem cycling through multiple linear locations.

Source code in src/flowcean/hybrid/benchmarks/mode_cycle.py
 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
def mode_cycle(
    modes: int = 4,
    dimension: int = 4,
    dwell_time: float = 0.5,
    initial_state: np.ndarray | None = None,
) -> HybridSystem:
    """Create a scalable hybrid system that cycles through locations.

    The system has `modes` locations, each with linear dynamics active for
    `dwell_time`.
    A clock state is appended and reset on each transition, making the number
    of locations and state dimension scalable for benchmarking.

    Args:
        modes: Number of locations in the cycle.
        dimension: Dimension of the continuous state (excluding the clock).
        dwell_time: Time to stay in each location.
        initial_state: Optional initial state (length dimension + 1).

    Returns:
        HybridSystem cycling through multiple linear locations.
    """
    if modes < MIN_MODES:
        message = f"modes must be at least {MIN_MODES}."
        raise ValueError(message)
    if dimension < MIN_DIMENSION:
        message = f"dimension must be at least {MIN_DIMENSION}."
        raise ValueError(message)

    matrices = [_make_matrix(dimension, idx) for idx in range(modes)]
    event = EventSurface(
        _event_surface_clock,
        direction=CrossingDirection.RISING,
        label="dwell",
    )
    reset = Reset(_reset_clock, label="reset_clock")
    locations, transitions = _build_locations_and_transitions(
        matrices,
        reset,
        event,
    )

    if initial_state is None:
        initial_state = np.zeros(dimension + 1, dtype=float)
        initial_state[0] = 1.0

    return HybridSystem(
        locations=locations,
        transitions=transitions,
        initial_location=locations[0],
        initial_state=initial_state,
        parameters={"dwell_time": dwell_time},
    )