commonpower.control.controllers.BaseController
- class BaseController(name: str)[source]
Bases:
objectThis is the base class for any controller type that will be implemented. It manages assignment of controllable entities to the controller and automatically deduces the action space from the bounds of the elements within these entities. The most important functionality of the controller is to compute the control input, a function that has to be implemented by the subclasses.
- Parameters:
name (str) – name of the controller
- Returns:
BaseController
Methods
Converts numpy array of actions to dictionary.
Add a controllable entity to the controller.
When adding a system to a controller, the system tree is searched recursively and all controllable entities that do not yet have a controller are added to 'nodes'.
Clips the control inputs to their bounds to avoid numerical errors.
Has to be implemented by subclasses.
Remove controller from all controlled entities
Filters all element histories for a given time period
Converts observation dictionary to a numpy array.
Compute control cost for one time step
Get ID of controller.
Derives action space of the controller from the list of its controlled entities.
Get controlled nodes.
Retrieve the controlled entities at the highest level in the tree.
Initial set-up of controller.
Has to be implemented by subclasses.
Attributes
obs_mask- _denormalize_input(action: OrderedDict) OrderedDict[source]
Denormalize action to original input space :param action: normalized action
Returns:
- _index_entities()[source]
Called during init to record the all entity ids. We can do this only now because entity ids are assigned when they are added to the pyomo model.
- act_array_to_dict(action: ndarray) OrderedDict[source]
Converts numpy array of actions to dictionary.
- Parameters:
action (np.ndarray) – numpy array of actions
- Returns:
OrderedDict – dictionary of input element IDs and action value for all controlled entities
- add_entity(entity: ControllableModelEntity)[source]
Add a controllable entity to the controller. Recursively searches the component tree of the entity and adds all individual controllable entities from that tree to ‘nodes’.
- Parameters:
entity – controllable entity to be added
- Returns:
BaseController – The current controller
- add_system(system: System) BaseController[source]
When adding a system to a controller, the system tree is searched recursively and all controllable entities that do not yet have a controller are added to ‘nodes’.
- Parameters:
system (System) – system to be added.
- Returns:
BaseController – The current controller.
- clip_to_bounds(control_input: dict) dict[source]
Clips the control inputs to their bounds to avoid numerical errors.
- Parameters:
control_input (dict) – dictionary of {control input ID: value of control input}
- Returns:
dict – dictionary of clipped control inputs
- compute_control_input(obs: OrderedDict | None = None, input_callback: Callable | None = None) Tuple[OrderedDict, float][source]
Has to be implemented by subclasses.
- Parameters:
obs (OrderedDict) – observation at current time point
input_callback (Callable) – only needed in training mode - retrieves action selected within training algorithm
- Returns:
Tuple –
- tuple containing
action (OrderedDict)
penalty for action adjustment performed by safety layer (float).
- filter_history_for_time_period(start: str | Timestamp, end: str | Timestamp) dict[source]
Filters all element histories for a given time period
- Parameters:
start (Union[str, pd.Timestamp]) – beginning of the time period.
str (If) – 00:00”.
00 (should be in format "2016-09-04) – 00:00”.
end (Union[str, pd.Timestamp]) – end of the time period. If str, should be in format “2016-09-04 00:00:00”.
- Returns:
(dict) – the filtered history.
- flatten_obs(obs: dict) ndarray[source]
Converts observation dictionary to a numpy array.
- Parameters:
obs (dict) – dictionary of observed element IDs and their values
- Returns:
np.ndarray – numpy array of all the observations
- get_cost(sys_inst: ConcreteModel) float[source]
Compute control cost for one time step
- Parameters:
sys_inst (ConcreteModel) – current Pyomo model with solution from optimization
- Returns:
float – control cost for one time step
- get_input_space(normalize: bool = False) Dict[source]
Derives action space of the controller from the list of its controlled entities.
- Parameters:
normalize (bool) – whether or not to normalize the action space
- Returns:
gym.spaces.Dict – action space of each entity that has INPUT model elements
- get_nodes() List[ControllableModelEntity][source]
Get controlled nodes.
- Returns:
List[ControllableModelEntity] – all entities under control
- get_top_level_nodes() List[ControllableModelEntity][source]
Retrieve the controlled entities at the highest level in the tree.
- Returns:
List[ControllableModelEntity] – Highest-level entities under control.