commonpower.modeling.base.ControllableModelEntity

class ControllableModelEntity(name: str, config: dict = {})[source]

Bases: ModelEntity

This 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_provider

Adds a data provider to the entity.

add_to_model

This 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_providers

cost_fcn

Returns the pyomo expression of the entity's cost function.

detach_controller

Remove the current controller from the entity

fix_inputs

Set the variables corresponding to inputs to fixed

get_children

get_input_ids

Get identifiers of input elements of a given model instance or self :param model_instance: model to get the input element identifiers for

get_inputs

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_element

Gets a pyomo element referenced by name from the given model.

get_pyomo_element_id

Constructs the global element name from the local name.

get_self_as_pyomo_block

Retrieves the pyomo block of the calling entity from a global model (based on the entity's global id).

get_value

Gets the value of the specified model element.

has_pyomo_element

This 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).

info

Prints some information about this entity.

input_space

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

n_inputs

Total number of model elements with type INPUT within the entire tree of this entity

observation_space

Determines the observation space of an entity based on the observation mask by retrieving the bounds of the model elements listed in the mask

observe

Get observations for one node within the system based on the model items within the observation mask.

register_controller

Register a controller with this node :param controller: controller to be registered :type controller: BaseController

set_value

Sets 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}

register_controller(controller)[source]

Register a controller with this node :param controller: controller to be registered :type controller: BaseController

Returns: None