Skip to content

Commit

Permalink
Merge pull request #430 from BDonnot/master
Browse files Browse the repository at this point in the history
Fix PandapowerBackend and authorize different grid between env and simulate
  • Loading branch information
BDonnot committed Mar 17, 2023
2 parents d1531b1 + 28061c4 commit 8f34ced
Show file tree
Hide file tree
Showing 56 changed files with 4,499 additions and 384 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@ Change Log
as a networkx graph. It is replaced by a "nb_connected" attribute. More information on the doc.
- [BREAKING] the function "obs.as_networkx" will be renamed "`obs.get_energy_graph`" and the
description has been adapted.
- [BREAKING] In `PandaPowerBackend` the kwargs argument "ligthsim2grid" was misspelled and is now properly
renamed `lightsim2grid`
- [FIXED] a bug in `PandapowerBackend` when running in dc mode (voltages were not read correctly
from the generators)
- [FIXED] issue https://github.com/rte-france/Grid2Op/issues/389 which was caused by 2 independant things:
Expand All @@ -62,6 +64,7 @@ Change Log
- [FIXED] some bus in the `obs.get_energy_graph` (previously `obs.as_networkx()`) for the cooldowns of substation
- [FIXED] issue https://github.com/rte-france/Grid2Op/issues/396
- [FIXED] issue https://github.com/rte-france/Grid2Op/issues/403
- [FIXED] a bug in `PandaPowerBackend` when it was copied (the kwargs used to build it were not propagated)
- [ADDED] the function `obs.get_forecast_env()` that is able to generate a grid2op environment from the
forecasts data in the observation. This is especially useful in model based RL.
- [ADDED] an example on how to write a backend.
Expand Down Expand Up @@ -103,6 +106,8 @@ Change Log
- [IMPROVED] the `obs.get_energy_graph` (previously `obs.as_networkx()`) method with added attributes for edges (origin and extremity substation, as well as origin and
extremity buses)
- [IMPROVED] the doc of the `obs.get_energy_graph` (previously `obs.as_networkx()`)
- [IMPROVED] it is now possible to use a different backend, a different grid or different kwargs between the
env backend and the obs backend.

