Skip to content

Commit

Permalink
Bugfix: Reset power flow availability after applying actions
Browse files Browse the repository at this point in the history
  • Loading branch information
thomaswolgast committed Nov 29, 2024
1 parent a5c5bd2 commit 8afd5fc
Showing 1 changed file with 11 additions and 3 deletions.
14 changes: 11 additions & 3 deletions opfgym/opf_env.py
Original file line number Diff line number Diff line change
Expand Up @@ -217,8 +217,7 @@ def reset(self, seed=None, options=None) -> tuple:
def _sampling(self, step=None, test=False, sample_new=True,
*args, **kwargs) -> None:

self.power_flow_available = False
self.optimal_power_flow_available = False
self.set_power_flow_unavailable()

data_distr = self.test_data if test is True else self.train_data
kwargs.update(self.sampling_params)
Expand Down Expand Up @@ -408,10 +407,12 @@ def step(self, action, *args, **kwargs) -> tuple:
return obs, reward, terminated, truncated, copy.deepcopy(self.info)

def _apply_actions(self, action, diff_action_step_size=None) -> float:
""" Apply agent actions as setpoints to the power system at hand.
""" Apply agent actions as setpoints to the power system at hand.
Returns the mean correction that was necessary to make the actions
valid."""

self.set_power_flow_unavailable()

# Clip invalid actions
action = np.clip(action, self.action_space.low, self.action_space.high)

Expand Down Expand Up @@ -636,6 +637,7 @@ def default_power_flow(net, enforce_q_lims=True, **kwargs):
"""
pp.runpp(net, enforce_q_lims=enforce_q_lims, **kwargs)


@staticmethod
def default_optimal_power_flow(net, calculate_voltage_angles=False, **kwargs):
""" Default OPF: Use the pandapower OPF.
Expand All @@ -644,6 +646,12 @@ def default_optimal_power_flow(net, calculate_voltage_angles=False, **kwargs):
in errors for SimBench nets. """
pp.runopp(net, calculate_voltage_angles=calculate_voltage_angles, **kwargs)

def set_power_flow_unavailable(self):
""" Reset the power flow availability to indicate that a new power flow
or OPF calculation is required. """
self.power_flow_available = False
self.optimal_power_flow_available = False


def get_obs_and_state_space(net: pp.pandapowerNet, obs_or_state_keys: list,
add_time_obs: bool=False, add_mean_obs: bool=False,
Expand Down

0 comments on commit 8afd5fc

Please sign in to comment.