Skip to content

Commit

Permalink
fixing legacy lightsim2grid compat
Browse files Browse the repository at this point in the history
  • Loading branch information
BDonnot committed Jun 26, 2024
1 parent f0cc227 commit 58c09ad
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 2 deletions.
4 changes: 2 additions & 2 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ jobs:
command: |
source venv_test/bin/activate
python -m pip install -U pip setuptools wheel
python -m pip install -U lightsim2grid==0.5.3 gymnasium "numpy<1.22" "pandapower<2.14.9"
python -m pip install -U lightsim2grid==0.5.3 gymnasium "numpy<1.22"
- run:
command: |
source venv_test/bin/activate
Expand All @@ -205,7 +205,7 @@ jobs:
command: |
source venv_test/bin/activate
python -m pip install -U pip setuptools wheel
python -m pip install -U lightsim2grid==0.6.0 gymnasium
python -m pip install -U lightsim2grid==0.6.0 gymnasium "numpy<1.22"
- run:
command: |
source venv_test/bin/activate
Expand Down
21 changes: 21 additions & 0 deletions grid2op/Backend/pandaPowerBackend.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,17 @@

import pandapower as pp
import scipy
# check that pandapower does not introduce some
from packaging import version

import grid2op
from grid2op.dtypes import dt_int, dt_float, dt_bool
from grid2op.Action import BaseAction
from grid2op.Exceptions import BackendError
from grid2op.Backend.backend import Backend

MIN_LS_VERSION_VM_PU = version.parse("0.6.0")

try:
import numba
NUMBA_ = True
Expand Down Expand Up @@ -544,6 +548,23 @@ def load_grid(self,
self._in_service_storage_cold_id = int((self._grid.storage.columns == "in_service").nonzero()[0][0])
self.comp_time = 0.

# hack for backward compat with oldest lightsim2grid version
try:
import lightsim2grid
if version.parse(lightsim2grid.__version__) < MIN_LS_VERSION_VM_PU:
warnings.warn("You are using a really old version of lightsim2grid. Consider upgrading.")
if "_options" in self._grid and "init_vm_pu" in self._grid["_options"]:
try:
float(self._grid["_options"]["init_vm_pu"])
except ValueError as exc_:
# we delete it because lightsim2grid uses it
# to init its internal "GridModel" and did not check that
# this is a float until MIN_LS_VERSION_VM_PU
del self._grid["_options"]["init_vm_pu"]
except ImportError:
# lightsim2grid is not installed, so no risk to contaminate it
pass

def _aux_run_pf_init(self):
"""run a powerflow when the file is being loaded. This is called three times for each call to "load_grid" """
with warnings.catch_warnings():
Expand Down

0 comments on commit 58c09ad

Please sign in to comment.