Skip to content

Typing

typing

Custom Typing Helpers.

This module centralizes type aliases used throughout the project and makes it easy to keep runtime imports lightweight while still providing precise type information. The goal is to express common shapes and dtypes once, so internal modules can share consistent, readable annotations without repeating NumPy typing boilerplate.

Examples:

>>> from flepimop2.typing import Float64NDArray
>>> Float64NDArray
numpy.ndarray[tuple[typing.Any, ...], numpy.dtype[numpy.float64]]

Float64NDArray = npt.NDArray[np.float64] module-attribute

Alias for a NumPy ndarray with float64 data type.

IdentifierString = Annotated[str, Field(min_length=1, max_length=255, pattern='^[a-z]([a-z0-9\\_]*[a-z0-9])?$'), AfterValidator(_identifier_string)] module-attribute

A string type representing a valid identifier for named configuration elements.

RaiseOnMissing = RaiseOnMissingType() module-attribute

Sentinel value indicating an error should be raised if a value is missing.

EngineProtocol

Bases: Protocol

Type-definition (Protocol) for engine runner functions.

__call__(stepper, times, state, params, **kwargs)

Protocol for engine runner functions.

Source code in src/flepimop2/typing.py
def __call__(
    self,
    stepper: SystemProtocol,
    times: Float64NDArray,
    state: Float64NDArray,
    params: dict[IdentifierString, Any],
    **kwargs: Any,
) -> Float64NDArray:
    """Protocol for engine runner functions."""
    ...

RaiseOnMissingType

A sentinel type indicating an error should be raised if a value is missing.

__reduce__()

Helper for pickling the RaiseOnMissingType singleton.

Returns:

Type Description
Literal['RaiseOnMissing']

The string "RaiseOnMissing".

Source code in src/flepimop2/typing.py
def __reduce__(self) -> Literal["RaiseOnMissing"]:
    """
    Helper for pickling the `RaiseOnMissingType` singleton.

    Returns:
        The string "RaiseOnMissing".
    """
    return "RaiseOnMissing"

__repr__()

String representation of the RaiseOnMissingType.

Returns:

Type Description
Literal['RaiseOnMissing']

The string "RaiseOnMissing".

Source code in src/flepimop2/typing.py
def __repr__(self) -> Literal["RaiseOnMissing"]:
    """
    String representation of the `RaiseOnMissingType`.

    Returns:
        The string "RaiseOnMissing".
    """
    return "RaiseOnMissing"

StateChangeEnum

Bases: StrEnum

Enumeration of types of state changes in a system.

Examples:

>>> from flepimop2.typing import StateChangeEnum
>>> StateChangeEnum.DELTA
<StateChangeEnum.DELTA: 'delta'>
>>> StateChangeEnum.FLOW
<StateChangeEnum.FLOW: 'flow'>

DELTA = 'delta' class-attribute instance-attribute

The state change is described directly by the changes in the state variables, i.e. \( x(t + \Delta t) = x(t) + \Delta x \).

ERROR = 'error' class-attribute instance-attribute

The state change is mis-specified.

FLOW = 'flow' class-attribute instance-attribute

The state change is described directly by the flow rates, or derivatives, of the state variables. I.e. \( dx/dt = f(x, t) \).

STATE = 'state' class-attribute instance-attribute

The state change is described directly by the new state values, i.e. \( x(t + \Delta t) = x_{new} \).

SystemProtocol

Bases: Protocol

Type-definition (Protocol) for system stepper functions.

__call__(time, state, **kwargs)

Protocol for system stepper functions.

Source code in src/flepimop2/typing.py
def __call__(
    self, time: np.float64, state: Float64NDArray, **kwargs: Any
) -> Float64NDArray:
    """Protocol for system stepper functions."""
    ...

as_system_protocol(func)

Decorator to mark a function as a SystemProtocol.

Parameters:

Name Type Description Default
func _SystemCallable[_P]

A callable matching the SystemProtocol signature.

required

Returns:

Type Description
SystemProtocol

The function cast as SystemProtocol.

Source code in src/flepimop2/typing.py
def as_system_protocol(func: _SystemCallable[_P]) -> SystemProtocol:
    """
    Decorator to mark a function as a SystemProtocol.

    Args:
        func: A callable matching the SystemProtocol signature.

    Returns:
        The function cast as SystemProtocol.
    """
    return cast("SystemProtocol", func)