[1.8.1] - 2023-01-11
---------------------
Expand Down
77 changes: 39 additions & 38 deletions grid2op/Backend/PandaPowerBackend.py
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ class PandaPowerBackend(Backend):
def __init__(
self,
detailed_infos_for_cascading_failures=False,
ligthsim2grid=False, # use lightsim2grid as pandapower powerflow solver
lightsim2grid=False, # use lightsim2grid as pandapower powerflow solver
dist_slack=False,
max_iter=10,
can_be_copied=True,
Expand All @@ -120,7 +120,7 @@ def __init__(
self,
detailed_infos_for_cascading_failures=detailed_infos_for_cascading_failures,
can_be_copied=can_be_copied,
ligthsim2grid=ligthsim2grid,
lightsim2grid=lightsim2grid,
dist_slack=dist_slack,
max_iter=max_iter
)
Expand Down Expand Up @@ -207,7 +207,7 @@ def __init__(
self.gen_theta = None
self.storage_theta = None

self._ligthsim2grid = ligthsim2grid
self._lightsim2grid = lightsim2grid
self._dist_slack = dist_slack
self._max_iter = max_iter

Expand Down Expand Up @@ -354,15 +354,15 @@ def load_grid(self, path=None, filename=None):
pp.runpp(
self._grid,
numba=numba_,
lightsim2grid=self._ligthsim2grid,
lightsim2grid=self._lightsim2grid,
distributed_slack=self._dist_slack,
max_iteration=self._max_iter,
)
except pp.powerflow.LoadflowNotConverged:
pp.rundcpp(
self._grid,
numba=numba_,
lightsim2grid=self._ligthsim2grid,
lightsim2grid=self._lightsim2grid,
distributed_slack=self._dist_slack,
max_iteration=self._max_iter,
)
Expand Down Expand Up @@ -393,33 +393,36 @@ def load_grid(self, path=None, filename=None):

bus_gen_added = ppc2pd[int(el)]
# see https://matpower.org/docs/ref/matpower5.0/idx_gen.html for details on the comprehension of self._grid._ppc
if new_pp_version:
id_added = pp.create_gen(
self._grid,
bus_gen_added,
p_mw=self._grid._ppc["gen"][gen_id_pp, 1],
vm_pu=self._grid._ppc["gen"][gen_id_pp, 5],
min_p_mw=self._grid._ppc["gen"][gen_id_pp, 9],
max_p_mw=self._grid._ppc["gen"][gen_id_pp, 8],
max_q_mvar=self._grid._ppc["gen"][gen_id_pp, 3],
min_q_mvar=self._grid._ppc["gen"][gen_id_pp, 4],
slack=i_ref is None,
slack_weight=1.0,
controllable=True,
)
else:
id_added = pp.create_gen(
self._grid,
bus_gen_added,
p_mw=self._grid._ppc["gen"][gen_id_pp, 1],
vm_pu=self._grid._ppc["gen"][gen_id_pp, 5],
min_p_mw=self._grid._ppc["gen"][gen_id_pp, 9],
max_p_mw=self._grid._ppc["gen"][gen_id_pp, 8],
max_q_mvar=self._grid._ppc["gen"][gen_id_pp, 3],
min_q_mvar=self._grid._ppc["gen"][gen_id_pp, 4],
slack=i_ref is None,
controllable=True,
)
with warnings.catch_warnings():
warnings.filterwarnings("ignore")
# some warnings are issued depending on pp and pandas version
if new_pp_version:
id_added = pp.create_gen(
self._grid,
bus_gen_added,
p_mw=self._grid._ppc["gen"][gen_id_pp, 1],
vm_pu=self._grid._ppc["gen"][gen_id_pp, 5],
min_p_mw=self._grid._ppc["gen"][gen_id_pp, 9],
max_p_mw=self._grid._ppc["gen"][gen_id_pp, 8],
max_q_mvar=self._grid._ppc["gen"][gen_id_pp, 3],
min_q_mvar=self._grid._ppc["gen"][gen_id_pp, 4],
slack=i_ref is None,
slack_weight=1.0,
controllable=True,
)
else:
id_added = pp.create_gen(
self._grid,
bus_gen_added,
p_mw=self._grid._ppc["gen"][gen_id_pp, 1],
vm_pu=self._grid._ppc["gen"][gen_id_pp, 5],
min_p_mw=self._grid._ppc["gen"][gen_id_pp, 9],
max_p_mw=self._grid._ppc["gen"][gen_id_pp, 8],
max_q_mvar=self._grid._ppc["gen"][gen_id_pp, 3],
min_q_mvar=self._grid._ppc["gen"][gen_id_pp, 4],
slack=i_ref is None,
controllable=True,
)

if i_ref is None:
i_ref = gen_id_pp
Expand All @@ -436,15 +439,15 @@ def load_grid(self, path=None, filename=None):
pp.runpp(
self._grid,
numba=numba_,
lightsim2grid=self._ligthsim2grid,
lightsim2grid=self._lightsim2grid,
distributed_slack=self._dist_slack,
max_iteration=self._max_iter,
)
except pp.powerflow.LoadflowNotConverged:
pp.rundcpp(
self._grid,
numba=numba_,
lightsim2grid=self._ligthsim2grid,
lightsim2grid=self._lightsim2grid,
distributed_slack=self._dist_slack,
max_iteration=self._max_iter,
)
Expand Down Expand Up @@ -1031,7 +1034,7 @@ def runpf(self, is_dc=False):
check_connectivity=False,
init=self._pf_init,
numba=numba_,
ligthsim2grid=self._ligthsim2grid,
lightsim2grid=self._lightsim2grid,
max_iteration=self._max_iter,
distributed_slack=self._dist_slack,
)
Expand Down Expand Up @@ -1189,9 +1192,7 @@ def copy(self):
As pandapower is pure python, the deep copy operator is perfectly suited for the task.
"""
# res = copy.deepcopy(self) # this was really slow...
res = type(self)(
detailed_infos_for_cascading_failures=self.detailed_infos_for_cascading_failures
)
res = type(self)(**self._my_kwargs)

# copy from base class (backend)

Expand Down
1 change: 1 addition & 0 deletions grid2op/Chronics/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
__all__ = [
"handlers",
"ChronicsHandler",
"GridValue",
"ChangeNothing",
Expand Down
11 changes: 11 additions & 0 deletions grid2op/Chronics/handlers/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# Copyright (c) 2019-2023, 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,
# you can obtain one at http://mozilla.org/MPL/2.0/.
# SPDX-License-Identifier: MPL-2.0
# This file is part of Grid2Op, Grid2Op a testbed platform to model sequential decision making in power systems.

__all__ = ["CSVHandler"]

from .csvHandler import CSVHandler

0 comments on commit 8f34ced

Please sign in to comment.