From fc8ae5502ae38d7a7f67dc1d0fa048aa67739f77 Mon Sep 17 00:00:00 2001 From: Pauline Jean-Marie Date: Fri, 3 Nov 2023 12:06:37 +0100 Subject: [PATCH] For compatibility reason, re-add former API add_specific_voltage_limits (in addition to new API) Signed-off-by: Pauline Jean-Marie --- .../impl/voltage_initializer.py | 19 +++++++++++++++++-- tests/test_voltage_initializer.py | 2 ++ 2 files changed, 19 insertions(+), 2 deletions(-) diff --git a/pypowsybl/voltage_initializer/impl/voltage_initializer.py b/pypowsybl/voltage_initializer/impl/voltage_initializer.py index a8251acd6f..28d6a30881 100644 --- a/pypowsybl/voltage_initializer/impl/voltage_initializer.py +++ b/pypowsybl/voltage_initializer/impl/voltage_initializer.py @@ -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 @@ -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 @@ -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. diff --git a/tests/test_voltage_initializer.py b/tests/test_voltage_initializer.py index 75c6f4366d..a610233f48 100644 --- a/tests/test_voltage_initializer.py +++ b/tests/test_voltage_initializer.py @@ -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)])