Skip to content

System

abc

Abstract class for Dynamic Systems.

SystemABC(*args, **kwargs)

Bases: ModuleABC

Abstract class for Dynamic Systems.

Attributes:

Name Type Description
module str

The module name for the system.

state_change StateChangeEnum

The type of state change.

options dict[str, Any] | None

Optional dictionary of additional options the system exposes for flepimop2 to take advantage of.

Initialize the SystemABC.

The default initialization sets the stepper to a no-op function. Concrete implementations should override this with a valid stepper function.

Parameters:

Name Type Description Default
*args Any

Positional arguments.

()
**kwargs Any

Keyword arguments.

{}
Source code in src/flepimop2/system/abc/__init__.py
77
78
79
80
81
82
83
84
85
86
87
88
def __init__(self, *args: Any, **kwargs: Any) -> None:  # noqa: ARG002
    """
    Initialize the SystemABC.

    The default initialization sets the stepper to a no-op function. Concrete
    implementations should override this with a valid stepper function.

    Args:
        *args: Positional arguments.
        **kwargs: Keyword arguments.
    """
    self._stepper = _no_step_function
__init_subclass__(**kwargs)

Ensure concrete subclasses define a valid state change type.

Parameters:

Name Type Description Default
**kwargs Any

Additional keyword arguments passed to parent classes.

{}

Raises:

Type Description
TypeError

If a concrete subclass does not define state_change.

Source code in src/flepimop2/system/abc/__init__.py
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
def __init_subclass__(cls, **kwargs: Any) -> None:
    """
    Ensure concrete subclasses define a valid state change type.

    Args:
        **kwargs: Additional keyword arguments passed to parent classes.

    Raises:
        TypeError: If a concrete subclass does not define `state_change`.

    """
    super().__init_subclass__(**kwargs)
    if inspect.isabstract(cls):
        return
    annotations = inspect.get_annotations(cls)
    has_state_change = (
        "state_change" in cls.__dict__ or "state_change" in annotations
    )
    if not has_state_change:
        msg = (
            f"Concrete class '{cls.__name__}' must define 'state_change' as "
            "a class attribute or type annotation."
        )
        raise TypeError(msg)
step(time, state, **params)

Perform a single step of the system's dynamics.

Parameters:

Name Type Description Default
time float64

The current time.

required
state Float64NDArray

The current state array.

required
**params Any

Additional parameters for the stepper.

{}

Returns:

Type Description
Float64NDArray

The next state array after one step.

Source code in src/flepimop2/system/abc/__init__.py
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
def step(
    self, time: np.float64, state: Float64NDArray, **params: Any
) -> Float64NDArray:
    """
    Perform a single step of the system's dynamics.

    Args:
        time: The current time.
        state: The current state array.
        **params: Additional parameters for the stepper.

    Returns:
        The next state array after one step.
    """
    return self._stepper(time, state, **params)

SystemProtocol

Bases: Protocol

Type-definition (Protocol) for system stepper functions.

__call__(time, state, **kwargs)

Protocol for system stepper functions.

Source code in src/flepimop2/system/abc/__init__.py
20
21
22
23
24
def __call__(
    self, time: np.float64, state: Float64NDArray, **kwargs: Any
) -> Float64NDArray:
    """Protocol for system stepper functions."""
    ...

build(config)

Build a SystemABC from a configuration dictionary.

Parameters:

Name Type Description Default
config dict[str, Any] | ModuleModel

Configuration dictionary or a ModuleModel instance.

required

Returns:

Type Description
SystemABC

The constructed system instance.

Source code in src/flepimop2/system/abc/__init__.py
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
def build(config: dict[str, Any] | ModuleModel) -> SystemABC:
    """
    Build a `SystemABC` from a configuration dictionary.

    Args:
        config: Configuration dictionary or a `ModuleModel` instance.

    Returns:
        The constructed system instance.

    """
    return _build(
        config,
        "system",
        "flepimop2.system.wrapper",
        SystemABC,
    )

wrapper

A SystemABC which wraps a user-defined script file.

WrapperSystem(*args, **kwargs)

Bases: ModuleModel, SystemABC

A SystemABC which wraps a user-defined script file.

Source code in src/flepimop2/system/abc/__init__.py
77
78
79
80
81
82
83
84
85
86
87
88
def __init__(self, *args: Any, **kwargs: Any) -> None:  # noqa: ARG002
    """
    Initialize the SystemABC.

    The default initialization sets the stepper to a no-op function. Concrete
    implementations should override this with a valid stepper function.

    Args:
        *args: Positional arguments.
        **kwargs: Keyword arguments.
    """
    self._stepper = _no_step_function