Skip to content

Commit

Permalink
Debug: Try to fix Test_Issue_125
Browse files Browse the repository at this point in the history
Signed-off-by: Xavier Weiss <[email protected]>
  • Loading branch information
DEUCE1957 committed Nov 8, 2024
1 parent 2f8f954 commit 0971320
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 6 deletions.
6 changes: 4 additions & 2 deletions grid2op/Backend/backend.py
Original file line number Diff line number Diff line change
Expand Up @@ -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__}"
Expand Down
5 changes: 2 additions & 3 deletions grid2op/Converter/BackendConverter.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,15 +95,13 @@ def __init__(
use_target_backend_name=False,
kwargs_target_backend=None,
kwargs_source_backend=None,
allow_detachment:bool=False,
):
Backend.__init__(
self,
detailed_infos_for_cascading_failures=detailed_infos_for_cascading_failures,
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:
Expand Down Expand Up @@ -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
Expand Down
4 changes: 3 additions & 1 deletion grid2op/tests/helper_path_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down

0 comments on commit 0971320

Please sign in to comment.