From 6ccc96d93985c508dfd79cbc7daf9c1b530fbef9 Mon Sep 17 00:00:00 2001 From: DONNOT Benjamin Date: Thu, 14 Mar 2024 15:23:45 +0100 Subject: [PATCH] foward compatibility --- .circleci/config.yml | 21 ++- .readthedocs.yml | 11 +- CHANGELOG.rst | 5 + docs/conf.py | 2 +- lightsim2grid/__init__.py | 2 +- lightsim2grid/lightSimBackend.py | 140 ++++++++++++-------- lightsim2grid/tests/test_DCPF.py | 4 + lightsim2grid/tests/test_LightSimBackend.py | 115 ++++++++-------- lightsim2grid/tests/test_RedispatchEnv.py | 79 ++--------- lightsim2grid/tests/test_Runner.py | 6 +- src/DataGeneric.h | 2 +- src/Solvers.h | 5 + 12 files changed, 202 insertions(+), 190 deletions(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index 6973ecc..3ffe6a5 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: 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/CHANGELOG.rst b/CHANGELOG.rst index bda46b0..1d6496d 100644 --- a/CHANGELOG.rst +++ b/CHANGELOG.rst @@ -19,6 +19,11 @@ Change Log - easier building (get rid of the "make" part) - code NR with dense matrices +[0.7.4.post1] 2024-03-14 +-------------------------- +- [FIXED] 'forward' compatibility with grid2op 1.10.0 by making the `copy()` + implementation of lightsim2grid more generic + [0.7.3] 2023-08-24 -------------------- - [FIXED] a bug where, when you disconnect a load (or gen), the next action cannot be performed diff --git a/docs/conf.py b/docs/conf.py index 8b64a4f..5c320d8 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 = "0.7.4" +release = "0.7.4.post1" version = '0.7' # -- General configuration --------------------------------------------------- diff --git a/lightsim2grid/__init__.py b/lightsim2grid/__init__.py index f7d6d89..3351fa3 100644 --- a/lightsim2grid/__init__.py +++ b/lightsim2grid/__init__.py @@ -9,7 +9,7 @@ import faulthandler faulthandler.enable() -__version__ = "0.7.4" +__version__ = "0.7.4.post1" __all__ = ["newtonpf", "SolverType", "ErrorType", "solver"] diff --git a/lightsim2grid/lightSimBackend.py b/lightsim2grid/lightSimBackend.py index 7a0ce86..630d29e 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 @@ -65,6 +72,8 @@ def __init__(self, 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,32 +177,33 @@ 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 @@ -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 @@ -970,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..9d6053e 100644 --- a/lightsim2grid/tests/test_DCPF.py +++ b/lightsim2grid/tests/test_DCPF.py @@ -124,9 +124,13 @@ 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() 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..917c29c 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) @@ -126,14 +142,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_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 e998a8d..9f7a497 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 @@ -79,4 +79,4 @@ def setUp(self): if __name__ == "__main__": - unittest.main() + unittest.main() \ No newline at end of file diff --git a/src/DataGeneric.h b/src/DataGeneric.h index a2be43f..1dd54ef 100644 --- a/src/DataGeneric.h +++ b/src/DataGeneric.h @@ -132,7 +132,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"); } /** diff --git a/src/Solvers.h b/src/Solvers.h index 350c254..2d8ebe7 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" @@ -72,3 +75,5 @@ typedef BaseDCSolver DCSolver; /** Solver based on Newton Raphson, using the KLU linear solver, only suitable for the DC approximation**/ class CKTSODCSolver : public DCSolver{}; #endif // CKTSO_SOLVER_AVAILABLE + +#endif // SOLVERS_H