/
test_issue_380.py
70 lines (61 loc) · 3.63 KB
/
test_issue_380.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
# 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 grid2op
import unittest
import warnings
import numpy as np
import pdb
class Issue380Tester(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.set_id(0)
def tearDown(self) -> None:
self.env.close()
return super().tearDown()
def test_limit_cs_margin(self):
obs = self.env.reset()
act = self.env.action_space({"curtail": [(2, 0.), (3, 0.), (4, 0.)]})
# this action "cut" 36.4 MW, I have a margin of 30
# margin is enough, i just cut the 6.4
res, res_add_curtailed, res_add_storage = act.limit_curtail_storage(obs, 0, do_copy=True)
assert np.sum(np.abs(res_add_storage)) == 0.
assert abs(np.sum(res_add_curtailed * obs.gen_pmax) - 6.4) <= 1e-4
# margin is relatively low, i just got 5. MW, so i "cut" 31.4
res, res_add_curtailed, res_add_storage = act.limit_curtail_storage(obs, 25, do_copy=True)
assert np.sum(np.abs(res_add_storage)) == 0.
assert abs(np.sum(res_add_curtailed * obs.gen_pmax) - 31.4) <= 1e-4
# margin is extremely low, i cut almost everything
res, res_add_curtailed, res_add_storage = act.limit_curtail_storage(obs, 29.8, do_copy=True)
assert np.sum(np.abs(res_add_storage)) == 0.
assert abs(np.sum(res_add_curtailed * obs.gen_pmax) - 36.2) <= 1e-4
# margin is extremely low, i cut almost everything
res, res_add_curtailed, res_add_storage = act.limit_curtail_storage(obs, 29.89, do_copy=True, _tol_equal=0.1)
assert np.sum(np.abs(res_add_storage)) == 0.
assert abs(np.sum(res_add_curtailed * obs.gen_pmax) - 36.29) <= 1e-4
# margin is extremely low, i cut everything (due to precision _tol_equal)
res, res_add_curtailed, res_add_storage = act.limit_curtail_storage(obs, 29.91, do_copy=True, _tol_equal=0.1)
assert np.sum(np.abs(res_add_storage)) == 0.
assert abs(np.sum(res_add_curtailed * obs.gen_pmax) - 36.4) <= 1e-4
# margin is null, i cut everything
res, res_add_curtailed, res_add_storage = act.limit_curtail_storage(obs, 30., do_copy=True, _tol_equal=0.1)
assert np.sum(np.abs(res_add_storage)) == 0.
assert abs(np.sum(res_add_curtailed * obs.gen_pmax) - 36.4) <= 1e-4
# Change of the _tol_equal
# margin is extremely low, i cut almost everything
res, res_add_curtailed, res_add_storage = act.limit_curtail_storage(obs, 29.989, do_copy=True, _tol_equal=0.01)
assert np.sum(np.abs(res_add_storage)) == 0.
assert abs(np.sum(res_add_curtailed * obs.gen_pmax) - 36.389) <= 1e-4
# margin is extremely low, i cut everything (due to precision _tol_equal)
res, res_add_curtailed, res_add_storage = act.limit_curtail_storage(obs, 29.991, do_copy=True, _tol_equal=0.01)
assert np.sum(np.abs(res_add_storage)) == 0.
assert abs(np.sum(res_add_curtailed * obs.gen_pmax) - 36.4) <= 1e-4
if __name__ == "__main__":
unittest.main()