Skip to content

Commit

Permalink
For compatibility reason, re-add former API add_specific_voltage_limi…
Browse files Browse the repository at this point in the history
…ts (in addition to new API)

Signed-off-by: Pauline Jean-Marie <[email protected]>
  • Loading branch information
Pauline Jean-Marie committed Nov 3, 2023
1 parent 1e2f559 commit fc8ae55
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 2 deletions.
19 changes: 17 additions & 2 deletions pypowsybl/voltage_initializer/impl/voltage_initializer.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,8 @@ def add_variable_two_windings_transformers(self, transformer_id_list: List[str])

def add_specific_low_voltage_limits(self, low_limits: List[Tuple[str, bool, float]]) -> None:
'''
Indicate to voltage initializer to override the network low voltages limits.
Indicate to voltage initializer to override the network low voltages limits,
limit can be given relative to former limit or absolute.
High limits can be given for the same voltage level ids using
:func:`~VoltageInitializerParameters.add_specific_high_voltage_limits`
but it is not necessary to give a high limit as long as each voltage level has its limits
Expand All @@ -81,7 +82,8 @@ def add_specific_low_voltage_limits(self, low_limits: List[Tuple[str, bool, floa

def add_specific_high_voltage_limits(self, high_limits: List[Tuple[str, bool, float]]) -> None:
'''
Indicate to voltage initializer to override the network high voltages limits.
Indicate to voltage initializer to override the network high voltages limits,
limit can be given relative to previous limit or absolute.
Low limits can be given for the same voltage level ids using
:func:`~VoltageInitializerParameters.add_specific_low_voltage_limits`
but it is not necessary to give a low limit as long as each voltage level has its limits
Expand All @@ -94,6 +96,19 @@ def add_specific_high_voltage_limits(self, high_limits: List[Tuple[str, bool, fl
for voltage_level_id, is_relative, limit in high_limits:
voltage_initializer_add_specific_high_voltage_limits(self._handle, voltage_level_id, is_relative, limit)

def add_specific_voltage_limits(self, limits: Dict[str, Tuple[float, float]]) -> None:
'''
Indicate to voltage initializer to override the network voltages limits.
Limits are given relative to previous limits.
Use this if voltage initializer cannot converge because of infeasibility.
Args:
limits: A dictionary keys are voltage ids, values are (lower limit, upper limit)
'''
for key in limits:
self.add_specific_low_voltage_limits([(key, True, limits[key][0])])
self.add_specific_high_voltage_limits([(key, True, limits[key][1])])

def add_algorithm_param(self, parameters_dict: Dict[str, str]) -> None:
'''
Add list of entries to VoltageInitializer. Danger zone as it tweaks the model directly.
Expand Down
2 changes: 2 additions & 0 deletions tests/test_voltage_initializer.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ def test_parameters():
params.add_variable_two_windings_transformers(["twt1", "twt2"])

params.add_algorithm_param({"foo": "bar", "bar": "bar2"})
params.add_specific_voltage_limits({"vl_id": (0.5, 1.2)})

params.add_specific_low_voltage_limits([("vl_id", True, 0.5)])
params.add_specific_high_voltage_limits([("vl_id", True, 1.2)])
params.add_specific_low_voltage_limits([("vl_id_2", False, 380)])
Expand Down

0 comments on commit fc8ae55

Please sign in to comment.