-
Notifications
You must be signed in to change notification settings - Fork 118
/
test_issue_153.py
56 lines (47 loc) · 2.23 KB
/
test_issue_153.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
# 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 numpy as np
import grid2op
import unittest
from grid2op.Parameters import Parameters
import warnings
class Issue153Tester(unittest.TestCase):
def test_issue_153(self):
"""
The rule "Prevent Reconnection" was not properly applied, this was because the
observation of the _ObsEnv was not properly updated.
"""
param = Parameters()
param.NO_OVERFLOW_DISCONNECTION = True
param.NB_TIMESTEP_COOLDOWN_SUB = 3
with warnings.catch_warnings():
warnings.filterwarnings("ignore")
env = grid2op.make(
"rte_case14_realistic", test=True, _add_to_name=type(self).__name__+"test_issue_153"
)
env.gen_max_ramp_up[:] = env.gen_pmax
env.gen_max_ramp_down[:] = env.gen_pmax
env.action_space.gen_max_ramp_up[:] = env.gen_pmax
env.action_space.gen_max_ramp_down[:] = env.gen_pmax
env.action_space.actionClass.gen_max_ramp_up[:] = env.gen_pmax
env.action_space.actionClass.gen_max_ramp_down[:] = env.gen_pmax
obs = env.reset()
# prod 1 do [74.8, 77. , 75.1, 76.4, 76.3, 75. , 74.5, 74.2, 73. , 72.6]
for i in range(3):
obs, reward, done, info = env.step(env.action_space())
# now generator 1 decreases: 76.3, 75. , 74.5, 74.2, 73. , 72.6
action = env.action_space({"redispatch": [(0, -76)]})
obs, reward, done, info = env.step(action)
# should be at 0.3
assert np.abs(obs.prod_p[0] - 0.3) <= 1e-2, "wrong data"
# I do an illegal action
obs, reward, done, info = env.step(action)
# and the redispatching was negative (this was the issue)
assert obs.prod_p[0] >= -env._tol_poly, "generator should be positive"
if __name__ == "__main__":
unittest.main()