Skip to content

Commit

Permalink
Minor renaming, cleaning, commenting
Browse files Browse the repository at this point in the history
  • Loading branch information
thomaswolgast committed Nov 20, 2024
1 parent 8da14f0 commit 5177c8c
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 22 deletions.
6 changes: 4 additions & 2 deletions opfgym/constraints.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,11 @@ class Constraint():
unit_type: Which pandapower table to look at for constraint data.
values_column: Which column in the previous table?
get_values: Function to extract the values from the pandapower network.
(def get_values(net) -> np.ndarray)
(def get_values(net) -> pd.Series)
get_boundaries: Function to extract the boundaries from the pandapower network.
(def get_boundaries(net) -> dict[str, pd.Series])
only_worst_case_violations: Only compute the worst-case violations? (instead of the sum of all)
auto_scale_violation: Scale violations to be of similar magnitude?
autoscale_violation: Scale violations to be of similar magnitude?
scale_bounded_values: Apply the scaling column to the bounded values? Required if the constraint is scaled as well, for example, for apparent power s_mva)
penalty_factor: Penalty scaling factor
penalty_power: Power to apply to the violation (e.g. 0.5 for square root, 2 for quadratic, etc.)
Expand Down
26 changes: 6 additions & 20 deletions opfgym/opf_env.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,15 +34,14 @@ def __init__(self,
bus_wise_obs: bool=False,
reward_function: opfgym.RewardFunction=None,
reward_function_params: dict=None,
remove_normal_obs: bool=False,
add_res_obs: bool=False,
add_time_obs: bool=False,
add_act_obs: bool=False,
add_mean_obs: bool=False,
train_data: str='simbench',
test_data: str='simbench',
sampling_kwargs: dict=None,
constraint_kwargs: dict={},
sampling_params: dict=None,
constraint_params: dict={},
custom_constraints: list=None,
autoscale_actions: bool=True,
diff_action_step_size: float=None,
Expand Down Expand Up @@ -84,26 +83,13 @@ def __init__(self,
self.evaluate_on = evaluate_on
self.train_data = train_data
self.test_data = test_data
self.sampling_kwargs = sampling_kwargs if sampling_kwargs else {}
self.sampling_params = sampling_params or {}

# Define the observation space
if remove_normal_obs:
# Completely overwrite the observation definition
assert add_res_obs or add_time_obs or add_act_obs
# Make sure to only remove redundant data and not e.g. price data
remove_idxs = []
for idx, (unit_type, column, _) in enumerate(self.obs_keys):
if unit_type in ('load', 'sgen', 'gen') and column in ('p_mw', 'q_mvar'):
remove_idxs.append(idx)
self.obs_keys = [value for index, value in enumerate(self.obs_keys)
if index not in remove_idxs]

self.add_act_obs = add_act_obs
if add_act_obs:
# The agent can observe its previous actions
self.obs_keys.extend(self.act_keys)
# Does not make sense without observing results from previous act
add_res_obs = True

self.add_time_obs = add_time_obs
# Add observations that require previous pf calculation
Expand Down Expand Up @@ -162,7 +148,7 @@ def __init__(self,
# Constraints
if custom_constraints is None:
self.constraints = opfgym.constraints.create_default_constraints(
self.net, constraint_kwargs)
self.net, constraint_params)
else:
self.constraints = custom_constraints

Expand Down Expand Up @@ -214,14 +200,14 @@ def reset(self, seed=None, options=None) -> tuple:

return self._get_obs(self.obs_keys, self.add_time_obs), copy.deepcopy(self.info)

def _sampling(self, step=None, test=False, sample_new=True,
def _sampling(self, step=None, test=False, sample_new=True,
*args, **kwargs) -> None:

self.power_flow_available = False
self.optimal_power_flow_available = False

data_distr = self.test_data if test is True else self.train_data
kwargs.update(self.sampling_kwargs)
kwargs.update(self.sampling_params)

# Maybe also allow different kinds of noise and similar! with `**sampling_params`?
if data_distr == 'noisy_simbench' or 'noise_factor' in kwargs.keys():
Expand Down

0 comments on commit 5177c8c

Please sign in to comment.