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
andlocal_observation
, which are set through the constructor, control which Observation classes will be used in the simulator. It is thus possible to subclassGlobalObservation
and/orLocalObservation
to use different observations.The computing calls (
compute_agent()
andcompute_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
Describe the shapes of the various Observations (local, global, merged).
The class that will be used to compute global observations.
The class that will be used to compute local observations.
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 ofGlobalObservation()
).
- 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 ofLocalObservation()
).
- observation: Type[Observation]¶
The class that represents the “whole” observation (local and global).
It combines fields from the
global_observation
andlocal_observation
dataclasses. Because these two attributes are set at runtime, this class is dynamically created. To simplify usage, it supports the methods defined inBaseObservation
(fields
,asdict
, and transformation to NumPy array withnp.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:
- Returns:
A dict comprised of:
agent_state
,local_state
, andglobal_state
. Each of these fields describe the shape (i.e., number of dimensions) of the corresponding observation. Note thatagent_state
refers to the merged (both local and global) case.