commonpower.core.Node

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

Bases: ControllableModelEntity

Base class providing functionality for busses and components.

Parameters:
  • name (str) – Name of the Node object.

  • config (dict, optional) – Configuration for defined model elements. Defaults to {}.

Methods

add_data_provider

Adds a data provider to the entity.

add_node

Adds a subordinate node.

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

compute_cost

Computes the cost based on the specified cost_fcn and stores the result in the node's cost parameter.

cost_fcn

Returns the node's cost as pyomo expression at time t.

detach_controller

Remove the current controller from the entity

empty_copy

Creates a fresh copy of the node.

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

reset

Stores the current global model instance and initializes parameters according to their configuration.

set_id

Generates and sets the node id.

set_value

Sets the value of the specified model element to the specified value.

unmodeled_update

System updates that are not modeled.

update

This reads data providers and executes the dynamics of self and all subordinate nodes.

update_data

Reads data providers for self and all subnodes.

validate_controller

Used to check whether all nodes which require a controller have one assigned.

validate_data_providers

Validates if data providers have compatible configurations.

Attributes

CLASS_INDEX

_add_constraints(model_elements: List[ModelElement]) List[ModelElement][source]
This method adds all node constraints

All of this is appended to the given model_elements list and returned.

Parameters:

model_elements (List[ModelElement]) – Model elements list so far

Returns:

List[ModelElement] – Model elements list with appended constraints

classmethod _augment_model_elements(model_elements: List[ModelElement]) List[ModelElement][source]

This method adds initial state variables and a cost variable All of this is appended to the given model_elements list and returned.

Parameters:

model_elements (List[ModelElement]) – Model elements list so far.

Returns:

List[ModelElement] – Model elements list with added limit variables and cost variable

_get_additional_constraints() List[ModelElement][source]

Returns additional constraints on model variables. This is a utility to keep the _get_model_elements() method clean.

Returns:

List[ModelElement] – List of additional constraint elements.

_get_dynamic_fcn() List[ModelElement][source]

Returns constraints on all state variables representing how the states change between timesteps.

Returns:

List[ModelElement] – Generated constraints.

_step_solution()[source]

Steps all variables (except states) forward by one timestep. This is mainly to provide a better warm-start for the solver in the next iteration.

_unmodeled_updates() None[source]

Unmodeled update actions can be defined here. This could for example be the “true” dynamics of the system, or maniputations of parameters.

_update_data(at_time: datetime)[source]

Reads node data providers.

Parameters:

at_time (datetime) – Timestamp of “now”.

_update_state()[source]

Updates states by moving one timestep “forward”, i.e., state[t] <- state[t+1]. This method can be overwritten by subclasses to implement the “true” dynamics of the system.

add_node(node: Node) Node[source]

Adds a subordinate node. The added node’s id is set according to its position in the model hierarchy.

Parameters:

node (Node) – Node istance to add.

Returns:

Node – Node instance.

add_to_model(model: ConcreteModel, **kwargs) None[source]

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.

We also store a reference to the global model in self.model.

Parameters:
  • model (ConcreteModel) – Global pyomo model.

  • **kwargs

compute_cost() None[source]

Computes the cost based on the specified cost_fcn and stores the result in the node’s cost parameter.

cost_fcn(scenario: CostScenario, model: ConcreteModel, t: int = 0) Expression[source]

Returns the node’s cost as pyomo expression at time t.

\[cost = \sum_{i \in children} cost_i\]
Returns:

Expression – Cost.

empty_copy(with_children: bool = True, with_data_providers: bool = True) Node[source]

Creates a fresh copy of the node.

Parameters:
  • with_children (bool) – Whether to clone the node’s children.

  • with_data_providers (bool) – Whether to clone the node’s data providers.

Returns:

Node – Cloned node instance.

reset(instance: ConcreteModel, at_time: datetime) None[source]

Stores the current global model instance and initializes parameters according to their configuration. It additionally loads the “current” values from data providers.

Parameters:
  • instance (ConcreteModel) – Global model instance.

  • at_time (datetime) – Timestamp of “now”.

set_id(parent_identity: str = '', number: int = 0) None[source]

Generates and sets the node id. This is called by the parent entity, i.e., the next higher entity in the object tree.

Parameters:
  • parent_identity (str, optional) – Id of the parent entity. Defaults to “”.

  • number (int, optional) – Number assigned by the parent entity. Defaults to 0.

unmodeled_update() None[source]

System updates that are not modeled. This could for example be the “true” dynamics of the system, or maniputations of parameters.

update(at_time: datetime) None[source]

This reads data providers and executes the dynamics of self and all subordinate nodes. Results are written to current model instance. It also calls _additional_updates().

Parameters:

at_time (datetime) – Timestamp of “now”.

update_data(at_time: datetime)[source]

Reads data providers for self and all subnodes.

Parameters:

at_time (datetime) – Timestamp of “now”.

validate_controller(controller_ids: list, controllers: dict) Tuple[list, dict][source]

Used to check whether all nodes which require a controller have one assigned. All unique controllers are added to a list of controllers maintained by the power system.

Parameters:
  • controller_ids (list) – unique controller IDs already registered by the system

  • controllers (list) – unique controllers already registered by the system

Returns:

list – IDs of controllers within the system dict: dictionary of {controller_id: controller} within the system

validate_data_providers(horizon: timedelta, tau: timedelta) None[source]

Validates if data providers have compatible configurations.

Parameters:
  • horizon (timedelta) – Forecast horizon.

  • tau (timedelta) – Sample time.