Skip to content

Commit 58c09ad

Browse files
committed
fixing legacy lightsim2grid compat
1 parent f0cc227 commit 58c09ad

File tree

2 files changed

+23
-2
lines changed

2 files changed

+23
-2
lines changed

.circleci/config.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -178,7 +178,7 @@ jobs:
178178
command: |
179179
source venv_test/bin/activate
180180
python -m pip install -U pip setuptools wheel
181-
python -m pip install -U lightsim2grid==0.5.3 gymnasium "numpy<1.22" "pandapower<2.14.9"
181+
python -m pip install -U lightsim2grid==0.5.3 gymnasium "numpy<1.22"
182182
- run:
183183
command: |
184184
source venv_test/bin/activate
@@ -205,7 +205,7 @@ jobs:
205205
command: |
206206
source venv_test/bin/activate
207207
python -m pip install -U pip setuptools wheel
208-
python -m pip install -U lightsim2grid==0.6.0 gymnasium
208+
python -m pip install -U lightsim2grid==0.6.0 gymnasium "numpy<1.22"
209209
- run:
210210
command: |
211211
source venv_test/bin/activate

grid2op/Backend/pandaPowerBackend.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,17 @@
1717

1818
import pandapower as pp
1919
import scipy
20+
# check that pandapower does not introduce some
21+
from packaging import version
2022

2123
import grid2op
2224
from grid2op.dtypes import dt_int, dt_float, dt_bool
2325
from grid2op.Action import BaseAction
2426
from grid2op.Exceptions import BackendError
2527
from grid2op.Backend.backend import Backend
2628

29+
MIN_LS_VERSION_VM_PU = version.parse("0.6.0")
30+
2731
try:
2832
import numba
2933
NUMBA_ = True
@@ -544,6 +548,23 @@ def load_grid(self,
544548
self._in_service_storage_cold_id = int((self._grid.storage.columns == "in_service").nonzero()[0][0])
545549
self.comp_time = 0.
546550

551+
# hack for backward compat with oldest lightsim2grid version
552+
try:
553+
import lightsim2grid
554+
if version.parse(lightsim2grid.__version__) < MIN_LS_VERSION_VM_PU:
555+
warnings.warn("You are using a really old version of lightsim2grid. Consider upgrading.")
556+
if "_options" in self._grid and "init_vm_pu" in self._grid["_options"]:
557+
try:
558+
float(self._grid["_options"]["init_vm_pu"])
559+
except ValueError as exc_:
560+
# we delete it because lightsim2grid uses it
561+
# to init its internal "GridModel" and did not check that
562+
# this is a float until MIN_LS_VERSION_VM_PU
563+
del self._grid["_options"]["init_vm_pu"]
564+
except ImportError:
565+
# lightsim2grid is not installed, so no risk to contaminate it
566+
pass
567+
547568
def _aux_run_pf_init(self):
548569
"""run a powerflow when the file is being loaded. This is called three times for each call to "load_grid" """
549570
with warnings.catch_warnings():

0 commit comments

Comments
 (0)