diff --git a/.circleci/config.yml b/.circleci/config.yml index 064a5e0..c5503e0 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -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) @@ -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: @@ -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 @@ -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) diff --git a/CHANGELOG.rst b/CHANGELOG.rst index 7250342..45809a2 100644 --- a/CHANGELOG.rst +++ b/CHANGELOG.rst @@ -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` diff --git a/lightsim2grid/tests/test_compat_legacy_grid2op.py b/lightsim2grid/tests/test_compat_legacy_grid2op.py index 0cd3912..98d7ad5 100644 --- a/lightsim2grid/tests/test_compat_legacy_grid2op.py +++ b/lightsim2grid/tests/test_compat_legacy_grid2op.py @@ -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: @@ -163,8 +178,14 @@ 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() @@ -172,7 +193,10 @@ def tearDown(self) -> None: 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: