Skip to content

Microgrid

Microgrid

A simulated energy system.

A microgrid is a collection of actors (exogenous consumers and producers), dispatchables (controllable resources like batteries), and a dispatch policy that governs their interaction. It can also be connected to the public grid.

Parameters:

Name Type Description Default
world World

The mosaik world instance.

required
step_size int

The step size of the simulation in seconds.

required
actors list[Actor]

The exogenous actors in the microgrid.

required
dispatchables list[Dispatchable]

The dispatchable resources in the microgrid.

required
policy DispatchPolicy

The DispatchPolicy that controls the microgrid.

required
grid_signals Optional[dict[str, Signal]]

Optional signals from the public grid.

None
name Optional[str]

Optional name for the microgrid.

None
coords Optional[tuple[float, float]]

Optional coordinates (latitude, longitude) for visualizing the microgrid's location in the dashboard.

None
Source code in vessim/microgrid.py
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 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
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
class Microgrid:
    """A simulated energy system.

    A microgrid is a collection of actors (exogenous consumers and producers),
    dispatchables (controllable resources like batteries), and a dispatch policy
    that governs their interaction. It can also be connected to the public grid.

    Args:
        world: The mosaik world instance.
        step_size: The step size of the simulation in seconds.
        actors: The exogenous actors in the microgrid.
        dispatchables: The dispatchable resources in the microgrid.
        policy: The `DispatchPolicy` that controls the microgrid.
        grid_signals: Optional signals from the public grid.
        name: Optional name for the microgrid.
        coords: Optional coordinates (latitude, longitude) for visualizing the
            microgrid's location in the dashboard.
    """

    def __init__(
        self,
        world: mosaik.World,
        step_size: int,
        actors: list[Actor],
        dispatchables: list[Dispatchable],
        policy: DispatchPolicy,
        grid_signals: Optional[dict[str, Signal]] = None,
        name: Optional[str] = None,
        coords: Optional[tuple[float, float]] = None,
    ):
        self.step_size = step_size
        self.actors = actors
        self.dispatchables = dispatchables
        self.policy = policy
        self.grid_signals = grid_signals
        self.name = name or f"microgrid_{id(self)}"
        self.coords = coords

        self.actor_entities = {}
        for actor in actors:
            actor_step_size = actor.step_size if actor.step_size else step_size
            if actor_step_size % step_size != 0:
                raise ValueError("Actor step size has to be a multiple of grids step size.")
            actor_sim = world.start(
                "Actor",
                sim_id=f"{self.name}.actor.{actor.name}",
                step_size=actor_step_size,
            )
            # We initialize all actors before the microgrid simulation to make sure
            # that there is already a valid p_delta at step 0
            self.actor_entities[actor.name] = actor_sim.Actor(actor=actor)

        microgrid_sim = world.start(
            "Microgrid",
            sim_id=f"{self.name}.microgrid",
            step_size=step_size,
            grid_signals=grid_signals,
        )
        self.entity = microgrid_sim.Microgrid(
            dispatchables=dispatchables, policy=policy,
        )
        for actor_entity in self.actor_entities.values():
            world.connect(actor_entity, self.entity, "power")

    def finalize(self):
        """Clean up in case the simulation was interrupted.

        Mosaik already has a cleanup functionality but this is an additional safety net
        in case the user interrupts the simulation before entering the mosiak event loop.
        """
        for actor in self.actors:
            actor.finalize()

finalize

Clean up in case the simulation was interrupted.

Mosaik already has a cleanup functionality but this is an additional safety net in case the user interrupts the simulation before entering the mosiak event loop.

Source code in vessim/microgrid.py
 93
 94
 95
 96
 97
 98
 99
100
def finalize(self):
    """Clean up in case the simulation was interrupted.

    Mosaik already has a cleanup functionality but this is an additional safety net
    in case the user interrupts the simulation before entering the mosiak event loop.
    """
    for actor in self.actors:
        actor.finalize()

MicrogridState

Bases: TypedDict

State of a microgrid.

This state is passed to Controllers on every step.

Source code in vessim/microgrid.py
15
16
17
18
19
20
21
22
23
24
25
26
class MicrogridState(TypedDict):
    """State of a microgrid.

    This state is passed to `Controller`s on every step.
    """

    p_delta: float  # Current power delta in W
    p_grid: float  # Last step's power exchange with the public grid in W
    actor_states: dict[str, dict]  # States of all actors in the microgrid
    policy_state: dict  # State of the microgrid dispatch policy
    dispatch_states: dict[str, dict]  # States of all dispatchables, keyed by name
    grid_signals: Optional[dict[str, float]]  # Current grid signals, if available