Skip to content

Commit

Permalink
fixing bug rte-france#220
Browse files Browse the repository at this point in the history
  • Loading branch information
BDonnot committed Jun 7, 2021
1 parent 53cfa3d commit b0748de
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 1 deletion.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -311,6 +311,7 @@ test_jorge/
grid2op/data_test/l2rpn_neurips_2020_track1_with_alert.zip
issue_208_res/
test_issue_208.py
test_issue_220.py

# profiling files
**.prof
2 changes: 2 additions & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ Change Log
(**NB** we higly recommend importing the `Runner` like `from grid2op.Runner import Runner` though !)
- [FIXED]: some bugs in the `action_space.get_all_unitary_redispatch` and `action_space.get_all_unitary_curtail`
- [FIXED]: some bugs in the `GreedyAgent` and `TopologyGreedy`
- [FIXED]: `Issue#220 <https://github.com/rte-france/Grid2Op/issues/220>`_ `flow_bus_matrix` did not took into
account disconnected powerlines, leading to impossibility to compute this matrix in some cases.
- [ADDED] support for the "alarm operator" / "attention budget" feature
- [ADDED] retrieval of the `max_step` (ie the maximum number of step that can be performed for the current episode)
in the observation
Expand Down
2 changes: 1 addition & 1 deletion grid2op/Observation/BaseObservation.py
Original file line number Diff line number Diff line change
Expand Up @@ -1371,9 +1371,9 @@ def flow_bus_matrix(self, active_flow=True, as_csr_matrix=False):
if self.shunts_data_available:
sh_vect = self._shunt_q

data = np.zeros(nb_bus + lor_bus.shape[0] + lex_bus.shape[0], dtype=dt_float)
nb_lor = np.sum(lor_conn)
nb_lex = np.sum(lex_conn)
data = np.zeros(nb_bus + nb_lor + nb_lex, dtype=dt_float)

# if two generators / loads / storage unit are connected at the same bus
# this is why i go with matrix product and sparse matrices
Expand Down
33 changes: 33 additions & 0 deletions grid2op/tests/test_issue_220.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
# Copyright (c) 2019-2020, 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.

import unittest
import warnings
import numpy as np

import grid2op


class Issue220Tester(unittest.TestCase):
def setUp(self) -> None:
with warnings.catch_warnings():
warnings.filterwarnings("ignore")
self.env = grid2op.make('l2rpn_case14_sandbox', test=True)
self.env.seed(0)
self.env.reset()

def test_flow_bus_matrix(self):
obs = self.env.reset()
res, _ = obs.flow_bus_matrix()
assert res.shape == (14, 14)
action = self.env.action_space()
action.change_line_status = [9]
# two powerlines will be disconnected: powerline 9 (action) and powerline 13 ("cascading failure")
new_obs, reward, done, info = self.env.step(action)
res, _ = new_obs.flow_bus_matrix()
assert res.shape == (14, 14)

0 comments on commit b0748de

Please sign in to comment.