From 3d9794affdaeaa02642b834e68313403acb48399 Mon Sep 17 00:00:00 2001 From: DONNOT Benjamin Date: Mon, 16 Dec 2024 11:37:24 +0100 Subject: [PATCH] fixing an issue with storage units, behaviour was not specified grid2op side, now it is Signed-off-by: DONNOT Benjamin --- CHANGELOG.rst | 5 +++-- docs/conf.py | 4 ++-- lightsim2grid/__init__.py | 2 +- lightsim2grid/tests/test_issue_66.py | 5 +++-- setup.py | 2 +- src/GridModel.h | 4 ++-- src/element_container/LoadContainer.cpp | 10 ++-------- src/element_container/LoadContainer.h | 14 ++++++++++++++ 8 files changed, 28 insertions(+), 18 deletions(-) diff --git a/CHANGELOG.rst b/CHANGELOG.rst index 431b947c..d081ba15 100644 --- a/CHANGELOG.rst +++ b/CHANGELOG.rst @@ -26,13 +26,14 @@ TODO: in `main.cpp` check the returned policy of pybind11 and also the `py::call TODO: a cpp class that is able to compute (DC powerflow) ContingencyAnalysis and TimeSeries using PTDF and LODF TODO: integration test with pandapower (see `pandapower/contingency/contingency.py` and import `lightsim2grid_installed` and check it's True) -[0.9.3] 2024-12-16 +[0.10.0] 2024-12-16 ------------------- +- [BREAKING] disconnected storage now raises errors if some power is produced / absorbed - [FIXED] an issue with the storage units (when asking it to produce / consume but deactivating them with the same action the grid did not diverge) - [IMPROVED] add the grid2op "detachement" support (loads and generators are allowed to be disconnected from the grid) - + [0.9.2.post2] 2024-11-29 -------------------------- - [FIXED] The attribute `can_output_theta` (of base `Backend` class) diff --git a/docs/conf.py b/docs/conf.py index e06ec26b..512eeddd 100644 --- a/docs/conf.py +++ b/docs/conf.py @@ -22,8 +22,8 @@ author = 'Benjamin DONNOT' # The full version, including alpha/beta/rc tags -release = "0.9.3" -version = '0.9' +release = "0.10.0" +version = '0.10' # -- General configuration --------------------------------------------------- diff --git a/lightsim2grid/__init__.py b/lightsim2grid/__init__.py index e38ac253..f5c5ccd5 100644 --- a/lightsim2grid/__init__.py +++ b/lightsim2grid/__init__.py @@ -6,7 +6,7 @@ # SPDX-License-Identifier: MPL-2.0 # This file is part of LightSim2grid, LightSim2grid implements a c++ backend targeting the Grid2Op platform. -__version__ = "0.9.3" +__version__ = "0.10.0" __all__ = ["newtonpf", "SolverType", "ErrorType", "solver", "compilation_options"] diff --git a/lightsim2grid/tests/test_issue_66.py b/lightsim2grid/tests/test_issue_66.py index be2cc08e..9fa55e90 100644 --- a/lightsim2grid/tests/test_issue_66.py +++ b/lightsim2grid/tests/test_issue_66.py @@ -89,8 +89,9 @@ def test_disco_storage(self): act = self.env.action_space({"set_storage": [(0, -1)]}) obs, reward, done, info = self.env.step(act) - assert len(info['exception']) == 0 - assert not done + # grid2op >= 1.11.0 requires this + assert len(info['exception']) == 1 + assert done # should not raise any RuntimeError diff --git a/setup.py b/setup.py index 1a5cba7a..2cff340a 100644 --- a/setup.py +++ b/setup.py @@ -14,7 +14,7 @@ from pybind11.setup_helpers import Pybind11Extension, build_ext -__version__ = "0.9.3" +__version__ = "0.10.0" KLU_SOLVER_AVAILABLE = False # Try to link against SuiteSparse (if available) diff --git a/src/GridModel.h b/src/GridModel.h index 0c504035..e16e8294 100644 --- a/src/GridModel.h +++ b/src/GridModel.h @@ -494,9 +494,9 @@ class GridModel : public GenericContainer // reactivate_storage(storage_id); // requirement from grid2op, might be discussed // storages_.change_p(storage_id, new_p, need_reset_); // } - storages_.change_p(storage_id, new_p, solver_control_); + storages_.change_p_nothrow(storage_id, new_p, solver_control_); } - void change_q_storage(int storage_id, real_type new_q) {storages_.change_q(storage_id, new_q, solver_control_); } + void change_q_storage(int storage_id, real_type new_q) {storages_.change_q_nothrow(storage_id, new_q, solver_control_); } int get_bus_storage(int storage_id) {return storages_.get_bus(storage_id);} //deactivate a powerline (disconnect it) diff --git a/src/element_container/LoadContainer.cpp b/src/element_container/LoadContainer.cpp index e7c7483e..fedf1f68 100644 --- a/src/element_container/LoadContainer.cpp +++ b/src/element_container/LoadContainer.cpp @@ -117,10 +117,7 @@ void LoadContainer::change_p(int load_id, real_type new_p, SolverControl & solve exc_ << ")"; throw std::runtime_error(exc_.str()); } - if (p_mw_(load_id) != new_p) { - solver_control.tell_recompute_sbus(); - p_mw_(load_id) = new_p; - } + change_p_nothrow(load_id, new_p, solver_control); } void LoadContainer::change_q(int load_id, real_type new_q, SolverControl & solver_control) @@ -134,10 +131,7 @@ void LoadContainer::change_q(int load_id, real_type new_q, SolverControl & solve exc_ << ")"; throw std::runtime_error(exc_.str()); } - if (q_mvar_(load_id) != new_q) { - solver_control.tell_recompute_sbus(); - q_mvar_(load_id) = new_q; - } + change_q_nothrow(load_id, new_q, solver_control); } void LoadContainer::reconnect_connected_buses(std::vector & bus_status) const { diff --git a/src/element_container/LoadContainer.h b/src/element_container/LoadContainer.h index 9a6710b8..edfea92a 100644 --- a/src/element_container/LoadContainer.h +++ b/src/element_container/LoadContainer.h @@ -153,7 +153,21 @@ class LoadContainer : public GenericContainer void change_bus(int load_id, int new_bus_id, SolverControl & solver_control, int nb_bus) {_change_bus(load_id, new_bus_id, bus_id_, solver_control, nb_bus);} int get_bus(int load_id) {return _get_bus(load_id, status_, bus_id_);} void change_p(int load_id, real_type new_p, SolverControl & solver_control); + void change_p_nothrow(int load_id, real_type new_p, SolverControl & solver_control) + { + if (p_mw_(load_id) != new_p) { + solver_control.tell_recompute_sbus(); + p_mw_(load_id) = new_p; + } + } void change_q(int load_id, real_type new_q, SolverControl & solver_control); + void change_q_nothrow(int load_id, real_type new_q, SolverControl & solver_control) + { + if (q_mvar_(load_id) != new_q) { + solver_control.tell_recompute_sbus(); + q_mvar_(load_id) = new_q; + } + } virtual void reconnect_connected_buses(std::vector & bus_status) const; virtual void disconnect_if_not_in_main_component(std::vector & busbar_in_main_component);