From 097132061246f4fd88c8c7fe73483cfbfb244231 Mon Sep 17 00:00:00 2001 From: Xavier Weiss Date: Fri, 8 Nov 2024 11:46:10 +0100 Subject: [PATCH] Debug: Try to fix Test_Issue_125 Signed-off-by: Xavier Weiss --- grid2op/Backend/backend.py | 6 ++++-- grid2op/Converter/BackendConverter.py | 5 ++--- grid2op/tests/helper_path_test.py | 4 +++- 3 files changed, 9 insertions(+), 6 deletions(-) diff --git a/grid2op/Backend/backend.py b/grid2op/Backend/backend.py index 2b21d61b..b38becc1 100644 --- a/grid2op/Backend/backend.py +++ b/grid2op/Backend/backend.py @@ -1083,8 +1083,10 @@ def _runpf_with_diverging_exception(self, is_dc : bool) -> Optional[Exception]: try: # Check if loads/gens have been detached and if this is allowed, otherwise raise an error # .. versionadded:: 1.11.0 - topo_vect = self._get_topo_vect() - + if hasattr(self, "_get_topo_vect"): + topo_vect = self._get_topo_vect() + else: + topo_vect = self.get_topo_vect() load_buses = topo_vect[self.load_pos_topo_vect] if not self._allow_detachment and (load_buses == -1).any(): raise Grid2OpException(f"One or more loads were detached before powerflow in Backend {type(self).__name__}" diff --git a/grid2op/Converter/BackendConverter.py b/grid2op/Converter/BackendConverter.py index 84bed15c..38178908 100644 --- a/grid2op/Converter/BackendConverter.py +++ b/grid2op/Converter/BackendConverter.py @@ -95,7 +95,6 @@ def __init__( use_target_backend_name=False, kwargs_target_backend=None, kwargs_source_backend=None, - allow_detachment:bool=False, ): Backend.__init__( self, @@ -103,7 +102,6 @@ def __init__( use_target_backend_name=use_target_backend_name, kwargs_target_backend=kwargs_target_backend, kwargs_source_backend=kwargs_source_backend, - allow_detachment=allow_detachment, ) difcf = detailed_infos_for_cascading_failures if kwargs_source_backend is None: @@ -167,10 +165,11 @@ def load_grid(self, path=None, filename=None): # register the "n_busbar_per_sub" (set for the backend class) # TODO in case source supports the "more than 2" feature but not target # it's unclear how I can "reload" the grid... - from grid2op.Space import DEFAULT_N_BUSBAR_PER_SUB, DEFAULT_ALLOW_DETACHMENT + from grid2op.Space import DEFAULT_N_BUSBAR_PER_SUB type(self.source_backend).set_n_busbar_per_sub(DEFAULT_N_BUSBAR_PER_SUB) type(self.target_backend).set_n_busbar_per_sub(DEFAULT_N_BUSBAR_PER_SUB) self.cannot_handle_more_than_2_busbar() + self.cannot_handle_detachment() self.source_backend.load_grid(path, filename) # and now i load the target backend diff --git a/grid2op/tests/helper_path_test.py b/grid2op/tests/helper_path_test.py index cd72b9ef..39d8439a 100644 --- a/grid2op/tests/helper_path_test.py +++ b/grid2op/tests/helper_path_test.py @@ -67,12 +67,14 @@ class MakeBackend(ABC, HelperTests): def make_backend(self, detailed_infos_for_cascading_failures=False) -> Backend: pass - def make_backend_with_glue_code(self, detailed_infos_for_cascading_failures=False, extra_name="", n_busbar=2) -> Backend: + def make_backend_with_glue_code(self, detailed_infos_for_cascading_failures=False, extra_name="", + n_busbar=2, allow_detachment=False) -> Backend: Backend._clear_class_attribute() bk = self.make_backend(detailed_infos_for_cascading_failures=detailed_infos_for_cascading_failures) type(bk)._clear_grid_dependant_class_attributes() type(bk).set_env_name(type(self).__name__ + extra_name) type(bk).set_n_busbar_per_sub(n_busbar) + type(bk)._allow_detachment = allow_detachment return bk def get_path(self) -> str: