From f2837b304c551d35dccbce3abbadaab1721c5466 Mon Sep 17 00:00:00 2001 From: DONNOT Benjamin Date: Thu, 14 Mar 2024 09:50:34 +0100 Subject: [PATCH 1/7] Backward compat with improved .copy() method --- docs/conf.py | 6 +- lightsim2grid/__init__.py | 2 +- lightsim2grid/lightSimBackend.py | 140 ++++++++++++++++++------------- setup.py | 2 +- 4 files changed, 87 insertions(+), 63 deletions(-) diff --git a/docs/conf.py b/docs/conf.py index 8438a0a..796a133 100644 --- a/docs/conf.py +++ b/docs/conf.py @@ -22,11 +22,7 @@ author = 'Benjamin DONNOT' # The full version, including alpha/beta/rc tags -<<<<<<< HEAD -release = "0.7.5.dev0" -======= -release = "0.7.4" ->>>>>>> master +release = "0.7.5.dev0.post1" version = '0.7' # -- General configuration --------------------------------------------------- diff --git a/lightsim2grid/__init__.py b/lightsim2grid/__init__.py index 145b6f3..abc421d 100644 --- a/lightsim2grid/__init__.py +++ b/lightsim2grid/__init__.py @@ -5,7 +5,7 @@ # you can obtain one at http://mozilla.org/MPL/2.0/. # SPDX-License-Identifier: MPL-2.0 # This file is part of LightSim2grid, LightSim2grid implements a c++ backend targeting the Grid2Op platform. -__version__ = "0.7.5" +__version__ = "0.7.5.post1" __all__ = ["newtonpf", "SolverType", "ErrorType", "solver"] diff --git a/lightsim2grid/lightSimBackend.py b/lightsim2grid/lightSimBackend.py index 7a0ce86..522a998 100644 --- a/lightsim2grid/lightSimBackend.py +++ b/lightsim2grid/lightSimBackend.py @@ -1,4 +1,4 @@ -# Copyright (c) 2020, RTE (https://www.rte-france.com) +# Copyright (c) 2020-2024, RTE (https://www.rte-france.com) # See AUTHORS.txt # This Source Code Form is subject to the terms of the Mozilla Public License, version 2.0. # If a copy of the Mozilla Public License, version 2.0 was not distributed with this file, @@ -40,22 +40,29 @@ def __init__(self, dist_slack_non_renew: bool=False, # distribute the slack on non renewable turned on (and with P>0) generators use_static_gen: bool=False, # add the static generators as generator gri2dop side ): - try: - # for grid2Op >= 1.7.1 - Backend.__init__(self, - detailed_infos_for_cascading_failures=detailed_infos_for_cascading_failures, - can_be_copied=can_be_copied, - solver_type=solver_type, - max_iter=max_iter, - tol=tol, - turned_off_pv=turned_off_pv, - dist_slack_non_renew=dist_slack_non_renew, - use_static_gen=use_static_gen) - except TypeError as exc_: - warnings.warn("Please use grid2op >= 1.7.1: with older grid2op versions, " - "you cannot set max_iter, tol nor solver_type arguments.") - Backend.__init__(self, - detailed_infos_for_cascading_failures=detailed_infos_for_cascading_failures) + self.max_it = max_iter + self.tol = tol # tolerance for the solver + self._check_suitable_solver_type(solver_type, check_in_avail_solver=False) + self.__current_solver_type = solver_type + + # does the "turned off" generators (including when p=0) + # are pv buses + self._turned_off_pv = turned_off_pv + + # distributed slack, on non renewable gen with P > 0 + self._dist_slack_non_renew = dist_slack_non_renew + + # add the static gen to the list of controlable gen in grid2Op + self._use_static_gen = use_static_gen # TODO implement it + + self._aux_init_super(detailed_infos_for_cascading_failures, + can_be_copied, + solver_type, + max_iter, + tol, + turned_off_pv, + dist_slack_non_renew, + use_static_gen) # lazy loading because it crashes... from lightsim2grid._utils import _DoNotUseAnywherePandaPowerBackend @@ -64,7 +71,9 @@ def __init__(self, if not self.__has_storage: warnings.warn("Please upgrade your grid2Op to >= 1.5.0. You are using a backward compatibility " "feature that will be removed in further lightsim2grid version.") - + + self.shunts_data_available = True # needs to be self and not type(self) here + self.nb_bus_total = None self.initdc = True # does not really hurt computation time self.__nb_powerline = None @@ -92,8 +101,6 @@ def __init__(self, self.init_pp_backend = _DoNotUseAnywherePandaPowerBackend() self.V = None - self.max_it = max_iter - self.tol = tol # tolerance for the solver self.prod_pu_to_kv = None self.load_pu_to_kv = None @@ -145,12 +152,20 @@ def __init__(self, # available solver in lightsim self.available_solvers = [] - self.comp_time = 0. # computation time of just the powerflow + + # computation time of just the powerflow (when the grid is formatted + # by the gridmodel already) + # it takes only into account the time spend in the powerflow algorithm + self.comp_time = 0. + + # computation time of the powerflow + # it takes into account everything in the gridmodel, including the mapping + # to the solver, building of Ybus and Sbus AND the time to solve the powerflow + self.timer_gridmodel_xx_pf = 0. + self._timer_postproc = 0. self._timer_preproc = 0. self._timer_solver = 0. - self._check_suitable_solver_type(solver_type, check_in_avail_solver=False) - self.__current_solver_type = solver_type # hack for the storage unit: # in grid2op, for simplicity, I suppose that if a storage is alone on a busbar, and @@ -162,33 +177,34 @@ def __init__(self, # TODO and should rather be handled in pandapower backend # backend SHOULD not do these kind of stuff self._idx_hack_storage = [] - - # does the "turned off" generators (including when p=0) - # are pv buses - self._turned_off_pv = turned_off_pv - - # distributed slack, on non renewable gen with P > 0 - self._dist_slack_non_renew = dist_slack_non_renew - - # add the static gen to the list of controlable gen in grid2Op - self._use_static_gen = use_static_gen # TODO implement it - - # storage data for this object (otherwise it's in the class) - self.n_storage = None - self.storage_to_subid = None - self.storage_pu_to_kv = None - self.name_storage = None - self.storage_to_sub_pos = None - self.storage_type = None - self.storage_Emin = None - self.storage_Emax = None - self.storage_max_p_prod = None - self.storage_max_p_absorb = None - self.storage_marginal_cost = None - self.storage_loss = None - self.storage_discharging_efficiency = None - self.storage_charging_efficiency = None + def _aux_init_super(self, + detailed_infos_for_cascading_failures, + can_be_copied, + solver_type, + max_iter, + tol, + turned_off_pv, + dist_slack_non_renew, + use_static_gen): + try: + # for grid2Op >= 1.7.1 + Backend.__init__(self, + detailed_infos_for_cascading_failures=detailed_infos_for_cascading_failures, + can_be_copied=can_be_copied, + solver_type=solver_type, + max_iter=max_iter, + tol=tol, + turned_off_pv=turned_off_pv, + dist_slack_non_renew=dist_slack_non_renew, + use_static_gen=use_static_gen + ) + except TypeError as exc_: + warnings.warn("Please use grid2op >= 1.7.1: with older grid2op versions, " + "you cannot set max_iter, tol nor solver_type arguments.") + Backend.__init__(self, + detailed_infos_for_cascading_failures=detailed_infos_for_cascading_failures) + def turnedoff_no_pv(self): self._turned_off_pv = False self._grid.turnedoff_no_pv() @@ -909,25 +925,37 @@ def copy(self): #################### # res = copy.deepcopy(self) # super slow res = type(self).__new__(type(self)) + # make sure to init the "base class" + # in particular with "new" attributes in future grid2op Backend + res._aux_init_super(self.detailed_infos_for_cascading_failures, + self._can_be_copied, + self.__current_solver_type, + self.max_it, + self.tol, + self._turned_off_pv, + self._dist_slack_non_renew, + self._use_static_gen) + res.comp_time = self.comp_time + res.timer_gridmodel_xx_pf = self.timer_gridmodel_xx_pf # copy the regular attribute res.__has_storage = self.__has_storage - res.__current_solver_type = self.__current_solver_type + res.__current_solver_type = self.__current_solver_type # forced here because of special `__` res.__nb_powerline = self.__nb_powerline res.__nb_bus_before = self.__nb_bus_before - res._can_be_copied = self._can_be_copied res.cst_1 = dt_float(1.0) - li_regular_attr = ["detailed_infos_for_cascading_failures", "comp_time", "can_output_theta", "_is_loaded", + li_regular_attr = ["comp_time", "can_output_theta", "_is_loaded", "nb_bus_total", "initdc", - "_big_topo_to_obj", "max_it", "tol", "dim_topo", + "_big_topo_to_obj", "dim_topo", "_idx_hack_storage", "_timer_preproc", "_timer_postproc", "_timer_solver", - "_my_kwargs", - "_turned_off_pv", "_dist_slack_non_renew" + "supported_grid_format", + "max_it", "tol", "_turned_off_pv", "_dist_slack_non_renew", + "_use_static_gen" ] for attr_nm in li_regular_attr: if hasattr(self, attr_nm): - # this test is needed for backward compatibility with other grid2op version + # this test is needed for backward compatibility with older grid2op version setattr(res, attr_nm, copy.deepcopy(getattr(self, attr_nm))) # copy the numpy array diff --git a/setup.py b/setup.py index b28c51d..154f7ed 100644 --- a/setup.py +++ b/setup.py @@ -14,7 +14,7 @@ from pybind11.setup_helpers import Pybind11Extension, build_ext -__version__ = "0.7.5" +__version__ = "0.7.5.post1" KLU_SOLVER_AVAILABLE = False # Try to link against SuiteSparse (if available) From 1a231f3219ddc9f120b3c2d8b8ca74b29e26a30c Mon Sep 17 00:00:00 2001 From: DONNOT Benjamin Date: Thu, 14 Mar 2024 10:03:12 +0100 Subject: [PATCH 2/7] trying to fix windows CI --- .circleci/config.yml | 21 ++++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index 6973ecc..f62aefe 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -268,11 +268,17 @@ jobs: size: medium # ("medium" "large" "xlarge" "2xlarge") steps: - checkout - # - run: - # name: "Install Python" - # command: choco install python --version=3.9 # use python 3.9 for windows test - - run: py -m pip install virtualenv - - run: py -m virtualenv venv_test + - run: choco install python --version=3.10 --force -y + - run: C:\Python310\python --version + - run: C:\Python310\python -m pip install --upgrade pip setuptools wheel + - run: C:\Python310\python -m pip install virtualenv + - run: C:\Python310\python -m virtualenv venv_test + - run: + name: "Chekc python / pip version in venv" + command: | + .\venv_test\Scripts\activate + python --version + pip --version - run: name: "Install grid2op from source" command: | @@ -286,8 +292,8 @@ jobs: pip install -U pybind11 git submodule init git submodule update - py setup.py build - py -m pip install -e .[test] + python setup.py build + python -m pip install -e .[test] - run: name: "make tests" command: | @@ -295,6 +301,7 @@ jobs: cd lightsim2grid\tests python -m unittest discover -v + workflows: version: 2.1 compile: From 557cda62c56b3dffdeabd6e1312bbe7a2788c3bf Mon Sep 17 00:00:00 2001 From: DONNOT Benjamin Date: Thu, 14 Mar 2024 10:52:33 +0100 Subject: [PATCH 3/7] backward compat with new grid2op tests --- CHANGELOG.rst | 5 ++++ lightsim2grid/lightSimBackend.py | 2 +- lightsim2grid/tests/test_DCPF.py | 3 +- lightsim2grid/tests/test_Runner.py | 5 ++-- .../tests/test_init_from_pypowsybl.py | 29 +++++++++++++------ 5 files changed, 31 insertions(+), 13 deletions(-) diff --git a/CHANGELOG.rst b/CHANGELOG.rst index 147c4ab..60a23df 100644 --- a/CHANGELOG.rst +++ b/CHANGELOG.rst @@ -19,6 +19,11 @@ Change Log - maybe have a look at suitesparse "sliplu" tools ? - easier building (get rid of the "make" part) +[0.7.5.post1] 2024-03-14 +------------------------- +- [FIXED] backward compat with "future" grid2op version with a + better way to copy `LightSimBackend` + [0.7.5] 2023-10-05 -------------------- - [FIXED] a bug in DC powerflow when asking for computation time: it was not reset to 0. when diff --git a/lightsim2grid/lightSimBackend.py b/lightsim2grid/lightSimBackend.py index 522a998..8a737e8 100644 --- a/lightsim2grid/lightSimBackend.py +++ b/lightsim2grid/lightSimBackend.py @@ -998,7 +998,7 @@ def copy(self): ] + type(self)._li_attr_disp for attr_nm in cls_attr: - if hasattr(self, attr_nm): + if hasattr(self, attr_nm) and not hasattr(type(self), attr_nm): # this test is needed for backward compatibility with other grid2op version setattr(res, attr_nm, copy.deepcopy(getattr(self, attr_nm))) ############### diff --git a/lightsim2grid/tests/test_DCPF.py b/lightsim2grid/tests/test_DCPF.py index 93604c1..847aff8 100644 --- a/lightsim2grid/tests/test_DCPF.py +++ b/lightsim2grid/tests/test_DCPF.py @@ -127,7 +127,8 @@ def _aux_test(self, pn_net): with warnings.catch_warnings(): warnings.filterwarnings("ignore") backend.load_grid(case_name) - + backend.assert_grid_correct() + nb_sub = backend.n_sub pp_net = backend.init_pp_backend._grid # first i deactivate all slack bus in pp that are connected but not handled in ls diff --git a/lightsim2grid/tests/test_Runner.py b/lightsim2grid/tests/test_Runner.py index e998a8d..32e8ccf 100644 --- a/lightsim2grid/tests/test_Runner.py +++ b/lightsim2grid/tests/test_Runner.py @@ -1,4 +1,4 @@ -# Copyright (c) 2020, RTE (https://www.rte-france.com) +# Copyright (c) 2020-2024, RTE (https://www.rte-france.com) # See AUTHORS.txt # This Source Code Form is subject to the terms of the Mozilla Public License, version 2.0. # If a copy of the Mozilla Public License, version 2.0 was not distributed with this file, @@ -11,7 +11,7 @@ import grid2op from grid2op.tests.test_Runner import TestRunner as TestRunner_glop from grid2op.tests.test_RunnerFast import TestRunner as TestRunnerFast_glop -from grid2op.tests.test_Runner import HelperTests, L2RPNReward, make +from grid2op.tests.test_Runner import L2RPNReward from grid2op.Runner import Runner from lightsim2grid.lightSimBackend import LightSimBackend @@ -80,3 +80,4 @@ def setUp(self): if __name__ == "__main__": unittest.main() + \ No newline at end of file diff --git a/lightsim2grid/tests/test_init_from_pypowsybl.py b/lightsim2grid/tests/test_init_from_pypowsybl.py index 97528f5..e9d8c40 100644 --- a/lightsim2grid/tests/test_init_from_pypowsybl.py +++ b/lightsim2grid/tests/test_init_from_pypowsybl.py @@ -170,15 +170,26 @@ def test_ac_pf(self): v_ls_ref = self.ref_samecase.ac_pf(1.0 * self.V_init_ac, 10, self.tol) assert np.abs(v_ls - v_ls_ref).max() <= self.tol_eq, "error for vresults for ac" - param = lf.Parameters(voltage_init_mode=pp._pypowsybl.VoltageInitMode.UNIFORM_VALUES, - transformer_voltage_control_on=False, - no_generator_reactive_limits=True, - phase_shifter_regulation_on=False, - simul_shunt=False, - distributed_slack=False, - provider_parameters={"slackBusSelectionMode": "NAME", - "slackBusesIds": self.network_ref.get_buses().iloc[self.get_slackbus_id()].name} - ) + try: + param = lf.Parameters(voltage_init_mode=pp._pypowsybl.VoltageInitMode.UNIFORM_VALUES, + transformer_voltage_control_on=False, + use_reactive_limits=False, + shunt_compensator_voltage_control_on=False, + phase_shifter_regulation_on=False, + distributed_slack=False, + provider_parameters={"slackBusSelectionMode": "NAME", + "slackBusesIds": self.network_ref.get_buses().iloc[self.get_slackbus_id()].name} + ) + except TypeError: + param = lf.Parameters(voltage_init_mode=pp._pypowsybl.VoltageInitMode.UNIFORM_VALUES, + transformer_voltage_control_on=False, + no_generator_reactive_limits=True, # documented in the doc but apparently fails + phase_shifter_regulation_on=False, + simul_shunt=False, # documented in the doc but apparently fails + distributed_slack=False, + provider_parameters={"slackBusSelectionMode": "NAME", + "slackBusesIds": self.network_ref.get_buses().iloc[self.get_slackbus_id()].name} + ) res_pypow = lf.run_ac(self.network_ref, parameters=param) if self.compare_pp(): pdp.runpp(self.pp_samecase, init="flat") From 1cf647dc722c80273c47a33c4784c7aa03154fb3 Mon Sep 17 00:00:00 2001 From: DONNOT Benjamin Date: Thu, 14 Mar 2024 11:13:45 +0100 Subject: [PATCH 4/7] trying to fix readthedocs --- .readthedocs.yml | 11 +++++++++-- src/BaseSolver.cpp | 1 - src/DataGeneric.h | 2 +- 3 files changed, 10 insertions(+), 4 deletions(-) diff --git a/.readthedocs.yml b/.readthedocs.yml index 97df330..ab6ff9c 100644 --- a/.readthedocs.yml +++ b/.readthedocs.yml @@ -1,4 +1,4 @@ -version: 2 +version: "2" submodules: include: @@ -6,8 +6,15 @@ submodules: - eigen recursive: true +build: + os: "ubuntu-22.04" + tools: + python: "3.10" + +sphinx: + configuration: docs/conf.py + python: - version: 3.8 install: - method: pip path: . diff --git a/src/BaseSolver.cpp b/src/BaseSolver.cpp index 05c837e..e9b3f65 100644 --- a/src/BaseSolver.cpp +++ b/src/BaseSolver.cpp @@ -145,7 +145,6 @@ Eigen::VectorXi BaseSolver::extract_slack_bus_id(const Eigen::VectorXi & pv, Eigen::VectorXi res(nb_bus - pv.size() - pq.size()); Eigen::Index i_res = 0; - bool found=false; // run through both pv and pq nodes and declare they are not slack bus std::vector tmp(nb_bus, true); for(unsigned int k=0; k < pv.size(); ++k) diff --git a/src/DataGeneric.h b/src/DataGeneric.h index 8d9bc60..4cf0a68 100644 --- a/src/DataGeneric.h +++ b/src/DataGeneric.h @@ -139,7 +139,7 @@ class DataGeneric : public BaseConstants template void check_size(const T & container, intType size, const std::string & container_name) { - if(container.size() != size) throw std::runtime_error(container_name + " do not have the proper size"); + if(static_cast(container.size()) != size) throw std::runtime_error(container_name + " do not have the proper size"); } /** From 6b8a10a5daa7abdcb10c8a98752b5411af62badb Mon Sep 17 00:00:00 2001 From: DONNOT Benjamin Date: Thu, 14 Mar 2024 11:16:07 +0100 Subject: [PATCH 5/7] CI might pass again --- lightsim2grid/tests/test_DCPF.py | 1 + lightsim2grid/tests/test_LightSimBackend.py | 117 +++++++++++--------- lightsim2grid/tests/test_RedispatchEnv.py | 79 ++----------- lightsim2grid/tests/test_Runner.py | 3 +- 4 files changed, 78 insertions(+), 122 deletions(-) diff --git a/lightsim2grid/tests/test_DCPF.py b/lightsim2grid/tests/test_DCPF.py index 847aff8..c659014 100644 --- a/lightsim2grid/tests/test_DCPF.py +++ b/lightsim2grid/tests/test_DCPF.py @@ -128,6 +128,7 @@ def _aux_test(self, pn_net): warnings.filterwarnings("ignore") backend.load_grid(case_name) backend.assert_grid_correct() + # backend.init_pp_backend.assert_grid_correct() nb_sub = backend.n_sub pp_net = backend.init_pp_backend._grid diff --git a/lightsim2grid/tests/test_LightSimBackend.py b/lightsim2grid/tests/test_LightSimBackend.py index 2cae0ba..52103bd 100644 --- a/lightsim2grid/tests/test_LightSimBackend.py +++ b/lightsim2grid/tests/test_LightSimBackend.py @@ -19,14 +19,50 @@ from grid2op.Space import GridObjects # lazy import __has_storage = hasattr(GridObjects, "n_storage") -from grid2op.tests.helper_path_test import HelperTests -from grid2op.tests.BaseBackendTest import BaseTestNames, BaseTestLoadingCase, BaseTestLoadingBackendFunc -from grid2op.tests.BaseBackendTest import BaseTestTopoAction, BaseTestEnvPerformsCorrectCascadingFailures -from grid2op.tests.BaseBackendTest import BaseTestChangeBusAffectRightBus, BaseTestShuntAction -from grid2op.tests.BaseBackendTest import BaseTestResetEqualsLoadGrid, BaseTestVoltageOWhenDisco, BaseTestChangeBusSlack -from grid2op.tests.BaseBackendTest import BaseIssuesTest, BaseStatusActions -from grid2op.tests.test_Environment import TestLoadingBackendPandaPower, TestResetOk -from grid2op.tests.test_Environment import TestResetAfterCascadingFailure, TestCascadingFailure +try: + # new way of doing, does not need to inherit from HelperTests but from unittest.TestCase + from grid2op._create_test_suite import create_test_suite + from grid2op.tests.helper_path_test import HelperTests as DEPRECATEDHelper + + class _Garbage: + def setUp(self): + pass + + class _SuperGarbage(DEPRECATEDHelper, _Garbage): + pass + + _garbage = _SuperGarbage() + _garbage.setUp() + + class HelperTests(unittest.TestCase): + def setUp(self) -> None: + self.tol_one = _garbage.tol_one + self.tolvect = _garbage.tolvect + return super().setUp() + + def tearDown(self) -> None: + return super().tearDown() + +except ImportError as exc_: + # old way of doing, need to inherit from that + from grid2op.tests.helper_path_test import HelperTests +from grid2op.tests.BaseBackendTest import (BaseTestNames, + BaseTestLoadingCase, + BaseTestLoadingBackendFunc, + BaseTestTopoAction, + BaseTestEnvPerformsCorrectCascadingFailures, + BaseTestChangeBusAffectRightBus, + BaseTestShuntAction, + BaseTestResetEqualsLoadGrid, + BaseTestVoltageOWhenDisco, + BaseTestChangeBusSlack, + BaseIssuesTest, + BaseStatusActions) + +from grid2op.tests.test_Environment import (BaseTestLoadingBackendPandaPower, + BaseTestResetOk, + BaseTestResetAfterCascadingFailure, + BaseTestCascadingFailure) if __has_storage: from grid2op.tests.BaseBackendTest import BaseTestStorageAction @@ -37,32 +73,24 @@ from lightsim2grid.solver import SolverType from grid2op.Runner import Runner -class TestNames(HelperTests, BaseTestNames): + +class TestNames(BaseTestNames, unittest.TestCase): def make_backend(self, detailed_infos_for_cascading_failures=False): with warnings.catch_warnings(): warnings.filterwarnings("ignore") bk = LightSimBackend(detailed_infos_for_cascading_failures=detailed_infos_for_cascading_failures) return bk - def get_path(self): - return PATH_DATA_TEST_INIT - -class TestLoadingCase(HelperTests, BaseTestLoadingCase): +class TestLoadingCase(BaseTestLoadingCase, unittest.TestCase): def make_backend(self, detailed_infos_for_cascading_failures=False): with warnings.catch_warnings(): warnings.filterwarnings("ignore") bk = LightSimBackend(detailed_infos_for_cascading_failures=detailed_infos_for_cascading_failures) return bk - def get_path(self): - return PATH_DATA_TEST - def get_casefile(self): - return "test_case14.json" - - -class TestLoadingBackendFunc(HelperTests, BaseTestLoadingBackendFunc): +class TestLoadingBackendFunc(BaseTestLoadingBackendFunc, unittest.TestCase): def setUp(self): # TODO find something more elegant BaseTestLoadingBackendFunc.setUp(self) @@ -84,14 +112,8 @@ def make_backend(self, detailed_infos_for_cascading_failures=False): bk = LightSimBackend(detailed_infos_for_cascading_failures=detailed_infos_for_cascading_failures) return bk - def get_path(self): - return PATH_DATA_TEST - - def get_casefile(self): - return "test_case14.json" - -class TestTopoAction(HelperTests, BaseTestTopoAction): +class TestTopoAction(BaseTestTopoAction, unittest.TestCase): def setUp(self): BaseTestTopoAction.setUp(self) @@ -105,14 +127,8 @@ def make_backend(self, detailed_infos_for_cascading_failures=False): bk = LightSimBackend(detailed_infos_for_cascading_failures=detailed_infos_for_cascading_failures) return bk - def get_path(self): - return PATH_DATA_TEST - - def get_casefile(self): - return "test_case14.json" - -class TestEnvPerformsCorrectCascadingFailures(HelperTests, BaseTestEnvPerformsCorrectCascadingFailures): +class TestEnvPerformsCorrectCascadingFailures(BaseTestEnvPerformsCorrectCascadingFailures, unittest.TestCase): def setUp(self): BaseTestEnvPerformsCorrectCascadingFailures.setUp(self) @@ -125,15 +141,9 @@ def make_backend(self, detailed_infos_for_cascading_failures=False): warnings.filterwarnings("ignore") bk = LightSimBackend(detailed_infos_for_cascading_failures=detailed_infos_for_cascading_failures) return bk + - def get_casefile(self): - return "test_case14.json" - - def get_path(self): - return PATH_DATA_TEST - - -class TestChangeBusAffectRightBus(HelperTests, BaseTestChangeBusAffectRightBus): +class TestChangeBusAffectRightBus(BaseTestChangeBusAffectRightBus, unittest.TestCase): def make_backend(self, detailed_infos_for_cascading_failures=False): with warnings.catch_warnings(): warnings.filterwarnings("ignore") @@ -141,7 +151,7 @@ def make_backend(self, detailed_infos_for_cascading_failures=False): return bk -class TestShuntAction(HelperTests, BaseTestShuntAction): +class TestShuntAction(BaseTestShuntAction, unittest.TestCase): def make_backend(self, detailed_infos_for_cascading_failures=False): with warnings.catch_warnings(): warnings.filterwarnings("ignore") @@ -149,7 +159,7 @@ def make_backend(self, detailed_infos_for_cascading_failures=False): return bk -class TestResetEqualsLoadGrid(HelperTests, BaseTestResetEqualsLoadGrid): +class TestResetEqualsLoadGrid(BaseTestResetEqualsLoadGrid, unittest.TestCase): def setUp(self): BaseTestResetEqualsLoadGrid.setUp(self) @@ -160,7 +170,7 @@ def make_backend(self, detailed_infos_for_cascading_failures=False): return bk -class TestVoltageOWhenDisco(HelperTests, BaseTestVoltageOWhenDisco): +class TestVoltageOWhenDisco(BaseTestVoltageOWhenDisco, unittest.TestCase): def make_backend(self, detailed_infos_for_cascading_failures=False): with warnings.catch_warnings(): warnings.filterwarnings("ignore") @@ -168,7 +178,7 @@ def make_backend(self, detailed_infos_for_cascading_failures=False): return bk -class TestChangeBusSlack(HelperTests, BaseTestChangeBusSlack): +class TestChangeBusSlack(BaseTestChangeBusSlack, unittest.TestCase): def make_backend(self, detailed_infos_for_cascading_failures=False): with warnings.catch_warnings(): warnings.filterwarnings("ignore") @@ -176,7 +186,7 @@ def make_backend(self, detailed_infos_for_cascading_failures=False): return bk -class TestIssuesTest(HelperTests, BaseIssuesTest): +class TestIssuesTest(BaseIssuesTest, unittest.TestCase): tests_skipped = ["test_issue_125"] if version.parse(grid2op.__version__) < version.parse("1.9.2") else [] def make_backend(self, detailed_infos_for_cascading_failures=False): with warnings.catch_warnings(): @@ -185,7 +195,7 @@ def make_backend(self, detailed_infos_for_cascading_failures=False): return bk -class TestStatusAction(HelperTests, BaseStatusActions): +class TestStatusAction(BaseStatusActions, unittest.TestCase): def make_backend(self, detailed_infos_for_cascading_failures=False): with warnings.catch_warnings(): warnings.filterwarnings("ignore") @@ -194,8 +204,9 @@ def make_backend(self, detailed_infos_for_cascading_failures=False): if __has_storage: - class TestStorageAction(HelperTests, BaseTestStorageAction): + class TestStorageAction(BaseTestStorageAction, unittest.TestCase): def setUp(self): + super().setUp() self.tests_skipped = ["test_storage_action_topo"] # TODO this test is super weird ! It's like we impose # TODO a behaviour from pandapower (weird one) to all backends... @@ -206,22 +217,22 @@ def make_backend(self, detailed_infos_for_cascading_failures=False): return bk -class TestLoadingBackendLightSim(TestLoadingBackendPandaPower): +class TestLoadingBackendLightSim(BaseTestLoadingBackendPandaPower, unittest.TestCase): def get_backend(self, detailed_infos_for_cascading_failures=True): return LightSimBackend(detailed_infos_for_cascading_failures=detailed_infos_for_cascading_failures) -class TestResetOkLS(TestResetOk): +class TestResetOkLS(BaseTestResetOk, unittest.TestCase): def make_backend(self, detailed_infos_for_cascading_failures=False): return LightSimBackend(detailed_infos_for_cascading_failures=detailed_infos_for_cascading_failures) -class TestResetAfterCascadingFailureLS(TestResetAfterCascadingFailure): +class TestResetAfterCascadingFailureLS(BaseTestResetAfterCascadingFailure, unittest.TestCase): def make_backend(self, detailed_infos_for_cascading_failures=False): return LightSimBackend(detailed_infos_for_cascading_failures=detailed_infos_for_cascading_failures) -class TestCascadingFailureLS(TestCascadingFailure): +class TestCascadingFailureLS(BaseTestCascadingFailure, unittest.TestCase): def make_backend(self, detailed_infos_for_cascading_failures=False): return LightSimBackend(detailed_infos_for_cascading_failures=detailed_infos_for_cascading_failures) diff --git a/lightsim2grid/tests/test_RedispatchEnv.py b/lightsim2grid/tests/test_RedispatchEnv.py index f49451b..0f5b5e0 100644 --- a/lightsim2grid/tests/test_RedispatchEnv.py +++ b/lightsim2grid/tests/test_RedispatchEnv.py @@ -5,75 +5,36 @@ # you can obtain one at http://mozilla.org/MPL/2.0/. # SPDX-License-Identifier: MPL-2.0 # This file is part of LightSim2grid, LightSim2grid implements a c++ backend targeting the Grid2Op platform. + import unittest import warnings -from grid2op.tests.helper_path_test import PATH_DATA_TEST_PP, PATH_DATA_TEST - -from grid2op.tests.helper_path_test import HelperTests -from grid2op.tests.BaseRedispTest import BaseTestRedispatch, BaseTestRedispatchChangeNothingEnvironment -from grid2op.tests.BaseRedispTest import BaseTestRedispTooLowHigh, BaseTestDispatchRampingIllegalETC -from grid2op.tests.BaseRedispTest import BaseTestLoadingAcceptAlmostZeroSumRedisp +from grid2op.tests.BaseRedispTest import (BaseTestRedispatch, + BaseTestRedispatchChangeNothingEnvironment, + BaseTestRedispTooLowHigh, + BaseTestDispatchRampingIllegalETC, + BaseTestLoadingAcceptAlmostZeroSumRedisp) from lightsim2grid.lightSimBackend import LightSimBackend -PATH_DATA_TEST_INIT = PATH_DATA_TEST -PATH_DATA_TEST = PATH_DATA_TEST_PP - - -class TestRedispatch(HelperTests, BaseTestRedispatch): - def setUp(self): - # TODO find something more elegant - BaseTestRedispatch.setUp(self) - - def tearDown(self): - # TODO find something more elegant - BaseTestRedispatch.tearDown(self) +class TestRedispatch(BaseTestRedispatch, unittest.TestCase): def make_backend(self, detailed_infos_for_cascading_failures=False): with warnings.catch_warnings(): warnings.filterwarnings("ignore") bk = LightSimBackend(detailed_infos_for_cascading_failures=detailed_infos_for_cascading_failures) return bk - def get_path(self): - return PATH_DATA_TEST_PP - - def get_casefile(self): - return "test_case14.json" - - -class TestRedispatchChangeNothingEnvironment(HelperTests, BaseTestRedispatchChangeNothingEnvironment): - def setUp(self): - # TODO find something more elegant - BaseTestRedispatchChangeNothingEnvironment.setUp(self) - - def tearDown(self): - # TODO find something more elegant - BaseTestRedispatchChangeNothingEnvironment.tearDown(self) +class TestRedispatchChangeNothingEnvironment(BaseTestRedispatchChangeNothingEnvironment, unittest.TestCase): def make_backend(self, detailed_infos_for_cascading_failures=False): with warnings.catch_warnings(): warnings.filterwarnings("ignore") bk = LightSimBackend(detailed_infos_for_cascading_failures=detailed_infos_for_cascading_failures) return bk - def get_path(self): - return PATH_DATA_TEST_PP - - def get_casefile(self): - return "test_case14.json" - - -class TestRedispTooLowHigh(HelperTests, BaseTestRedispTooLowHigh): - def setUp(self): - # TODO find something more elegant - BaseTestRedispTooLowHigh.setUp(self) - - def tearDown(self): - # TODO find something more elegant - BaseTestRedispTooLowHigh.tearDown(self) +class TestRedispTooLowHigh(BaseTestRedispTooLowHigh, unittest.TestCase): def make_backend(self, detailed_infos_for_cascading_failures=False): with warnings.catch_warnings(): warnings.filterwarnings("ignore") @@ -81,15 +42,7 @@ def make_backend(self, detailed_infos_for_cascading_failures=False): return bk -class TestDispatchRampingIllegalETC(HelperTests, BaseTestDispatchRampingIllegalETC): - def setUp(self): - # TODO find something more elegant - BaseTestDispatchRampingIllegalETC.setUp(self) - - def tearDown(self): - # TODO find something more elegant - BaseTestDispatchRampingIllegalETC.tearDown(self) - +class TestDispatchRampingIllegalETC(BaseTestDispatchRampingIllegalETC, unittest.TestCase): def make_backend(self, detailed_infos_for_cascading_failures=False): with warnings.catch_warnings(): warnings.filterwarnings("ignore") @@ -97,15 +50,7 @@ def make_backend(self, detailed_infos_for_cascading_failures=False): return bk -class TestLoadingAcceptAlmostZeroSumRedisp(HelperTests, BaseTestLoadingAcceptAlmostZeroSumRedisp): - def setUp(self): - # TODO find something more elegant - BaseTestLoadingAcceptAlmostZeroSumRedisp.setUp(self) - - def tearDown(self): - # TODO find something more elegant - BaseTestLoadingAcceptAlmostZeroSumRedisp.tearDown(self) - +class TestLoadingAcceptAlmostZeroSumRedisp(BaseTestLoadingAcceptAlmostZeroSumRedisp, unittest.TestCase): def make_backend(self, detailed_infos_for_cascading_failures=False): with warnings.catch_warnings(): warnings.filterwarnings("ignore") @@ -114,4 +59,4 @@ def make_backend(self, detailed_infos_for_cascading_failures=False): if __name__ == "__main__": - unittest.main() + unittest.main() \ No newline at end of file diff --git a/lightsim2grid/tests/test_Runner.py b/lightsim2grid/tests/test_Runner.py index 32e8ccf..9f7a497 100644 --- a/lightsim2grid/tests/test_Runner.py +++ b/lightsim2grid/tests/test_Runner.py @@ -79,5 +79,4 @@ def setUp(self): if __name__ == "__main__": - unittest.main() - \ No newline at end of file + unittest.main() \ No newline at end of file From 919eb64958bfbb83d9898136be27efa1478623da Mon Sep 17 00:00:00 2001 From: DONNOT Benjamin Date: Thu, 14 Mar 2024 11:35:50 +0100 Subject: [PATCH 6/7] tyring to fix test in DC powerflow --- lightsim2grid/tests/test_DCPF.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/lightsim2grid/tests/test_DCPF.py b/lightsim2grid/tests/test_DCPF.py index c659014..3e910d7 100644 --- a/lightsim2grid/tests/test_DCPF.py +++ b/lightsim2grid/tests/test_DCPF.py @@ -124,8 +124,10 @@ def _aux_test(self, pn_net): real_init_file = pp.from_json(case_name) backend = LightSimBackend() + type(backend)._clear_grid_dependant_class_attributes() with warnings.catch_warnings(): warnings.filterwarnings("ignore") + type(backend).env_name = pn_net backend.load_grid(case_name) backend.assert_grid_correct() # backend.init_pp_backend.assert_grid_correct() From af31a9112539a518b449d2b789251b6cf1b23be0 Mon Sep 17 00:00:00 2001 From: DONNOT Benjamin Date: Thu, 14 Mar 2024 12:02:17 +0100 Subject: [PATCH 7/7] fixing read the doc --- src/Solvers.h | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/Solvers.h b/src/Solvers.h index 4adaac8..d3678f5 100644 --- a/src/Solvers.h +++ b/src/Solvers.h @@ -6,6 +6,9 @@ // SPDX-License-Identifier: MPL-2.0 // This file is part of LightSim2grid, LightSim2grid implements a c++ backend targeting the Grid2Op platform. +#ifndef SOLVERS_H +#define SOLVERS_H + #include "BaseNRSolver.h" #include "BaseNRSolverSingleSlack.h" #include "DCSolver.h" @@ -94,3 +97,5 @@ typedef BaseFDPFSolver FDPF_BX_SparseLUSol class FDPF_XB_CKTSOSolver : public FDPF_XB_SparseLUSolver {}; class FDPF_BX_CKTSOSolver : public FDPF_BX_SparseLUSolver {}; #endif // CKTSO_SOLVER_AVAILABLE + +#endif // SOLVERS_H