commonpower.control.safety_layer.safety_layers.ActionProjectionSafetyLayer

class ActionProjectionSafetyLayer(penalty: BasePenalty, solver: OptSolver | None = None)[source]

Bases: ActionReplacementWithOptSafetyLayer

Computes safe action by minimizing the distance between the RL action and the safe action while also satisfying constraints.

Parameters:
Returns:

ActionReplacementSafetyLayer

Methods

action_distance

Euclidean norm between action expressed by the model and the action in dict

compute_safe_action

Checks whether the actions proposed by the controller satisfy the constraints of the controlled entities and replaces by pyomo-generated output if necessary.

get_penalty

Get penalty depending on the penalty class used.

initialize

Initializes the safety layer :param nodes: list of controlled entities to be safeguarded :type nodes: List[ModelEntity] :param top_level_nodes: list of controlled entities in highest level of model tree :type top_level_nodes: List[ModelEntity] :param solver: solver for optimization problem which will be called by Pyomo :type solver: OptSolver

is_action_feasible

As feasibility check is quite costly, we can skip for projection layer as we check action distance to the original action after optimization

prepare_model

Prepare model.

set_action_from_model

Corrects an action according to a model.

set_action_in_model

Sets the model values to the action to initialize the optimization.

solve_model

Finds a feasible action by solving a local model.

Attributes

DISTANCE_EPS

is_action_feasible(action) bool[source]

As feasibility check is quite costly, we can skip for projection layer as we check action distance to the original action after optimization

prepare_model() ConcreteModel[source]

Prepare model. Additionally projection criterion is added

Returns:

ConcreteModel

pyomo optimization model, representing

the part of the system under supervision of the safety