Skip to content

Commit

Permalink
fix legacy tests
Browse files Browse the repository at this point in the history
  • Loading branch information
BDonnot committed Jul 26, 2024
1 parent ba5cfb9 commit d717513
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 3 deletions.
10 changes: 9 additions & 1 deletion .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,8 @@ jobs:
command: |
source venv_test/bin/activate
pip install "grid2op~=1.7.0"
sed -i -e 's/np.int)/np.int32)/g' venv_test/lib/python3.*/site-packages/grid2op/Backend/PandaPowerBackend.py
sed -i -e 's/np.bool/np.bool_/g' venv_test/lib/python3.*/site-packages/grid2op/dtypes.py
python -m unittest lightsim2grid/tests/test_compat_legacy_grid2op.py
- run:
name: legacy test (grid2op ~1.8)
Expand All @@ -159,6 +161,8 @@ jobs:
name: legacy test (grid2op ~1.9)
command: |
source venv_test/bin/activate
pip uninstall gym
pip install gymnasium
pip install "grid2op~=1.9.0"
python -m unittest lightsim2grid/tests/test_compat_legacy_grid2op.py
- run:
Expand All @@ -171,6 +175,8 @@ jobs:
name: legacy test (grid2op 0.9.1.post1 - l2rpn wcci 2020)
command: |
source venv_test/bin/activate
pip uninstall gymnasium
pip install gym
pip install grid2op==0.9.1.post1
sed -i -e 's/np.int)/np.int32)/g' venv_test/lib/python3.*/site-packages/grid2op/Backend/PandaPowerBackend.py
sed -i -e 's/np.bool/np.bool_/g' venv_test/lib/python3.*/site-packages/grid2op/dtypes.py
Expand Down Expand Up @@ -199,7 +205,9 @@ jobs:
name: legacy test (grid2op 1.9.0 - l2rpn Delft 2023)
command: |
source venv_test/bin/activate
ppip install grid2op==1.9.0
pip uninstall gym
pip install gymnasium
pip install grid2op==1.9.0
python -m unittest lightsim2grid/tests/test_compat_legacy_grid2op.py
- run:
name: legacy test (grid2op 1.9.1 - l2rpn IDF 2023)
Expand Down
2 changes: 2 additions & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,8 @@ gridmodel.get_Bf() gridmodel.get_Bf_solver()
- [FIXED] basic backward compatibility is ensured and tested for grid2op >= 0.9.1.post1
Not all features are tested and only 1.x versions are tested
(ie 1.1 or 1.2 but not 1.2.1, 1.2.2, 1.2.3 etc.)
- [FIXED] a bug when using `LightSimBackend` with some old (but not too old) grid2op
versions.
- [ADDED] it is now possible to deactivate the support for shunts by
subclassing the LightSimBackend class and setting the `shunts_data_available`
to `False`
Expand Down
28 changes: 26 additions & 2 deletions lightsim2grid/tests/test_compat_legacy_grid2op.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,26 @@
except ImportError as exc_:
print(exc_)
GYM_AVAIL = False

try:
import gymnasium
GYMANSIUM_AVAIL = True
except ImportError:
GYMANSIUM_AVAIL = False

try:
import gym
GYM_AVAIL = True
except ImportError:
GYM_AVAIL = False


from lightsim2grid import LightSimBackend


GRID2OP_VER_FIXED_REWARD = version.parse("1.5.0")
GRID2OP_VER_NEW_GYM_API = version.parse("1.8.0")


class TestEnvironmentBasic(unittest.TestCase):
def setUp(self) -> None:
Expand Down Expand Up @@ -163,16 +178,25 @@ def test_runner(self):
class TestBasicEnvironmentGym(unittest.TestCase):
def setUp(self) -> None:
if not GYM_AVAIL:
self.skipTest("gym is not installed (gymnasium did not exist in 1.6.4)")
self.skipTest("gym is not installed (no gym compat before 1.3.0)")
TestEnvironmentBasic.setUp(self)
self.new_gym_api = False
if GYMANSIUM_AVAIL:
self.new_gym_api = True
if version.parse(grid2op.__version__) >= GRID2OP_VER_NEW_GYM_API:
self.new_gym_api = True


def tearDown(self) -> None:
self.env.close()
return super().tearDown()

def _aux_run_envs(self, act, env_gym):
for i in range(10):
obs_in, reward, done, info = env_gym.step(act)
if self.new_gym_api:
obs_in, reward, done, truncated, info = env_gym.step(act)
else:
obs_in, reward, done, info = env_gym.step(act)
if i < 3:
assert obs_in["timestep_overflow"][self.line_id] == i + 1, f"error for step {i}: {obs_in['timestep_overflow'][self.line_id]}"
else:
Expand Down

0 comments on commit d717513

Please sign in to comment.