Skip to content

Engine

abc

Abstract class for Engines to evolve Dynamic Systems.

EngineABC(*args, **kwargs)

Bases: ModuleABC

Abstract class for Engines to evolve Dynamic Systems.

Initialize the EngineABC.

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

Parameters:

Name Type Description Default
*args Any

Positional arguments.

()
**kwargs Any

Keyword arguments.

{}
Source code in src/flepimop2/engine/abc/__init__.py
47
48
49
50
51
52
53
54
55
56
57
58
def __init__(self, *args: Any, **kwargs: Any) -> None:  # noqa: ARG002
    """
    Initialize the EngineABC.

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

    Args:
        *args: Positional arguments.
        **kwargs: Keyword arguments.
    """
    self._runner = _no_run_func
run(system, eval_times, initial_state, params, **kwargs)

Run the engine with the provided system and parameters.

Parameters:

Name Type Description Default
system SystemABC

The dynamic system to be evolved.

required
eval_times Float64NDArray

Array of time points for evaluation.

required
initial_state Float64NDArray

The initial state array.

required
params dict[IdentifierString, Any]

Additional parameters for the stepper.

required
**kwargs Any

Additional keyword arguments for the engine.

{}

Returns:

Type Description
Float64NDArray

The evolved time x state array.

Source code in src/flepimop2/engine/abc/__init__.py
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
86
87
def run(
    self,
    system: SystemABC,
    eval_times: Float64NDArray,
    initial_state: Float64NDArray,
    params: dict[IdentifierString, Any],
    **kwargs: Any,
) -> Float64NDArray:
    """
    Run the engine with the provided system and parameters.

    Args:
        system: The dynamic system to be evolved.
        eval_times: Array of time points for evaluation.
        initial_state: The initial state array.
        params: Additional parameters for the stepper.
        **kwargs: Additional keyword arguments for the engine.

    Returns:
        The evolved time x state array.
    """
    return self._runner(
        system._stepper,  # noqa: SLF001
        eval_times,
        initial_state,
        params,
        **kwargs,
    )
validate_system(system)

Validation hook for system properties.

Parameters:

Name Type Description Default
system SystemABC

The system to validate.

required

Returns:

Type Description
list[ValidationIssue] | None

A list of validation issues, or None if not implemented.

Source code in src/flepimop2/engine/abc/__init__.py
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
def validate_system(  # noqa: PLR6301
    self,
    system: SystemABC,  # noqa: ARG002
) -> list[ValidationIssue] | None:
    """
    Validation hook for system properties.

    Args:
        system: The system to validate.

    Returns:
        A list of validation issues, or `None` if not implemented.
    """
    return None

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/engine/abc/__init__.py
30
31
32
33
34
35
36
37
38
39
def __call__(
    self,
    stepper: SystemProtocol,
    times: Float64NDArray,
    state: Float64NDArray,
    params: dict[IdentifierString, Any],
    **kwargs: Any,
) -> Float64NDArray:
    """Protocol for engine runner functions."""
    ...

build(config)

Build a EngineABC from a configuration dictionary.

Parameters:

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

Configuration dictionary or a ModuleModel instance to construct the engine from.

required

Returns:

Type Description
EngineABC

The constructed engine instance.

Source code in src/flepimop2/engine/abc/__init__.py
105
106
107
108
109
110
111
112
113
114
115
116
def build(config: dict[str, Any] | ModuleModel) -> EngineABC:
    """Build a `EngineABC` from a configuration dictionary.

    Args:
        config: Configuration dictionary or a `ModuleModel` instance to construct the
            engine from.

    Returns:
        The constructed engine instance.

    """
    return _build(config, "engine", "flepimop2.engine.wrapper", EngineABC)

wrapper

A EngineABC which wraps a user-defined script file.

WrapperEngine(*args, **kwargs)

Bases: ModuleModel, EngineABC

A EngineABC which wraps a user-defined script file.

Source code in src/flepimop2/engine/abc/__init__.py
47
48
49
50
51
52
53
54
55
56
57
58
def __init__(self, *args: Any, **kwargs: Any) -> None:  # noqa: ARG002
    """
    Initialize the EngineABC.

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

    Args:
        *args: Positional arguments.
        **kwargs: Keyword arguments.
    """
    self._runner = _no_run_func
validate_system(system)

Validate that the given system is compatible with this engine.

Parameters:

Name Type Description Default
system SystemABC

The system to validate.

required

Returns:

Type Description
list[ValidationIssue] | None

A list of validation issues, or None if not implemented.

Source code in src/flepimop2/engine/wrapper/__init__.py
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
def validate_system(self, system: SystemABC) -> list[ValidationIssue] | None:
    """
    Validate that the given system is compatible with this engine.

    Args:
        system: The system to validate.

    Returns:
        A list of validation issues, or `None` if not implemented.

    """
    if system.state_change != self.state_change:
        return [
            ValidationIssue(
                msg=(
                    f"Engine state change type, '{self.state_change}', is not "
                    "compatible with system state change type "
                    f"'{system.state_change}'."
                ),
                kind="incompatible_system",
            )
        ]
    return None