Skip to content

Commit

Permalink
Merge pull request #236 from BDonnot/master
Browse files Browse the repository at this point in the history
Hotfix issue #235
  • Loading branch information
BDonnot committed Jun 23, 2021
2 parents 28d0dde + 4577dae commit 15f36a7
Show file tree
Hide file tree
Showing 4 changed files with 66 additions and 5 deletions.
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -312,7 +312,9 @@ grid2op/data_test/l2rpn_neurips_2020_track1_with_alert.zip
issue_208_res/
test_issue_208.py
test_issue_220.py
test_issue_*.py
test_issue235.py
test_issue*.py
!grid2op/tests/test_issue*.py
res_alert/
env_debug_time_last_alarm_inconsistency.zip
env_debug_time_last_alarm_inconsistency/
Expand Down
7 changes: 6 additions & 1 deletion CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,12 @@ Change Log
- [???] "asynch" multienv
- [???] properly model interconnecting powerlines

[1.6.0] - 2021-06-yy
[1.6.0] (hotfix) - 2021-06-22
------------------------------
- [FIXED] issue `Issue#235 <https://github.com/rte-france/Grid2Op/issues/235>`_ issue when using the "simulate"
feature in case of divergence of powerflow.

[1.6.0] - 2021-06-22
--------------------
- [BREAKING] (but transparent for everyone): the `disc_lines` attribute is now part of the environment, and is also
containing integer (representing the "order" on which the lines are disconnected due to protections) rather
Expand Down
7 changes: 4 additions & 3 deletions grid2op/Observation/_ObsEnv.py
Original file line number Diff line number Diff line change
Expand Up @@ -444,7 +444,7 @@ def simulate(self, action):
obs, reward, done, info = self.step(action)
return obs, reward, done, info

def get_obs(self, _update_state=False):
def get_obs(self, _update_state=True):
"""
INTERNAL
Expand All @@ -457,8 +457,9 @@ def get_obs(self, _update_state=False):
res: :class:`grid2op.Observation.Observation`
The observation available.
"""
self.current_obs.update(self, with_forecast=False)
res = copy.deepcopy(self.current_obs)
if _update_state:
self.current_obs.update(self, with_forecast=False)
res = self.current_obs.copy()
return res

def update_grid(self, env):
Expand Down
53 changes: 53 additions & 0 deletions grid2op/tests/test_issue_235.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
# 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 warnings

import grid2op
from grid2op.Chronics import ChangeNothing
from grid2op.tests.helper_path_test import *
from grid2op.Observation import CompleteObservation


class Issue224TesterObs(CompleteObservation):
def __init__(self, obs_env=None, action_helper=None, seed=None):
CompleteObservation.__init__(self, obs_env, action_helper, seed)
self._is_updated = False

def update(self, env, with_forecast=True):
self._is_updated = True
super().update(env, with_forecast)


class Issue224Tester(unittest.TestCase):
"""
This bug was due to the environment that updated the observation even when it diverges.
In this test i checked that the `update` method of the observation is not called even when I simulate
an action that lead to divergence of the powerflow.
"""
def setUp(self) -> None:
with warnings.catch_warnings():
warnings.filterwarnings("ignore")
env_nm = 'l2rpn_icaps_2021'
# from lightsim2grid import LightSimBackend
# backend=LightSimBackend(),
self.env = grid2op.make(env_nm, test=True, observation_class=Issue224TesterObs)
self.env.seed(0)
self.env.reset()

def test_diverging_action(self):
final_dict = {'generators_id': [(19, 1)],
'loads_id': [(30, 2)],
'lines_or_id': [(58, 1)],
'lines_ex_id': [(46, 1), (47, 2)]}
action = self.env.action_space({"set_bus": final_dict})
obs = self.env.reset()
simobs, simr, simd, siminfo = obs.simulate(action, time_step=0)
assert np.all(simobs.gen_p == 0.)
assert not simobs._is_updated

0 comments on commit 15f36a7

Please sign in to comment.