Skip to content

Commit 7cfb4b5

Browse files
committed
update backend for grid2op v1.11.0 dev
1 parent 6bc1bf0 commit 7cfb4b5

File tree

3 files changed

+31
-43
lines changed

3 files changed

+31
-43
lines changed

.github/workflows/ci.yml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,12 @@ jobs:
151151
# Pkg.PackageSpec(;url="https://github.com/loriab/PandaModels.jl", rev="update_pm")
152152
#])'
153153
154+
- name: Special Config - Dev grid2op
155+
if: matrix.cfg.label != 'script'
156+
run: |
157+
# both "conda" and "installer" lanes use pypi g2o
158+
python -m pip install 'git+https://github.com/Grid2op/grid2op.git@dev_1.11.0' --no-deps
159+
154160
- name: Install PandaModelsBackend
155161
if: matrix.cfg.label != 'script'
156162
run: |

pandamodelsbackend/pandaModelsBackend.py

Lines changed: 21 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -56,36 +56,14 @@ def _aux_runpf_pp(self, is_dc: bool):
5656
warnings.filterwarnings("ignore", category=RuntimeWarning)
5757
warnings.filterwarnings("ignore", category=DeprecationWarning)
5858
self._pf_init = "dc"
59-
# nb_bus = self.get_nb_active_bus()
60-
# if self._nb_bus_before is None:
61-
# self._pf_init = "dc"
62-
# elif nb_bus == self._nb_bus_before:
63-
# self._pf_init = "results"
64-
# else:
65-
# self._pf_init = "auto"
66-
67-
if (~self._grid.load["in_service"]).any():
68-
# TODO see if there is a better way here -> do not handle this here, but rather in Backend._next_grid_state
69-
raise pp.powerflow.LoadflowNotConverged("Disconnected load: for now grid2op cannot handle properly"
70-
" disconnected load. If you want to disconnect one, say it"
71-
" consumes 0. instead. Please check loads: "
72-
f"{(~self._grid.load['in_service'].values).nonzero()[0]}"
73-
)
74-
if (~self._grid.gen["in_service"]).any():
75-
# TODO see if there is a better way here -> do not handle this here, but rather in Backend._next_grid_state
76-
raise pp.powerflow.LoadflowNotConverged("Disconnected gen: for now grid2op cannot handle properly"
77-
" disconnected generators. If you want to disconnect one, say it"
78-
" produces 0. instead. Please check generators: "
79-
f"{(~self._grid.gen['in_service'].values).nonzero()[0]}"
80-
)
8159
try:
8260
if is_dc:
83-
#TODO: Call pm function here too
61+
# TODO: Could call PwMd function here too, but Ben says DC will be same
8462
pp.rundcpp(self._grid, check_connectivity=True, init="flat")
8563

