Skip to content

Scenario

abc

Abstract base class for scenarios.

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

Alias for a NumPy ndarray with float64 data type.

ScenarioABC

Bases: ModuleABC

Abstract base class for scenarios.

scenario_type abstractmethod property

Return the type of the scenario tuples for introspection purposes.

Returns:

Type Description
type[NamedTuple]

The type of the scenario tuples.

scenarios() abstractmethod

Expose the scenarios.

Returns:

Type Description
Iterable[NamedTuple]

An iterable of scenario tuples.

Source code in src/flepimop2/scenario/abc/__init__.py
@abstractmethod
def scenarios(self) -> Iterable[NamedTuple]:
    """Expose the scenarios.

    Returns:
        An iterable of scenario tuples.
    """
    raise NotImplementedError

build(config)

Build a ScenarioABC from a configuration dictionary.

Parameters:

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

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

required

Returns:

Type Description
ScenarioABC

The constructed scenario instance.

Source code in src/flepimop2/scenario/abc/__init__.py
def build(config: dict[IdentifierString, Any] | ModuleModel) -> ScenarioABC:
    """Build a `ScenarioABC` from a configuration dictionary.

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

    Returns:
        The constructed scenario instance.

    """
    return _build(config, "scenario", "flepimop2.scenario.grid", ScenarioABC)

grid

Grid scenario implementation.

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

Alias for a NumPy ndarray with float64 data type.

GridScenario

Bases: ModuleModel, ScenarioABC

Grid scenario implementation.

This scenario generates scenarios by taking the Cartesian product of parameter lists defined in the configuration.

Attributes:

Name Type Description
module Literal['flepimop2.scenario.grid']

The module type, fixed to "flepimop2.scenario.grid".

parameters dict[IdentifierString, list[Any]]

A dictionary where keys are parameter names and values are lists of parameter values to be combined into scenarios.

scenario_type property

Return the type of the scenario tuples for introspection purposes.

Returns:

Type Description
type[NamedTuple]

The type of the scenario tuples.

scenarios()

Expose the scenarios.

Yields:

Type Description
Iterable[NamedTuple]

Scenario tuples from parameters.

Source code in src/flepimop2/scenario/grid/__init__.py
def scenarios(self) -> Iterable[NamedTuple]:
    """
    Expose the scenarios.

    Yields:
        Scenario tuples from parameters.
    """
    param_lists = self.parameters.values()
    for p in itertools.product(*param_lists):
        yield self.scenario_type(*p)