Skip to content

Commit 8c3448e

Browse files
committed
ready to merge with dev_1.10.2
1 parent 93e2042 commit 8c3448e

File tree

4 files changed

+138
-5
lines changed

4 files changed

+138
-5
lines changed

.gitignore

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -403,6 +403,11 @@ grid2op/tests/requirements.txt
403403
grid2op/tests/venv_test_311/
404404
issue_577/
405405
junk.py
406+
grid2op/tests/20240429_failed_tests.txt
407+
grid2op/tests/20240429_failed_tests_small.txt
408+
grid2op/tests/20240429_teq_test.txt
409+
grid2op/tests/req_38_np121
410+
test_make_2_envs.py
406411

407412
# profiling files
408413
**.prof

grid2op/Action/baseAction.py

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6435,7 +6435,6 @@ def decompose_as_unary_actions(self,
64356435
tmp += a
64366436
assert tmp == act
64376437
6438-
64396438
Parameters
64406439
----------
64416440
group_topo : bool, optional
@@ -6499,12 +6498,15 @@ def decompose_as_unary_actions(self,
64996498
self._aux_decompose_as_unary_actions_curtail(cls, group_curtail, res)
65006499
return res
65016500

6502-
def _add_act_and_remove_line_status_only_set(self, other: "BaseAction"):
6501+
def _add_act_and_remove_line_status_only_set(self, other: "BaseAction") -> "BaseAction":
65036502
"""INTERNAL
65046503
65056504
This is used by the environment when combining action in the "set state" in env.reset.
65066505
65076506
It supposes both self and other are only "set" actions
6507+
6508+
.. versionadded:: 1.10.2
6509+
65086510
"""
65096511
self += other
65106512
cls = type(self)
@@ -6529,13 +6531,16 @@ def _add_act_and_remove_line_status_only_set(self, other: "BaseAction"):
65296531
self._modif_set_status = True
65306532
if (self._set_topo_vect != 0).any():
65316533
self._modif_set_bus = True
6534+
return self
65326535

65336536
def remove_change(self) -> "BaseAction":
65346537
"""This function will modify 'self' and remove all "change" action type.
65356538
65366539
It is mainly used in the environment, when removing the "change" type for setting the original
65376540
state of the grid.
65386541
6542+
.. versionadded:: 1.10.2
6543+
65396544
"""
65406545
if self._change_bus_vect.any():
65416546
warnings.warn("This action modified the buses with `change_bus` ")
@@ -6544,4 +6549,4 @@ def remove_change(self) -> "BaseAction":
65446549
if self._switch_line_status.any():
65456550
self._switch_line_status[:] = False
65466551
self._modif_change_status = False
6547-
return self
6552+
return self

grid2op/tests/test_RunnerFast.py

Lines changed: 125 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,125 @@
1+
# Copyright (c) 2019-2020, RTE (https://www.rte-france.com)
2+
# See AUTHORS.txt
3+
# This Source Code Form is subject to the terms of the Mozilla Public License, version 2.0.
4+
# If a copy of the Mozilla Public License, version 2.0 was not distributed with this file,
5+
# you can obtain one at http://mozilla.org/MPL/2.0/.
6+
# SPDX-License-Identifier: MPL-2.0
7+
# This file is part of Grid2Op, Grid2Op a testbed platform to model sequential decision making in power systems.
8+
9+
import warnings
10+
import unittest
11+
12+
from grid2op.tests.helper_path_test import *
13+
14+
PATH_ADN_CHRONICS_FOLDER = os.path.abspath(
15+
os.path.join(PATH_CHRONICS, "test_multi_chronics")
16+
)
17+
PATH_PREVIOUS_RUNNER = os.path.join(data_test_dir, "runner_data")
18+
19+
import grid2op
20+
from grid2op.Runner import Runner
21+
from grid2op.dtypes import dt_float
22+
23+
warnings.simplefilter("error")
24+
25+
26+
class TestRunner(HelperTests, unittest.TestCase):
27+
def setUp(self):
28+
super().setUp()
29+
self.init_grid_path = os.path.join(PATH_DATA_TEST_PP, "test_case14.json")
30+
self.path_chron = PATH_ADN_CHRONICS_FOLDER
31+
self.parameters_path = None
32+
self.max_iter = 10
33+
self.real_reward = dt_float(7748.425 / 12.)
34+
self.real_reward_li = [self.real_reward, dt_float(7786.8955 / 12.)] # 7786.89599609375
35+
36+
self.all_real_rewards = [
37+
dt_float(el / 12.)
38+
for el in [
39+
761.3295,
40+
768.10144,
41+
770.2673,
42+
767.767,
43+
768.69,
44+
768.71246,
45+
779.1029,
46+
783.2737,
47+
788.7833,
48+
792.39764,
49+
]
50+
]
51+
with warnings.catch_warnings():
52+
warnings.filterwarnings("ignore")
53+
self.env = grid2op.make("l2rpn_case14_sandbox", test=True, _add_to_name=type(self).__name__)
54+
self.runner = Runner(**self.env.get_params_for_runner())
55+
56+
def test_one_episode(self):
57+
with warnings.catch_warnings():
58+
warnings.filterwarnings("ignore")
59+
_, cum_reward, timestep, max_ts = self.runner.run_one_episode(
60+
max_iter=self.max_iter
61+
)
62+
assert int(timestep) == self.max_iter
63+
assert np.abs(cum_reward - self.real_reward) <= self.tol_one, f"{cum_reward} != {self.real_reward}"
64+
65+
def test_one_episode_detailed(self):
66+
with warnings.catch_warnings():
67+
warnings.filterwarnings("ignore")
68+
_, cum_reward, timestep, max_ts, episode_data = self.runner.run_one_episode(
69+
max_iter=self.max_iter, detailed_output=True
70+
)
71+
assert int(timestep) == self.max_iter
72+
assert np.abs(cum_reward - self.real_reward) <= self.tol_one
73+
for j in range(len(self.all_real_rewards)):
74+
assert (
75+
np.abs(episode_data.rewards[j] - self.all_real_rewards[j])
76+
<= self.tol_one
77+
), f"{episode_data.rewards[j]} != {self.all_real_rewards[j]}"
78+
79+
def test_2episode(self):
80+
with warnings.catch_warnings():
81+
warnings.filterwarnings("ignore")
82+
res = self.runner._run_sequential(nb_episode=2, max_iter=self.max_iter)
83+
assert len(res) == 2
84+
for i, (stuff, _, cum_reward, timestep, total_ts) in enumerate(res):
85+
assert int(timestep) == self.max_iter
86+
assert np.abs(cum_reward - self.real_reward_li[i]) <= self.tol_one, f"for iter {i}: {cum_reward} != {self.real_reward_li[i]}"
87+
88+
def test_init_from_env(self):
89+
with warnings.catch_warnings():
90+
warnings.filterwarnings("ignore")
91+
with grid2op.make("rte_case14_test", test=True, _add_to_name=type(self).__name__) as env:
92+
runner = Runner(**env.get_params_for_runner())
93+
res = runner.run(nb_episode=1, max_iter=self.max_iter)
94+
for i, _, cum_reward, timestep, total_ts in res:
95+
assert int(timestep) == self.max_iter, f"{timestep} != {self.max_iter}"
96+
97+
def test_seed_seq(self):
98+
with warnings.catch_warnings():
99+
warnings.filterwarnings("ignore")
100+
with grid2op.make("rte_case14_test", test=True, _add_to_name=type(self).__name__) as env:
101+
runner = Runner(**env.get_params_for_runner())
102+
res = runner.run(
103+
nb_episode=1, max_iter=self.max_iter, env_seeds=[1], agent_seeds=[2]
104+
)
105+
for i, _, cum_reward, timestep, total_ts in res:
106+
assert int(timestep) == self.max_iter, f"{timestep} != {self.max_iter}"
107+
108+
def test_seed_par(self):
109+
with warnings.catch_warnings():
110+
warnings.filterwarnings("ignore")
111+
with grid2op.make("rte_case14_test", test=True, _add_to_name=type(self).__name__) as env:
112+
runner = Runner(**env.get_params_for_runner())
113+
res = runner.run(
114+
nb_episode=2,
115+
nb_process=2,
116+
max_iter=self.max_iter,
117+
env_seeds=[1, 2],
118+
agent_seeds=[3, 4],
119+
)
120+
for i, _, cum_reward, timestep, total_ts in res:
121+
assert int(timestep) == self.max_iter
122+
123+
124+
if __name__ == "__main__":
125+
unittest.main()

grid2op/tests/test_action_set_orig_state.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,6 @@
4141

4242

4343
# TODO test "change" is deactivated
44-
# TODO test grid2Op compat mode (storage units)
45-
# TODO test with redispatching and curtailment actions
4644
# TODO test with "names_orig_to_backend"
4745

4846

0 commit comments

Comments
 (0)