commonpower.modeling.base.ControllableModelEntity
- class ControllableModelEntity(name: str, config: dict = {})[source]
Bases:
ModelEntityThis class abstracts ModelEntities which are controllable.
This class abstracts power system entities which have a pyomo model representation. It also bundles all interfaces needed to interact with their model. Subclasses of ModelEntity implement certain methods which specify the model elements associated to instances of that class.
- Parameters:
name (str) – Descriptive name of the entity. It will not be used within the pyomo model and is merely for human interpretability.
config (dict, optional) – Configuration dict of the entity. The content required depends on the modelling of the specific subclass. Defaults to {}.
Methods
add_data_providerAdds a data provider to the entity.
add_to_modelThis method adds the calling entity to the given (global) pyomo model. To this end, we - declare and add a new pyomo block named by self.id (the entity's global id). - call _get_model_elements() to retrieve the entity's model elements (variables and parameters). - call _augment_model_elements() to add additional model elements (constraints etc.). - check the configuration dict for completeness based on the defined model elements. - add all model elements to the previously declared pyomo block.
clear_data_providerscost_fcnReturns the pyomo expression of the entity's cost function.
Remove the current controller from the entity
Set the variables corresponding to inputs to fixed
get_childrenGet identifiers of input elements of a given model instance or self :param model_instance: model to get the input element identifiers for
Extracts model elements of type INPUT from a given model instance or self :param model_instance: model to get the input elements for :type model_instance: ConcreteModel, Optional
get_pyomo_elementGets a pyomo element referenced by name from the given model.
get_pyomo_element_idConstructs the global element name from the local name.
get_self_as_pyomo_blockRetrieves the pyomo block of the calling entity from a global model (based on the entity's global id).
get_valueGets the value of the specified model element.
has_pyomo_elementThis is essentially an indicator wrapper around get_pyomo_element() which returns False if no corresponding model element could be found (instead of raising an error).
infoPrints some information about this entity.
Determines the input space of an entity from the bounds of all model elements with type INPUT within the tree :param normalize: Whether or not to normalize the input space to [-1,1] :type normalize: bool
Total number of model elements with type INPUT within the entire tree of this entity
Determines the observation space of an entity based on the observation mask by retrieving the bounds of the model elements listed in the mask
Get observations for one node within the system based on the model items within the observation mask.
Register a controller with this node :param controller: controller to be registered :type controller: BaseController
set_valueSets the value of the specified model element to the specified value.
- detach_controller(include_children: bool = False)[source]
Remove the current controller from the entity
Returns: None
- fix_inputs(inputs: Dict)[source]
Set the variables corresponding to inputs to fixed
- Parameters:
inputs – nested dictionary of inputs corresponding to model elements of type INPUT
- Returns:
None
- get_input_ids(model_instance: ConcreteModel | None = None) list | None[source]
Get identifiers of input elements of a given model instance or self :param model_instance: model to get the input element identifiers for
- Returns:
(None/list) – list of identifiers of model elements of type INPUT
- get_inputs(model_instance: ConcreteModel | None = None) Dict[source]
Extracts model elements of type INPUT from a given model instance or self :param model_instance: model to get the input elements for :type model_instance: ConcreteModel, Optional
- Returns:
(None/Dict) – dictionary of {element_name: array_of_input_values}
- input_space(normalize: bool = True)[source]
Determines the input space of an entity from the bounds of all model elements with type INPUT within the tree :param normalize: Whether or not to normalize the input space to [-1,1] :type normalize: bool
- Returns:
(None/gym.spaces.Dict) – input space as a nested dictionary {element_name: box_input_space} in the format of the gymnasium API
- n_inputs() int[source]
Total number of model elements with type INPUT within the entire tree of this entity
- Returns:
int – number of inputs
- observation_space(obs_mask: Tuple[dict, int])[source]
Determines the observation space of an entity based on the observation mask by retrieving the bounds of the model elements listed in the mask
- Parameters:
Tuple (obs_mask) – tuple with a) dictionary containing the IDs of model elements which should
observed (be)
observation (b) number of forecast steps that should be included in)
- Returns:
None/gym.spaces.Dict – None if the node has no elements that should be observed, else a dictionary as in {model element ID: box observation space}
- observe(obs_mask: Tuple[dict, int]) dict[source]
Get observations for one node within the system based on the model items within the observation mask.
- Parameters:
Tuple (obs_mask) – tuple with a) dictionary containing the IDs of model elements which should
observed (be)
observation (b) number of forecast steps that should be included in)
- Returns:
dict – dict of observed values as {element ID: value}