8664
# if I put check_connectivity=False then the test AAATestBackendAPI.test_22_islanded_grid_make_divergence
8765
# does not pass
88-
66+
8967
# if dc i start normally next time i call an ac powerflow
9068
self._nb_bus_before = None
9169
else:
@@ -130,14 +108,20 @@ def runpf(self, is_dc : bool=False) -> Tuple[bool, Union[Exception, None]]:
130108
in case of "do nothing" action applied.
131109
"""
132110
try:
111+
# as pandapower does not modify the topology or the status of
112+
# powerline, then we can compute the topology (and the line status)
113+
# at the beginning
114+
# This is also interesting in case of divergence :-)
115+
self._get_line_status()
116+
self._get_topo_vect()
133117
self._aux_runpf_pp(is_dc)
134-
cls = type(self)
118+
cls = type(self)
135119
# if a connected bus has a no voltage, it's a divergence (grid was not connected)
136120
if self._grid.res_bus.loc[self._grid.bus["in_service"]]["va_degree"].isnull().any():
137121
buses_ko = self._grid.res_bus.loc[self._grid.bus["in_service"]]["va_degree"].isnull()
138122
buses_ko = buses_ko.values.nonzero()[0]
139123
raise pp.powerflow.LoadflowNotConverged(f"Isolated bus, check buses {buses_ko} with `env.backend._grid.res_bus.iloc[{buses_ko}, :]`")
140-
124+
141125
(
142126
self.prod_p[:],
143127
self.prod_q[:],
@@ -150,13 +134,8 @@ def runpf(self, is_dc : bool=False) -> Tuple[bool, Union[Exception, None]]:
150134
self.load_v[:],
151135
self.load_theta[:],
152136
) = self._loads_info()
153-
154-
if not is_dc:
155-
if not np.isfinite(self.load_v).all():
156-
# TODO see if there is a better way here
157-
# some loads are disconnected: it's a game over case!
158-
raise pp.powerflow.LoadflowNotConverged(f"Isolated load: check loads {np.isfinite(self.load_v).nonzero()[0]}")
159-
else:
137+
138+
if is_dc:
160139
# fix voltages magnitude that are always "nan" for dc case
161140
# self._grid.res_bus["vm_pu"] is always nan when computed in DC
162141
self.load_v[:] = self.load_pu_to_kv # TODO
@@ -175,8 +154,8 @@ def runpf(self, is_dc : bool=False) -> Tuple[bool, Union[Exception, None]]:
175154
):
176155
self.load_v[l_id] = self.prod_v[g_id]
177156
break
178-
179-
self.line_status[:] = self._get_line_status()
157+
self.load_v[~self._grid.load["in_service"]] = 0.
158+
180159
# I retrieve the data once for the flows, so has to not re read multiple dataFrame
181160
self.p_or[:] = self._aux_get_line_info("p_from_mw", "p_hv_mw")
182161
self.q_or[:] = self._aux_get_line_info("q_from_mvar", "q_hv_mvar")
@@ -222,19 +201,21 @@ def runpf(self, is_dc : bool=False) -> Tuple[bool, Union[Exception, None]]:
222201
self.storage_theta[:],
223202
) = self._storages_info()
224203
deact_storage = ~np.isfinite(self.storage_v)
225-
if (np.abs(self.storage_p[deact_storage]) > self.tol).any():
226-
raise pp.powerflow.LoadflowNotConverged(
227-
"Isolated storage set to absorb / produce something"
228-
)
229204
self.storage_p[deact_storage] = 0.0
230205
self.storage_q[deact_storage] = 0.0
231206
self.storage_v[deact_storage] = 0.0
232207
self._grid.storage["in_service"].values[deact_storage] = False
233208

234-
self._topo_vect[:] = self._get_topo_vect()
235209
if getattr(self._grid, 'converged', False) and getattr(self._grid, 'OPF_converged', False):
236210
raise pp.powerflow.LoadflowNotConverged("Divergence without specific reason (self._grid.converged and self._grid.OPF_converged both are False)")
237211
self.div_exception = None
212+
if is_dc:
213+
# pandapower apparently does not set 0 for q in DC...
214+
self.prod_q[:] = 0.
215+
self.load_q[:] = 0.
216+
self.storage_q[:] = 0.
217+
self.q_or[:] = 0.
218+
self.q_ex[:] = 0.
238219
return True, None
239220

240221
except pp.powerflow.LoadflowNotConverged as exc_:

pandamodelsbackend/tests/test_backend_api.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import unittest
2+
from grid2op.Space import DEFAULT_ALLOW_DETACHMENT
23
from grid2op.tests.aaa_test_backend_interface import AAATestBackendAPI
34

45
from pandamodelsbackend import PandaModelsBackend
@@ -9,7 +10,7 @@ def make_backend(self, detailed_infos_for_cascading_failures=False):
910

1011
# The following tests are skipped as these tests may not relevant for the PandaModelsBackend backend
1112
# in the PandaModelsBackend as PandaPower runnpp doesn't converge but runpm does
12-
def test_17_isolated_gen_stops_computation(self):
13+
def test_17_isolated_gen_stops_computation(self, allow_detachment=DEFAULT_ALLOW_DETACHMENT):
1314
pass
1415

1516
def test_22_islanded_grid_stops_computation(self):
@@ -20,10 +21,10 @@ def test_12_modify_gen_pf_getter(self):
2021

2122
# The following tests are skipped as these tests lead to error in Julia
2223
# probably a bug in PandaPower or PandaModels that leads to this error
23-
def test_16_isolated_load_stops_computation(self):
24+
def test_16_isolated_load_stops_computation(self, allow_detachment=DEFAULT_ALLOW_DETACHMENT):
2425
pass
2526

26-
def test_19_isolated_storage_stops_computation(self):
27+
def test_19_isolated_storage_stops_computation(self, allow_detachment=DEFAULT_ALLOW_DETACHMENT):
2728
pass
2829

2930
if __name__ == "__main__":

0 commit comments

Comments
 (0)