diff --git a/.circleci/config.yml b/.circleci/config.yml index f54f17919..6dca4b27b 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -3,27 +3,27 @@ version: 2.1 executors: grid2op-executor: docker: - - image: python:3.10-buster + - image: python:3.10 working_directory: /Grid2Op python37: docker: - - image: python:3.7-buster + - image: python:3.7 python38: docker: - - image: python:3.8-buster + - image: python:3.8 python39: docker: - - image: python:3.9-buster + - image: python:3.9 python310: docker: - - image: python:3.10-buster + - image: python:3.10 python311: docker: - - image: python:3.11-buster + - image: python:3.11 python312: docker: - - image: cimg/python:3.12.0 + - image: cimg/python:3.12 jobs: test: @@ -140,27 +140,27 @@ jobs: python -m pip install -U .[test] export _GRID2OP_FORCE_TEST=1 grid2op.testinstall - - run: - command: | - source venv_test/bin/activate - python -m pip install -U "numpy>=1.21,<1.22" - python -m pip install -U .[test] - export _GRID2OP_FORCE_TEST=1 - grid2op.testinstall - - run: - command: | - source venv_test/bin/activate - python -m pip install -U "numpy>=1.22,<1.23" - python -m pip install -U .[test] - export _GRID2OP_FORCE_TEST=1 - grid2op.testinstall - - run: - command: | - source venv_test/bin/activate - python -m pip install -U "numpy>=1.23,<1.24" - python -m pip install -U .[test] - export _GRID2OP_FORCE_TEST=1 - grid2op.testinstall + # - run: + # command: | + # source venv_test/bin/activate + # python -m pip install -U "numpy>=1.21,<1.22" + # python -m pip install -U .[test] + # export _GRID2OP_FORCE_TEST=1 + # grid2op.testinstall + # - run: + # command: | + # source venv_test/bin/activate + # python -m pip install -U "numpy>=1.22,<1.23" + # python -m pip install -U .[test] + # export _GRID2OP_FORCE_TEST=1 + # grid2op.testinstall + # - run: + # command: | + # source venv_test/bin/activate + # python -m pip install -U "numpy>=1.23,<1.24" + # python -m pip install -U .[test] + # export _GRID2OP_FORCE_TEST=1 + # grid2op.testinstall - run: command: | source venv_test/bin/activate @@ -187,53 +187,53 @@ jobs: python -m pip install -U pip setuptools wheel python -m pip install chronix2grid>="1.1.0.post1" python -m pip uninstall -y grid2op - - run: - command: | - source venv_test/bin/activate - python -m pip install -U numba - python -m pip install -U .[test] - - run: - command: | - source venv_test/bin/activate - python -m pip install -U "numpy>=1.20,<1.21" - python -m pip install -U .[test] - export _GRID2OP_FORCE_TEST=1 - grid2op.testinstall - - run: - command: | - source venv_test/bin/activate - python -m pip install -U "numpy>=1.21,<1.22" - python -m pip install -U .[test] - export _GRID2OP_FORCE_TEST=1 - grid2op.testinstall - - run: - command: | - source venv_test/bin/activate - python -m pip install -U "numpy>=1.22,<1.23" - python -m pip install -U .[test] - export _GRID2OP_FORCE_TEST=1 - grid2op.testinstall - - run: - command: | - source venv_test/bin/activate - python -m pip install -U "numpy>=1.23,<1.24" - python -m pip install -U .[test] - export _GRID2OP_FORCE_TEST=1 - grid2op.testinstall - - run: - command: | - source venv_test/bin/activate - python -m pip install -U "numpy>=1.24,<1.25" - python -m pip install -U .[test] - export _GRID2OP_FORCE_TEST=1 - grid2op.testinstall - - run: - command: | - source venv_test/bin/activate - python -m pip install -U "numpy>=1.25,<1.26" - python -m pip install -U .[test] - export _GRID2OP_FORCE_TEST=1 - grid2op.testinstall + # - run: + # command: | + # source venv_test/bin/activate + # python -m pip install -U numba + # python -m pip install -U .[test] + # - run: + # command: | + # source venv_test/bin/activate + # python -m pip install -U "numpy>=1.20,<1.21" + # python -m pip install -U .[test] + # export _GRID2OP_FORCE_TEST=1 + # grid2op.testinstall + # - run: + # command: | + # source venv_test/bin/activate + # python -m pip install -U "numpy>=1.21,<1.22" + # python -m pip install -U .[test] + # export _GRID2OP_FORCE_TEST=1 + # grid2op.testinstall + # - run: + # command: | + # source venv_test/bin/activate + # python -m pip install -U "numpy>=1.22,<1.23" + # python -m pip install -U .[test] + # export _GRID2OP_FORCE_TEST=1 + # grid2op.testinstall + # - run: + # command: | + # source venv_test/bin/activate + # python -m pip install -U "numpy>=1.23,<1.24" + # python -m pip install -U .[test] + # export _GRID2OP_FORCE_TEST=1 + # grid2op.testinstall + # - run: + # command: | + # source venv_test/bin/activate + # python -m pip install -U "numpy>=1.24,<1.25" + # python -m pip install -U .[test] + # export _GRID2OP_FORCE_TEST=1 + # grid2op.testinstall + # - run: + # command: | + # source venv_test/bin/activate + # python -m pip install -U "numpy>=1.25,<1.26" + # python -m pip install -U .[test] + # export _GRID2OP_FORCE_TEST=1 + # grid2op.testinstall - run: command: | source venv_test/bin/activate @@ -265,34 +265,34 @@ jobs: python -m pip install -U .[test] export _GRID2OP_FORCE_TEST=1 grid2op.testinstall - - run: - command: | - source venv_test/bin/activate - python -m pip install -U "numpy>=1.22,<1.23" - python -m pip install -U .[test] - export _GRID2OP_FORCE_TEST=1 - grid2op.testinstall - - run: - command: | - source venv_test/bin/activate - python -m pip install -U "numpy>=1.23,<1.24" - python -m pip install -U .[test] - export _GRID2OP_FORCE_TEST=1 - grid2op.testinstall - - run: - command: | - source venv_test/bin/activate - python -m pip install -U "numpy>=1.24,<1.25" - python -m pip install -U .[test] - export _GRID2OP_FORCE_TEST=1 - grid2op.testinstall - - run: - command: | - source venv_test/bin/activate - python -m pip install -U "numpy>=1.25,<1.26" - python -m pip install -U .[test] - export _GRID2OP_FORCE_TEST=1 - grid2op.testinstall + # - run: + # command: | + # source venv_test/bin/activate + # python -m pip install -U "numpy>=1.22,<1.23" + # python -m pip install -U .[test] + # export _GRID2OP_FORCE_TEST=1 + # grid2op.testinstall + # - run: + # command: | + # source venv_test/bin/activate + # python -m pip install -U "numpy>=1.23,<1.24" + # python -m pip install -U .[test] + # export _GRID2OP_FORCE_TEST=1 + # grid2op.testinstall + # - run: + # command: | + # source venv_test/bin/activate + # python -m pip install -U "numpy>=1.24,<1.25" + # python -m pip install -U .[test] + # export _GRID2OP_FORCE_TEST=1 + # grid2op.testinstall + # - run: + # command: | + # source venv_test/bin/activate + # python -m pip install -U "numpy>=1.25,<1.26" + # python -m pip install -U .[test] + # export _GRID2OP_FORCE_TEST=1 + # grid2op.testinstall - run: command: | source venv_test/bin/activate @@ -324,20 +324,20 @@ jobs: python -m pip install -U .[test] export _GRID2OP_FORCE_TEST=1 grid2op.testinstall - - run: - command: | - source venv_test/bin/activate - python -m pip install -U "numpy>=1.24,<1.25" - python -m pip install -U .[test] - export _GRID2OP_FORCE_TEST=1 - grid2op.testinstall - - run: - command: | - source venv_test/bin/activate - python -m pip install -U "numpy>=1.25,<1.26" - python -m pip install -U .[test] - export _GRID2OP_FORCE_TEST=1 - grid2op.testinstall + # - run: + # command: | + # source venv_test/bin/activate + # python -m pip install -U "numpy>=1.24,<1.25" + # python -m pip install -U .[test] + # export _GRID2OP_FORCE_TEST=1 + # grid2op.testinstall + # - run: + # command: | + # source venv_test/bin/activate + # python -m pip install -U "numpy>=1.25,<1.26" + # python -m pip install -U .[test] + # export _GRID2OP_FORCE_TEST=1 + # grid2op.testinstall - run: command: | source venv_test/bin/activate @@ -380,4 +380,4 @@ workflows: - install39 - install310 - install311 - # - install312 # failing because of dependencies of numba, torch etc. Tired of it so ignoring it ! + - install312 # failing because of dependencies of numba, torch etc. Tired of it so ignoring it ! diff --git a/.gitignore b/.gitignore index 2a03d9711..84e7e7bd5 100644 --- a/.gitignore +++ b/.gitignore @@ -397,6 +397,8 @@ grid2op/tests/test_failing_simulator.txt old_pyproject.toml pp_bug_gen_alone.py test_dunder.py +grid2op/tests/test_fail_ci.txt +saved_multiepisode_agent_36bus_DN_4/ # profiling files **.prof diff --git a/CHANGELOG.rst b/CHANGELOG.rst index f21dc67a6..f492ba4a1 100644 --- a/CHANGELOG.rst +++ b/CHANGELOG.rst @@ -32,6 +32,14 @@ Change Log - [???] properly model interconnecting powerlines +[1.9.8] - 20xx-yy-zz +---------------------- +- [IMPROVED] the CI speed: by not testing every possible numpy version but only most ancient and most recent +- [IMPROVED] Runner now test grid2op version 1.9.6 and 1.9.7 +- [IMPROVED] refacto `gridobj_cls._clear_class_attribute` and `gridobj_cls._clear_grid_dependant_class_attributes` +- [IMPROVED] the bahviour of the generic class `MakeBackend` used for the test suite. +- [IMPROVED] re introducing python 12 testing + [1.9.7] - 2023-12-01 ---------------------- - [BREAKING] removal of the `grid2op/Exceptions/PowerflowExceptions.py` file and move the diff --git a/docs/conf.py b/docs/conf.py index 18cee2d9a..b9cbbc67d 100644 --- a/docs/conf.py +++ b/docs/conf.py @@ -22,7 +22,7 @@ author = 'Benjamin Donnot' # The full version, including alpha/beta/rc tags -release = '1.9.7' +release = '1.9.8.dev0' version = '1.9' diff --git a/grid2op/Space/GridObjects.py b/grid2op/Space/GridObjects.py index 48439dca6..f14eb3a46 100644 --- a/grid2op/Space/GridObjects.py +++ b/grid2op/Space/GridObjects.py @@ -650,70 +650,8 @@ def tell_dim_alert(cls, dim_alerts): @classmethod def _clear_class_attribute(cls): - cls.glop_version = grid2op.__version__ - cls._PATH_ENV = None - - cls.SUB_COL = 0 - cls.LOA_COL = 1 - cls.GEN_COL = 2 - cls.LOR_COL = 3 - cls.LEX_COL = 4 - cls.STORAGE_COL = 5 - - cls.attr_list_vect = None - cls.attr_list_set = {} - cls.attr_list_json = [] - cls.attr_nan_list_set = set() - - # class been init - cls._IS_INIT = False - - # name of the objects - cls.env_name = "unknown" - cls.name_load = None - cls.name_gen = None - cls.name_line = None - cls.name_sub = None - cls.name_storage = None - - cls.n_gen = -1 - cls.n_load = -1 - cls.n_line = -1 - cls.n_sub = -1 - cls.n_storage = -1 - - cls.sub_info = None - cls.dim_topo = -1 - - # to which substation is connected each element - cls.load_to_subid = None - cls.gen_to_subid = None - cls.line_or_to_subid = None - cls.line_ex_to_subid = None - cls.storage_to_subid = None - - # which index has this element in the substation vector - cls.load_to_sub_pos = None - cls.gen_to_sub_pos = None - cls.line_or_to_sub_pos = None - cls.line_ex_to_sub_pos = None - cls.storage_to_sub_pos = None - - # which index has this element in the topology vector - cls.load_pos_topo_vect = None - cls.gen_pos_topo_vect = None - cls.line_or_pos_topo_vect = None - cls.line_ex_pos_topo_vect = None - cls.storage_pos_topo_vect = None - - # "convenient" way to retrieve information of the grid - cls.grid_objects_types = None - # to which substation each element of the topovect is connected - cls._topo_vect_to_sub = None - - # list of attribute to convert it from/to a vector - cls._vectorized = None - + cls.shunts_data_available = False + # for redispatching / unit commitment cls._li_attr_disp = [ "gen_type", @@ -744,56 +682,9 @@ def _clear_class_attribute(cls): float, bool, ] - - # redispatch data, not available in all environment - cls.redispatching_unit_commitment_availble = False - cls.gen_type = None - cls.gen_pmin = None - cls.gen_pmax = None - cls.gen_redispatchable = None - cls.gen_max_ramp_up = None - cls.gen_max_ramp_down = None - cls.gen_min_uptime = None - cls.gen_min_downtime = None - cls.gen_cost_per_MW = None # marginal cost (in currency / (power.step) and not in $/(MW.h) it would be $ / (MW.5mins) ) - cls.gen_startup_cost = None # start cost (in currency) - cls.gen_shutdown_cost = None # shutdown cost (in currency) - cls.gen_renewable = None - - # storage unit static data - cls.storage_type = None - cls.storage_Emax = None - cls.storage_Emin = None - cls.storage_max_p_prod = None - cls.storage_max_p_absorb = None - cls.storage_marginal_cost = None - cls.storage_loss = None - cls.storage_charging_efficiency = None - cls.storage_discharging_efficiency = None - - # grid layout - cls.grid_layout = None - - # shunt data, not available in every backend - cls.shunts_data_available = False - cls.n_shunt = None - cls.name_shunt = None - cls.shunt_to_subid = None - - # alarm / alert - cls.assistant_warning_type = None - # alarms - cls.dim_alarms = 0 - cls.alarms_area_names = [] - cls.alarms_lines_area = {} - cls.alarms_area_lines = [] - - # alerts - cls.dim_alerts = 0 - cls.alertable_line_names = [] - cls.alertable_line_ids = [] - + cls._clear_grid_dependant_class_attributes() + @classmethod def _clear_grid_dependant_class_attributes(cls): cls.glop_version = grid2op.__version__ @@ -856,10 +747,10 @@ def _clear_grid_dependant_class_attributes(cls): cls.grid_objects_types = None # to which substation each element of the topovect is connected cls._topo_vect_to_sub = None - + # list of attribute to convert it from/to a vector cls._vectorized = None - + # redispatch data, not available in all environment cls.redispatching_unit_commitment_availble = False cls.gen_type = None @@ -885,7 +776,15 @@ def _clear_grid_dependant_class_attributes(cls): cls.storage_loss = None cls.storage_charging_efficiency = None cls.storage_discharging_efficiency = None - + + # grid layout + cls.grid_layout = None + + # shunt data, not available in every backend + cls.n_shunt = None + cls.name_shunt = None + cls.shunt_to_subid = None + # alarm / alert cls.assistant_warning_type = None @@ -900,11 +799,6 @@ def _clear_grid_dependant_class_attributes(cls): cls.alertable_line_names = [] cls.alertable_line_ids = [] - # shunt data, not available in every backend - cls.n_shunt = None - cls.name_shunt = None - cls.shunt_to_subid = None - @classmethod def _update_value_set(cls): """ diff --git a/grid2op/__init__.py b/grid2op/__init__.py index 8597490cb..bd891c039 100644 --- a/grid2op/__init__.py +++ b/grid2op/__init__.py @@ -11,7 +11,7 @@ Grid2Op """ -__version__ = '1.9.7' +__version__ = '1.9.8.dev0' __all__ = [ "Action", diff --git a/grid2op/tests/BaseBackendTest.py b/grid2op/tests/BaseBackendTest.py index 9603e0839..ad24c2ca6 100644 --- a/grid2op/tests/BaseBackendTest.py +++ b/grid2op/tests/BaseBackendTest.py @@ -74,7 +74,7 @@ def get_path(self): def test_properNames(self): self.skip_if_needed() - backend = self.make_backend() + backend = self.make_backend_with_glue_code() path = self.get_path() with warnings.catch_warnings(): @@ -97,7 +97,7 @@ def get_casefile(self): return "test_case14.json" def test_load_file(self): - backend = self.make_backend() + backend = self.make_backend_with_glue_code() path_matpower = self.get_path() case_file = self.get_casefile() with warnings.catch_warnings(): @@ -191,7 +191,7 @@ def test_load_file(self): assert np.max(np.abs(q_bus.flatten())) <= self.tolvect def test_assert_grid_correct(self): - backend = self.make_backend() + backend = self.make_backend_with_glue_code() path_matpower = self.get_path() case_file = self.get_casefile() with warnings.catch_warnings(): @@ -212,7 +212,7 @@ def get_casefile(self): return "test_case14.json" def setUp(self): - self.backend = self.make_backend() + self.backend = self.make_backend_with_glue_code() self.path_matpower = self.get_path() self.case_file = self.get_casefile() with warnings.catch_warnings(): @@ -813,7 +813,7 @@ def get_casefile(self): return "test_case14.json" def setUp(self): - self.backend = self.make_backend() + self.backend = self.make_backend_with_glue_code() self.path_matpower = self.get_path() self.case_file = self.get_casefile() with warnings.catch_warnings(): @@ -1422,13 +1422,13 @@ def test_get_action_to_set_storage(self): env = grid2op.make( "educ_case14_storage", test=True, - backend=self.make_backend(), + backend=self.make_backend_with_glue_code(), _add_to_name=type(self).__name__ ) env2 = grid2op.make( "educ_case14_storage", test=True, - backend=self.make_backend(), + backend=self.make_backend_with_glue_code(), _add_to_name=type(self).__name__ ) obs, *_ = env.step(env.action_space({"set_storage": [-1.0, 1.0]})) @@ -1453,7 +1453,7 @@ def test_update_from_obs(self): env = grid2op.make( "rte_case14_realistic", test=True, - backend=self.make_backend(), + backend=self.make_backend_with_glue_code(), _add_to_name=type(self).__name__ ) @@ -1559,8 +1559,7 @@ def get_path(self): return PATH_DATA_TEST def setUp(self): - self.backend = self.make_backend(detailed_infos_for_cascading_failures=True) - type(self.backend)._clear_grid_dependant_class_attributes() + self.backend = self.make_backend_with_glue_code(detailed_infos_for_cascading_failures=True) self.path_matpower = self.get_path() self.case_file = self.get_casefile() with warnings.catch_warnings(): @@ -1885,12 +1884,11 @@ class BaseTestChangeBusAffectRightBus(MakeBackend): def test_set_bus(self): self.skip_if_needed() # print("test_set_bus") - backend = self.make_backend() - type(backend)._clear_grid_dependant_class_attributes() + backend = self.make_backend_with_glue_code() with warnings.catch_warnings(): warnings.filterwarnings("ignore") env = grid2op.make("rte_case14_realistic", test=True, backend=backend, - _add_to_name=type(self).__name__) + _add_to_name=type(self).__name__) env.reset() action = env.action_space({"set_bus": {"lines_or_id": [(17, 2)]}}) obs, reward, done, info = env.step(action) @@ -1901,8 +1899,7 @@ def test_set_bus(self): def test_change_bus(self): self.skip_if_needed() # print("test_change_bus") - backend = self.make_backend() - type(backend)._clear_grid_dependant_class_attributes() + backend = self.make_backend_with_glue_code() with warnings.catch_warnings(): warnings.filterwarnings("ignore") env = grid2op.make("rte_case14_realistic", test=True, backend=backend, @@ -1916,8 +1913,7 @@ def test_change_bus(self): def test_change_bustwice(self): self.skip_if_needed() # print("test_change_bustwice") - backend = self.make_backend() - type(backend)._clear_grid_dependant_class_attributes() + backend = self.make_backend_with_glue_code() with warnings.catch_warnings(): warnings.filterwarnings("ignore") env = grid2op.make("rte_case14_realistic", test=True, backend=backend, @@ -1938,8 +1934,7 @@ def test_change_bustwice(self): def test_isolate_load(self): self.skip_if_needed() # print("test_isolate_load") - backend = self.make_backend() - type(backend)._clear_grid_dependant_class_attributes() + backend = self.make_backend_with_glue_code() with warnings.catch_warnings(): warnings.filterwarnings("ignore") env = grid2op.make("rte_case14_realistic", test=True, backend=backend, @@ -1951,8 +1946,7 @@ def test_isolate_load(self): def test_reco_disco_bus(self): self.skip_if_needed() # print("test_reco_disco_bus") - backend = self.make_backend() - type(backend)._clear_grid_dependant_class_attributes() + backend = self.make_backend_with_glue_code() with warnings.catch_warnings(): warnings.filterwarnings("ignore") env_case1 = grid2op.make( @@ -1978,8 +1972,7 @@ def test_reco_disco_bus(self): def test_reco_disco_bus2(self): self.skip_if_needed() # print("test_reco_disco_bus2") - backend = self.make_backend() - type(backend)._clear_grid_dependant_class_attributes() + backend = self.make_backend_with_glue_code() with warnings.catch_warnings(): warnings.filterwarnings("ignore") env_case2 = grid2op.make( @@ -2005,8 +1998,7 @@ def test_reco_disco_bus2(self): def test_reco_disco_bus3(self): self.skip_if_needed() # print("test_reco_disco_bus3") - backend = self.make_backend() - type(backend)._clear_grid_dependant_class_attributes() + backend = self.make_backend_with_glue_code() with warnings.catch_warnings(): warnings.filterwarnings("ignore") env_case2 = grid2op.make( @@ -2030,8 +2022,7 @@ def test_reco_disco_bus3(self): def test_reco_disco_bus4(self): self.skip_if_needed() # print("test_reco_disco_bus4") - backend = self.make_backend() - type(backend)._clear_grid_dependant_class_attributes() + backend = self.make_backend_with_glue_code() with warnings.catch_warnings(): warnings.filterwarnings("ignore") env_case2 = grid2op.make( @@ -2055,8 +2046,7 @@ def test_reco_disco_bus4(self): def test_reco_disco_bus5(self): self.skip_if_needed() # print("test_reco_disco_bus5") - backend = self.make_backend() - type(backend)._clear_grid_dependant_class_attributes() + backend = self.make_backend_with_glue_code() with warnings.catch_warnings(): warnings.filterwarnings("ignore") env_case2 = grid2op.make( @@ -2078,7 +2068,7 @@ def test_reco_disco_bus5(self): class BaseTestShuntAction(MakeBackend): def test_shunt_ambiguous_id_incorrect(self): self.skip_if_needed() - backend = self.make_backend() + backend = self.make_backend_with_glue_code() with warnings.catch_warnings(): warnings.filterwarnings("ignore") with grid2op.make( @@ -2094,8 +2084,8 @@ def test_shunt_ambiguous_id_incorrect(self): def test_shunt_effect(self): self.skip_if_needed() - backend1 = self.make_backend() - backend2 = self.make_backend() + backend1 = self.make_backend_with_glue_code() + backend2 = self.make_backend_with_glue_code() with warnings.catch_warnings(): warnings.filterwarnings("ignore") env_ref = grid2op.make( @@ -2170,9 +2160,8 @@ def test_shunt_effect(self): class BaseTestResetEqualsLoadGrid(MakeBackend): def setUp(self): - backend1 = self.make_backend() - backend2 = self.make_backend() - type(backend1)._clear_grid_dependant_class_attributes() + backend1 = self.make_backend_with_glue_code() + backend2 = self.make_backend_with_glue_code() with warnings.catch_warnings(): warnings.filterwarnings("ignore") self.env1 = grid2op.make("rte_case5_example", test=True, backend=backend1, _add_to_name=type(self).__name__) @@ -2304,8 +2293,7 @@ def test_obs_from_same_chronic(self): def test_combined_changes(self): # Unlimited sub changes - backend = self.make_backend() - type(backend)._clear_grid_dependant_class_attributes() + backend = self.make_backend_with_glue_code() params = grid2op.Parameters.Parameters() params.MAX_SUB_CHANGED = 999 @@ -2376,8 +2364,7 @@ def aux_random_topos_act(self, env, n=128, r=2): class BaseTestVoltageOWhenDisco(MakeBackend): def test_this(self): self.skip_if_needed() - backend = self.make_backend() - type(backend)._clear_grid_dependant_class_attributes() + backend = self.make_backend_with_glue_code() with warnings.catch_warnings(): warnings.filterwarnings("ignore") with grid2op.make("rte_case14_realistic", test=True, backend=backend, _add_to_name=type(self).__name__) as env: @@ -2392,8 +2379,7 @@ def test_this(self): class BaseTestChangeBusSlack(MakeBackend): def test_change_slack_case14(self): self.skip_if_needed() - backend = self.make_backend() - type(backend)._clear_grid_dependant_class_attributes() + backend = self.make_backend_with_glue_code() with warnings.catch_warnings(): warnings.filterwarnings("ignore") env = grid2op.make("rte_case14_realistic", test=True, backend=backend, _add_to_name=type(self).__name__) @@ -2439,8 +2425,7 @@ def _aux_test_kirchoff(self): def test_there_are_storage(self): """test the backend properly loaded the storage units""" self.skip_if_needed() - backend = self.make_backend() - type(backend)._clear_grid_dependant_class_attributes() + backend = self.make_backend_with_glue_code() with warnings.catch_warnings(): warnings.filterwarnings("ignore") self.env = grid2op.make("educ_case14_storage", test=True, backend=backend, _add_to_name=type(self).__name__) @@ -2449,8 +2434,7 @@ def test_there_are_storage(self): def test_storage_action_mw(self): """test the actions are properly implemented in the backend""" self.skip_if_needed() - backend = self.make_backend() - type(backend)._clear_grid_dependant_class_attributes() + backend = self.make_backend_with_glue_code() with warnings.catch_warnings(): warnings.filterwarnings("ignore") self.env = grid2op.make("educ_case14_storage", test=True, backend=backend, _add_to_name=type(self).__name__) @@ -2520,8 +2504,7 @@ def test_storage_action_topo(self): param = Parameters() param.NB_TIMESTEP_COOLDOWN_SUB = 0 param.NB_TIMESTEP_COOLDOWN_LINE = 0 - backend = self.make_backend() - type(backend)._clear_grid_dependant_class_attributes() + backend = self.make_backend_with_glue_code() with warnings.catch_warnings(): warnings.filterwarnings("ignore") self.env = grid2op.make( @@ -2669,8 +2652,7 @@ class BaseIssuesTest(MakeBackend): def test_issue_125(self): # https://github.com/rte-france/Grid2Op/issues/125 self.skip_if_needed() - backend = self.make_backend() - type(backend)._clear_grid_dependant_class_attributes() + backend = self.make_backend_with_glue_code() with warnings.catch_warnings(): warnings.filterwarnings("ignore") env = grid2op.make("rte_case14_realistic", test=True, backend=backend, _add_to_name=type(self).__name__) @@ -2691,8 +2673,7 @@ def test_issue_125(self): def test_issue_134(self): self.skip_if_needed() - backend = self.make_backend() - type(backend)._clear_grid_dependant_class_attributes() + backend = self.make_backend_with_glue_code() param = Parameters() param.NB_TIMESTEP_COOLDOWN_LINE = 0 @@ -2769,8 +2750,7 @@ def test_issue_134(self): def test_issue_134_check_ambiguity(self): self.skip_if_needed() - backend = self.make_backend() - type(backend)._clear_grid_dependant_class_attributes() + backend = self.make_backend_with_glue_code() param = Parameters() param.MAX_LINE_STATUS_CHANGED = 9999 @@ -2799,8 +2779,7 @@ def test_issue_134_check_ambiguity(self): def test_issue_134_withcooldown_forrules(self): self.skip_if_needed() - backend = self.make_backend() - type(backend)._clear_grid_dependant_class_attributes() + backend = self.make_backend_with_glue_code() param = Parameters() param.NB_TIMESTEP_COOLDOWN_LINE = 20 @@ -2941,8 +2920,7 @@ def test_issue_134_withcooldown_forrules(self): def test_issue_copyenv(self): # https://github.com/BDonnot/lightsim2grid/issues/10 - backend = self.make_backend() - type(backend)._clear_grid_dependant_class_attributes() + backend = self.make_backend_with_glue_code() with warnings.catch_warnings(): warnings.filterwarnings("ignore") env1 = grid2op.make("rte_case14_realistic", test=True, backend=backend, _add_to_name=type(self).__name__) @@ -2954,8 +2932,7 @@ def test_issue_copyenv(self): class BaseStatusActions(MakeBackend): def _make_my_env(self): - backend = self.make_backend() - type(backend)._clear_grid_dependant_class_attributes() + backend = self.make_backend_with_glue_code() param = Parameters() param.NB_TIMESTEP_COOLDOWN_LINE = 0 param.NB_TIMESTEP_COOLDOWN_SUB = 0 diff --git a/grid2op/tests/BaseRedispTest.py b/grid2op/tests/BaseRedispTest.py index f12087dd4..b6a4b6567 100644 --- a/grid2op/tests/BaseRedispTest.py +++ b/grid2op/tests/BaseRedispTest.py @@ -33,7 +33,7 @@ def get_casefile(self): def setUp(self): super().setUp() # powergrid - self.backend = self.make_backend() + self.backend = self.make_backend_with_glue_code() self.path_matpower = self.get_path() self.case_file = self.get_casefile() @@ -374,7 +374,7 @@ def get_casefile(self): def setUp(self): super().setUp() # powergrid - self.backend = self.make_backend() + self.backend = self.make_backend_with_glue_code() self.path_matpower = self.get_path() self.case_file = self.get_casefile() @@ -476,7 +476,7 @@ class BaseTestRedispTooLowHigh(MakeBackend): # test bug reported in issues https://github.com/rte-france/Grid2Op/issues/44 def setUp(self) -> None: super().setUp() - backend = self.make_backend() + backend = self.make_backend_with_glue_code() with warnings.catch_warnings(): warnings.filterwarnings("ignore") self.env = grid2op.make("rte_case14_redisp", @@ -574,7 +574,7 @@ class BaseTestDispatchRampingIllegalETC(MakeBackend): def setUp(self): super().setUp() # powergrid - backend = self.make_backend() + backend = self.make_backend_with_glue_code() with warnings.catch_warnings(): warnings.filterwarnings("ignore") self.env = grid2op.make("rte_case14_test", test=True, backend=backend, @@ -842,7 +842,7 @@ class BaseTestLoadingAcceptAlmostZeroSumRedisp(MakeBackend): def setUp(self): super().setUp() # powergrid - backend = self.make_backend() + backend = self.make_backend_with_glue_code() with warnings.catch_warnings(): warnings.filterwarnings("ignore") self.env = grid2op.make("rte_case14_test", test=True, backend=backend, diff --git a/grid2op/tests/aaa_test_backend_interface.py b/grid2op/tests/aaa_test_backend_interface.py index 16d469b82..e45361b04 100644 --- a/grid2op/tests/aaa_test_backend_interface.py +++ b/grid2op/tests/aaa_test_backend_interface.py @@ -40,7 +40,7 @@ def aux_get_env_name(self): def aux_make_backend(self) -> Backend: """do not run nor modify ! (used for this test class only)""" - backend = self.make_backend() + backend = self.make_backend_with_glue_code() backend.load_grid(self.get_path(), self.get_casefile()) backend.load_redispacthing_data("tmp") # pretend there is no generator backend.load_storage_data(self.get_path()) @@ -52,7 +52,7 @@ def aux_make_backend(self) -> Backend: def test_00create_backend(self): """Tests the backend can be created (not integrated in a grid2op environment yet)""" self.skip_if_needed() - backend = self.make_backend() + backend = self.make_backend_with_glue_code() def test_01load_grid(self): """Tests the grid can be loaded (supposes that your backend can read the grid.json in educ_case14_storage)* diff --git a/grid2op/tests/helper_path_test.py b/grid2op/tests/helper_path_test.py index f1ad50281..683b65bd8 100644 --- a/grid2op/tests/helper_path_test.py +++ b/grid2op/tests/helper_path_test.py @@ -63,6 +63,13 @@ class MakeBackend(ABC, HelperTests): def make_backend(self, detailed_infos_for_cascading_failures=False) -> Backend: pass + def make_backend_with_glue_code(self, detailed_infos_for_cascading_failures=False, extra_name="") -> Backend: + Backend._clear_class_attribute() + bk = self.make_backend(detailed_infos_for_cascading_failures=detailed_infos_for_cascading_failures) + type(bk)._clear_grid_dependant_class_attributes() + type(bk).set_env_name(type(self).__name__ + extra_name) + return bk + def get_path(self) -> str: raise NotImplementedError( "This function should be implemented for the test suit you are developping" diff --git a/grid2op/tests/test_Runner.py b/grid2op/tests/test_Runner.py index d4324015f..1d8dcd233 100644 --- a/grid2op/tests/test_Runner.py +++ b/grid2op/tests/test_Runner.py @@ -505,6 +505,8 @@ def test_backward_compatibility(self): "1.9.3", "1.9.4", "1.9.5", + "1.9.6", + "1.9.7", ] curr_version = "test_version" assert ( diff --git a/setup.py b/setup.py index 5e4a176d0..68b3586f9 100644 --- a/setup.py +++ b/setup.py @@ -96,7 +96,11 @@ def my_test_suite(): if sys.version_info.minor == 12: # numba is not available for python 3.12 at the moment - pkgs["extras"]["test"] = [el for el in pkgs["extras"]["test"] if not ("numba" in el)] + pkgs["extras"]["test"] = [el for el in pkgs["extras"]["test"] if (not ("numba" in el) and + not ("gym" in el) and + not ('stable-baselines3' in el) + ) + ] setup(description='An gymnasium compatible environment to model sequential decision making for powersystems', long_description=long_description,