Skip to content

Commit 0817063

Browse files
committed
fix other issues
Signed-off-by: DONNOT Benjamin <[email protected]>
1 parent 7f0e900 commit 0817063

File tree

3 files changed

+39
-40
lines changed

3 files changed

+39
-40
lines changed

grid2op/tests/_aux_test_gym_compat.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,7 @@ def test_convert_togym(self):
153153
for el in env_gym.observation_space.spaces
154154
]
155155
)
156-
size_th = 542 # as of grid2Op 1.11.0 (with obs.gen_p_delta)
156+
size_th = 562 # as of grid2Op 1.11.0 (with obs.gen_p_delta + timestep_protection_engaged)
157157
assert (
158158
dim_obs_space == size_th
159159
), f"Size should be {size_th} but is {dim_obs_space}"

grid2op/tests/test_alert_gym_compat.py

Lines changed: 37 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -77,44 +77,42 @@ def test_print_alert(self):
7777
"1.4 0. 0. 0. 0. 0. 2.8 0. 0. 2.8\n 0. 0. 4.3 0. 0. 2.8 8.5 9.9], "
7878
"(22,), float32), 'set_bus': Box(-1, 2, (177,), int32), 'set_line_status': Box(-1, 1, (59,), int32))")
7979
str_ = env_gym.observation_space.__str__()
80-
81-
assert str_ == ("Dict('_shunt_bus': Box(-2147483648, 2147483647, (6,), int32), '_shunt_p': Box(-inf, inf, (6,), float32), "
82-
"'_shunt_q': Box(-inf, inf, (6,), float32), '_shunt_v': Box(-inf, inf, (6,), float32), 'a_ex': Box(0.0, inf, "
83-
"(59,), float32), 'a_or': Box(0.0, inf, (59,), float32), 'active_alert': MultiBinary(10), 'actual_dispatch': "
84-
"Box([ -50. -67.2 -50. -250. -50. -33.6 -37.3 -37.3 -33.6 -74.7\n -100. -37.3 -37.3 -100. -74.7 "
85-
"-74.7 -150. -67.2 -74.7 -400.\n -300. -350. ], [ 50. 67.2 50. 250. 50. 33.6 37.3 37.3 33.6 74.7 100. "
86-
"37.3\n 37.3 100. 74.7 74.7 150. 67.2 74.7 400. 300. 350. ], (22,), float32), 'alert_duration': "
87-
"Box(0, 2147483647, (10,), int32), 'attack_under_alert': Box(-1, 1, (10,), int32), 'attention_budget': "
88-
"Box(0.0, inf, (1,), float32), 'current_step': Box(-2147483648, 2147483647, (1,), int32), 'curtailment': "
89-
"Box(0.0, 1.0, (22,), float32), 'curtailment_limit': Box(0.0, 1.0, (22,), float32), 'curtailment_limit_effective': "
90-
"Box(0.0, 1.0, (22,), float32), 'day': Discrete(32), 'day_of_week': Discrete(8), 'delta_time': Box(0.0, inf, (1,), "
91-
"float32), 'duration_next_maintenance': Box(-1, 2147483647, (59,), int32), 'gen_margin_down': Box(0.0, "
92-
"[ 1.4 0. 1.4 10.4 1.4 0. 0. 0. 0. 0. 2.8 0. 0. 2.8\n 0. 0. 4.3 0. 0. 2.8 8.5 "
93-
"9.9], (22,), float32), 'gen_margin_up': Box(0.0, [ 1.4 0. 1.4 10.4 1.4 0. 0. 0. 0. 0. 2.8 0. "
94-
"0. 2.8\n 0. 0. 4.3 0. 0. 2.8 8.5 9.9], (22,), float32), 'gen_p': Box(-734.88995, [ 784.88995 "
95-
"802.08997 784.88995 984.88995 784.88995 768.4899\n 772.18994 772.18994 768.4899 809.58997 834.88995 "
96-
"772.18994\n 772.18994 834.88995 809.58997 809.58997 884.88995 802.08997\n 809.58997 1134.8899 1034.8899 "
97-
"1084.8899 ], (22,), float32), 'gen_p_before_curtail': Box(-734.88995, [ 784.88995 802.08997 784.88995 984.88995 "
98-
"784.88995 768.4899\n 772.18994 772.18994 768.4899 809.58997 834.88995 772.18994\n 772.18994 834.88995 "
99-
"809.58997 809.58997 884.88995 802.08997\n 809.58997 1134.8899 1034.8899 1084.8899 ], (22,), float32), "
100-
"'gen_p_delta': Box(-inf, inf, (22,), float32), 'gen_q': Box(-inf, inf, (22,), float32), 'gen_theta': Box(-180.0, "
101-
"180.0, (22,), float32), 'gen_v': Box(0.0, inf, (22,), float32), 'hour_of_day': Discrete(24), 'is_alarm_illegal': "
102-
"Discrete(2), 'line_status': MultiBinary(59), 'load_p': Box(-inf, inf, (37,), float32), 'load_q': Box(-inf, inf, "
103-
"(37,), float32), 'load_theta': Box(-180.0, 180.0, (37,), float32), 'load_v': Box(0.0, inf, (37,), float32), 'max_step': "
104-
"Box(-2147483648, 2147483647, (1,), int32), 'minute_of_hour': Discrete(60), 'month': Discrete(13), 'p_ex': "
105-
"Box(-inf, inf, (59,), float32), 'p_or': Box(-inf, inf, (59,), float32), 'q_ex': Box(-inf, inf, (59,), float32), "
106-
"'q_or': Box(-inf, inf, (59,), float32), 'rho': Box(0.0, inf, (59,), float32), 'target_dispatch': Box([ -50. "
107-
"-67.2 -50. -250. -50. -33.6 -37.3 -37.3 -33.6 -74.7\n -100. -37.3 -37.3 -100. -74.7 -74.7 "
108-
"-150. -67.2 -74.7 -400.\n -300. -350. ], [ 50. 67.2 50. 250. 50. 33.6 37.3 37.3 33.6 74.7 100. "
109-
"37.3\n 37.3 100. 74.7 74.7 150. 67.2 74.7 400. 300. 350. ], (22,), float32), 'thermal_limit': Box(0.0, inf, "
110-
"(59,), float32), 'theta_ex': Box(-180.0, 180.0, (59,), float32), 'theta_or': Box(-180.0, 180.0, (59,), float32), "
111-
"'time_before_cooldown_line': Box(0, 96, (59,), int32), 'time_before_cooldown_sub': Box(0, 3, (36,), int32), "
112-
"'time_next_maintenance': Box(-1, 2147483647, (59,), int32), 'time_since_last_alarm': Box(-1, 2147483647, "
113-
"(1,), int32), 'time_since_last_alert': Box(-1, 2147483647, (10,), int32), 'time_since_last_attack': "
114-
"Box(-1, 2147483647, (10,), int32), 'timestep_overflow': Box(-2147483648, 2147483647, (59,), int32), "
115-
"'topo_vect': Box(-1, 2, (177,), int32), 'total_number_of_alert': Box(0, 2147483647, (1,), int32), 'v_ex': "
116-
"Box(0.0, inf, (59,), float32), 'v_or': Box(0.0, inf, (59,), float32), 'was_alarm_used_after_game_over': Discrete(2), "
117-
"'was_alert_used_after_attack': Box(-1, 1, (10,), int32), 'year': Discrete(2100))")
80+
ref_obs = ("Dict('_shunt_bus': Box(-2147483648, 2147483647, (6,), int32), '_shunt_p': Box(-inf, inf, (6,), float32), "
81+
"'_shunt_q': Box(-inf, inf, (6,), float32), '_shunt_v': Box(-inf, inf, (6,), float32), 'a_ex': Box(0.0, inf, (59,), float32), "
82+
"'a_or': Box(0.0, inf, (59,), float32), 'active_alert': MultiBinary(10), "
83+
"'actual_dispatch': Box([ -50. -67.2 -50. -250. -50. -33.6 -37.3 -37.3 -33.6 -74.7\n -100. -37.3 -37.3 -100. "
84+
" -74.7 -74.7 -150. -67.2 -74.7 -400.\n -300. -350. ], [ 50. 67.2 50. 250. 50. 33.6 37.3 37.3 33.6 74.7 100. "
85+
" 37.3\n 37.3 100. 74.7 74.7 150. 67.2 74.7 400. 300. 350. ], (22,), float32), 'alert_duration': Box(0, 2147483647, "
86+
"(10,), int32), 'attack_under_alert': Box(-1, 1, (10,), int32), 'attention_budget': Box(0.0, inf, (1,), float32), "
87+
"'current_step': Box(-2147483648, 2147483647, (1,), int32), 'curtailment': Box(0.0, 1.0, (22,), float32), "
88+
"'curtailment_limit': Box(0.0, 1.0, (22,), float32), 'curtailment_limit_effective': Box(0.0, 1.0, (22,), float32), "
89+
"'day': Discrete(32), 'day_of_week': Discrete(8), 'delta_time': Box(0.0, inf, (1,), float32), 'duration_next_maintenance': "
90+
"Box(-1, 2147483647, (59,), int32), 'gen_margin_down': Box(0.0, [ 1.4 0. 1.4 10.4 1.4 0. 0. 0. 0. 0. 2.8 0. "
91+
"0. 2.8\n 0. 0. 4.3 0. 0. 2.8 8.5 9.9], (22,), float32), 'gen_margin_up': Box(0.0, [ 1.4 0. 1.4 10.4 1.4 0. "
92+
"0. 0. 0. 0. 2.8 0. 0. 2.8\n 0. 0. 4.3 0. 0. 2.8 8.5 9.9], (22,), float32), 'gen_p': "
93+
"Box(-734.88995, [ 784.88995 802.08997 784.88995 984.88995 784.88995 768.4899\n 772.18994 772.18994 768.4899 "
94+
"809.58997 834.88995 772.18994\n 772.18994 834.88995 809.58997 809.58997 884.88995 802.08997\n 809.58997 1134.8899 "
95+
"1034.8899 1084.8899 ], (22,), float32), 'gen_p_before_curtail': Box(-734.88995, [ 784.88995 802.08997 784.88995 984.88995 "
96+
"784.88995 768.4899\n 772.18994 772.18994 768.4899 809.58997 834.88995 772.18994\n 772.18994 834.88995 809.58997 "
97+
"809.58997 884.88995 802.08997\n 809.58997 1134.8899 1034.8899 1084.8899 ], (22,), float32), 'gen_p_delta': "
98+
"Box(-inf, inf, (22,), float32), 'gen_q': Box(-inf, inf, (22,), float32), 'gen_theta': Box(-180.0, 180.0, (22,), float32), "
99+
"'gen_v': Box(0.0, inf, (22,), float32), 'hour_of_day': Discrete(24), 'is_alarm_illegal': Discrete(2), 'line_status': "
100+
"MultiBinary(59), 'load_p': Box(-inf, inf, (37,), float32), 'load_q': Box(-inf, inf, (37,), float32), 'load_theta': "
101+
"Box(-180.0, 180.0, (37,), float32), 'load_v': Box(0.0, inf, (37,), float32), 'max_step': Box(-2147483648, 2147483647, "
102+
"(1,), int32), 'minute_of_hour': Discrete(60), 'month': Discrete(13), 'p_ex': Box(-inf, inf, (59,), float32), 'p_or': "
103+
"Box(-inf, inf, (59,), float32), 'q_ex': Box(-inf, inf, (59,), float32), 'q_or': Box(-inf, inf, (59,), float32), 'rho': "
104+
"Box(0.0, inf, (59,), float32), 'target_dispatch': Box([ -50. -67.2 -50. -250. -50. -33.6 -37.3 -37.3 -33.6 "
105+
"-74.7\n -100. -37.3 -37.3 -100. -74.7 -74.7 -150. -67.2 -74.7 -400.\n -300. -350. ], [ 50. 67.2 50. 250. "
106+
"50. 33.6 37.3 37.3 33.6 74.7 100. 37.3\n 37.3 100. 74.7 74.7 150. 67.2 74.7 400. 300. 350. ], (22,), "
107+
"float32), 'thermal_limit': Box(0.0, inf, (59,), float32), 'theta_ex': Box(-180.0, 180.0, (59,), float32), 'theta_or': "
108+
"Box(-180.0, 180.0, (59,), float32), 'time_before_cooldown_line': Box(0, 96, (59,), int32), 'time_before_cooldown_sub': "
109+
"Box(0, 3, (36,), int32), 'time_next_maintenance': Box(-1, 2147483647, (59,), int32), 'time_since_last_alarm': "
110+
"Box(-1, 2147483647, (1,), int32), 'time_since_last_alert': Box(-1, 2147483647, (10,), int32), 'time_since_last_attack': "
111+
"Box(-1, 2147483647, (10,), int32), 'timestep_overflow': Box(-2147483648, 2147483647, (59,), int32), 'timestep_protection_engaged': "
112+
"Box(-2147483648, 2147483647, (59,), int32), 'topo_vect': Box(-1, 2, (177,), int32), 'total_number_of_alert': Box(0, 2147483647, "
113+
"(1,), int32), 'v_ex': Box(0.0, inf, (59,), float32), 'v_or': Box(0.0, inf, (59,), float32), 'was_alarm_used_after_game_over': "
114+
"Discrete(2), 'was_alert_used_after_attack': Box(-1, 1, (10,), int32), 'year': Discrete(2100))")
115+
assert str_ == ref_obs
118116
act = self.env.action_space()
119117
act.raise_alert = [2]
120118
act_gym = env_gym.action_space.to_gym(act)
@@ -168,6 +166,7 @@ def test_convert_alert_to_gym(self):
168166
)
169167
size_th = 1718 # as of grid2Op 1.9.1 (where alerts are added)
170168
size_th = 1740 # as of grid2Op 1.11.0 (where gen_p_delta)
169+
size_th = 1799 # as of grid2Op 1.11.0 (where timestep_protection_engaged)
171170
assert (
172171
dim_obs_space == size_th
173172
), f"Size should be {size_th} but is {dim_obs_space}"

grid2op/tests/test_issue_418.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ def test_seed(self):
3737
obs = gymenv.reset(seed=42)
3838
curt = np.array([1,1.,0.18852758,0.5537014,0.43770432,1])
3939
curt = np.array([-1,-1.,0.18852758,0.5537014,0.43770432,-1])
40-
year = 1476 # gen_p_delta being sampled before
40+
year = 229 # gen_p_delta being sampled before same for timestep_protection_engaged
4141
day = 9
4242

4343
# test that the seeding worked also in action space and observation space

0 commit comments

Comments
 (0)