smartgrid.observation.observation_manager.ObservationManager

class smartgrid.observation.observation_manager.ObservationManager(local_observation: ~typing.Type[~smartgrid.observation.local_observation.LocalObservation] = <class 'smartgrid.observation.local_observation.LocalObservation'>, global_observation: ~typing.Type[~smartgrid.observation.global_observation.GlobalObservation] = <class 'smartgrid.observation.global_observation.GlobalObservation'>)[source]

Bases: object

The ObservationManager is responsible for computing observations.

Its primary purpose is to allow extensibility: the attributes global_observation and local_observation, which are set through the constructor, control which Observation classes will be used in the simulator. It is thus possible to subclass GlobalObservation and/or LocalObservation to use different observations.

The computing calls (compute_agent() and compute_global()) are delegated to the corresponding calls through these attributes.

__init__(local_observation: ~typing.Type[~smartgrid.observation.local_observation.LocalObservation] = <class 'smartgrid.observation.local_observation.LocalObservation'>, global_observation: ~typing.Type[~smartgrid.observation.global_observation.GlobalObservation] = <class 'smartgrid.observation.global_observation.GlobalObservation'>)[source]

Methods

__init__([local_observation, global_observation])

compute(world, agent)

compute_agent(world, agent)

Create the local observation for an Agent.

compute_global(world)

Create the global observation for the World.

reset()

Reset the ObservationManager.

Attributes

shape

Describe the shapes of the various Observations (local, global, merged).

global_observation

The class that will be used to compute global observations.

local_observation

The class that will be used to compute local observations.

observation

The class that represents the "whole" observation (local and global).

compute_agent(world: World, agent: Agent) LocalObservation[source]

Create the local observation for an Agent.

compute_global(world) GlobalObservation[source]

Create the global observation for the World.

global_observation: Type[GlobalObservation]

The class that will be used to compute global observations. It should be a subclass of GlobalObservation to ensure that necessary methods are present. Please note that this field should be set to a class itself, not an instance, e.g., GlobalObservation (instead of GlobalObservation()).

local_observation: Type[LocalObservation]

The class that will be used to compute local observations. It should be a subclass of LocalObservation to ensure that necessary methods are present. Please note that this field should be set to a class itself, not an instance, e.g., LocalObservation (instead of LocalObservation()).

observation: Type[Observation]

The class that represents the “whole” observation (local and global).

It combines fields from the global_observation and local_observation dataclasses. Because these two attributes are set at runtime, this class is dynamically created. To simplify usage, it supports the methods defined in BaseObservation (fields, asdict, and transformation to NumPy array with np.asarray).

reset()[source]

Reset the ObservationManager.

It is particularly important to reset the memoization process of GlobalObservation.

property shape: Dict[str, int]

Describe the shapes of the various Observations (local, global, merged).

Return type:

dict

Returns:

A dict comprised of: agent_state, local_state, and global_state. Each of these fields describe the shape (i.e., number of dimensions) of the corresponding observation. Note that agent_state refers to the merged (both local and global) case.