/
test_issue_321.py
152 lines (137 loc) · 6.04 KB
/
test_issue_321.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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
# Copyright (c) 2019-2022, RTE (https://www.rte-france.com)
# See AUTHORS.txt and https://github.com/rte-france/Grid2Op/pull/319
# 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 pdb
import warnings
import unittest
import grid2op
from grid2op.Parameters import Parameters
from grid2op.Action import PlayableAction
import numpy as np
class Issue321Tester(unittest.TestCase):
def test_curtail_limit_effective(self):
"""test that obs.curtailment_limit is above
obs.curtailment_limit_effective in this case
previously it was O. for some generators see the issue
"""
param = Parameters()
param.LIMIT_INFEASIBLE_CURTAILMENT_STORAGE_ACTION = True
env_name = "educ_case14_storage"
with warnings.catch_warnings():
warnings.filterwarnings("ignore")
env = grid2op.make(env_name, test=True,
action_class=PlayableAction, param=param,
_add_to_name=type(self).__name__)
env.seed(0)
env.set_id(0)
env.reset()
# Apply a curtailment action
action = env.action_space({'curtail': [(2, 0.1), (3, 0.15), (4, 0.2)]})
obs, _, _, _ = env.step(action)
# env does not act, they should be equal
assert np.all(obs.curtailment_limit == obs.curtailment_limit_effective)
def test_when_params_active_cutdown(self):
"""test the curtailment effective is above the curtailment
when we want to curtail too much at once"""
seed_ = 0
scen_nm = "2050-02-14_0"
with warnings.catch_warnings():
warnings.filterwarnings("ignore")
env = grid2op.make("l2rpn_wcci_2022_dev",
test=True,
_add_to_name=type(self).__name__)
param = env.parameters
param.LIMIT_INFEASIBLE_CURTAILMENT_STORAGE_ACTION = True
env.seed(seed_)
env.set_id(scen_nm)
obs = env.reset()
all_zero = env.action_space(
{"curtail": [(el, 0.0) for el in np.where(env.gen_renewable)[0]]}
)
obs, reward, done, info = env.step(all_zero)
assert done
env.change_parameters(param)
env.seed(seed_)
env.set_id(scen_nm)
obs = env.reset()
obs, reward, done, info = env.step(all_zero)
assert not done
# stuff is activated, the real limit (effective) is above the
# limit in the action (env "cut down" curtailment)
assert np.all(obs.curtailment_limit <= obs.curtailment_limit_effective)
assert np.all(obs.curtailment_limit[env.gen_renewable] == 0.)
def test_when_params_active_limitup(self):
"""test the curtailment effective is below the curtailment limit
when too much curtailment has been removed "at once"
"""
seed_ = 0
scen_nm = "2050-02-14_0"
with warnings.catch_warnings():
warnings.filterwarnings("ignore")
env = grid2op.make("l2rpn_wcci_2022_dev",
test=True,
_add_to_name=type(self).__name__)
param = env.parameters
param.LIMIT_INFEASIBLE_CURTAILMENT_STORAGE_ACTION = True
env.seed(seed_)
env.set_id(scen_nm)
obs = env.reset()
# produce a list of actions that can curtail down to O.
# then remove all curtailment at once (and check it
# breaks the env)
first_ = env.action_space(
{"curtail": [(el, 0.15) for el in np.where(env.gen_renewable)[0]]}
)
second_ = env.action_space(
{"curtail": [(el, 0.09) for el in np.where(env.gen_renewable)[0]]}
)
third_ = env.action_space(
{"curtail": [(el, 0.04) for el in np.where(env.gen_renewable)[0]]}
)
all_zero = env.action_space(
{"curtail": [(el, 0.0) for el in np.where(env.gen_renewable)[0]]}
)
all_one = env.action_space(
{"curtail": [(el, 1.0) for el in np.where(env.gen_renewable)[0]]}
)
obs, reward, done, info = env.step(first_)
assert not done
obs, reward, done, info = env.step(second_)
assert not done
obs, reward, done, info = env.step(third_)
assert not done
obs, reward, done, info = env.step(all_zero)
assert not done
obs, reward, done, info = env.step(all_one)
assert done
# use this same list of actions, and make sure it does not break the
# env with the appropriate params (expected !)
# => this means the params is effective. And so the env prevent a
# removal of the curtailment too strong.
env.change_parameters(param)
env.seed(seed_)
env.set_id(scen_nm)
obs = env.reset()
obs, reward, done, info = env.step(first_)
assert not done
obs, reward, done, info = env.step(second_)
assert not done
obs, reward, done, info = env.step(third_)
assert not done
obs, reward, done, info = env.step(all_zero)
assert not done
obs, reward, done, info = env.step(all_one)
assert not done
# stuff is activated, the real limit (effective) is below the
# limit in the action: instead of having a curtailment of 1.,
# curtailment is a below, just enough not to break
assert np.all(obs.curtailment_limit[env.gen_renewable] == 1.)
gen_prod = obs.gen_p > 0.
assert np.all(obs.curtailment_limit[env.gen_renewable & gen_prod] >
obs.curtailment_limit_effective[env.gen_renewable & gen_prod])
if __name__ == "__main__":
unittest.main()