Skip to content

Commit

Permalink
Test: Update Obs Size and Str Contents
Browse files Browse the repository at this point in the history
Signed-off-by: Xavier Weiss <[email protected]>
  • Loading branch information
DEUCE1957 committed Nov 11, 2024
1 parent 02cd7b3 commit f72adae
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 55 deletions.
104 changes: 51 additions & 53 deletions grid2op/tests/test_alert_gym_compat.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,78 +78,75 @@ def test_print_alert(self):
"(22,), float32), 'set_bus': Box(-1, 2, (177,), int32), 'set_line_status': Box(-1, 1, (59,), int32))")
str_ = env_gym.observation_space.__str__()
assert str_ == ("Dict('_shunt_bus': Box(-2147483648, 2147483647, (6,), int32), '_shunt_p': Box(-inf, inf, (6,), float32), "
"'_shunt_q': Box(-inf, inf, (6,), float32), '_shunt_v': Box(-inf, inf, (6,), float32), "
"'a_ex': Box(0.0, inf, (59,), float32), 'a_or': Box(0.0, inf, (59,), float32), 'active_alert': MultiBinary(10), "
"'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. -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. 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, (10,), int32), 'attack_under_alert': Box(-1, 1, (10,), int32), "
"'_shunt_q': Box(-inf, inf, (6,), float32), '_shunt_v': Box(-inf, inf, (6,), float32), 'a_ex': Box(0.0, inf, (59,), "
"float32), 'a_or': Box(0.0, inf, (59,), float32), 'active_alert': MultiBinary(10), '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. -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. 37.3\n "
"37.3 100. 74.7 74.7 150. 67.2 74.7 400. 300. 350. ], (22,), float32), 'actual_flex': Box(-inf, inf, (37,), "
"float32), 'alert_duration': Box(0, 2147483647, (10,), int32), 'attack_under_alert': Box(-1, 1, (10,), int32), "
"'attention_budget': Box(0.0, inf, (1,), float32), 'current_step': Box(-2147483648, 2147483647, (1,), int32), "
"'curtailment': Box(0.0, 1.0, (22,), float32), 'curtailment_limit': Box(0.0, 1.0, (22,), float32), "
"'curtailment_limit_effective': Box(0.0, 1.0, (22,), float32), 'day': Discrete(32), 'day_of_week': Discrete(8), "
"'delta_time': Box(0.0, inf, (1,), float32), 'duration_next_maintenance': 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. 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. "
"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': Box(-734.88995, [ 784.88995 802.08997 784.88995 984.88995 784.88995 768.4899\n "
"772.18994 772.18994 768.4899 809.58997 834.88995 772.18994\n 772.18994 834.88995 "
"809.58997 809.58997 884.88995 802.08997\n 809.58997 1134.8899 1034.8899 1084.8899 ], "
"(22,), float32), 'gen_p_before_curtail': Box(-734.88995, [ 784.88995 802.08997 784.88995 "
"984.88995 784.88995 768.4899\n 772.18994 772.18994 768.4899 809.58997 834.88995 "
"772.18994\n 772.18994 834.88995 809.58997 809.58997 884.88995 802.08997\n 809.58997 "
"1134.8899 1034.8899 1084.8899 ], (22,), float32), 'gen_q': Box(-inf, inf, (22,), float32), "
"'gen_theta': Box(-180.0, 180.0, (22,), float32), 'gen_v': Box(0.0, inf, (22,), float32), "
"'hour_of_day': Discrete(24), 'is_alarm_illegal': Discrete(2), 'line_status': MultiBinary(59), "
"'load_p': Box(-inf, inf, (37,), float32), 'load_q': Box(-inf, inf, (37,), float32), "
"'load_theta': Box(-180.0, 180.0, (37,), float32), 'load_v': Box(0.0, inf, (37,), float32), "
"'max_step': Box(-2147483648, 2147483647, (1,), int32), 'minute_of_hour': Discrete(60), "
"'month': Discrete(13), 'p_ex': Box(-inf, inf, (59,), float32), 'p_or': Box(-inf, inf, (59,), float32), "
"'q_ex': Box(-inf, inf, (59,), float32), 'q_or': Box(-inf, inf, (59,), float32), 'rho': Box(0.0, inf, (59,), float32), "
"'target_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. -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. 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, (59,), float32), 'theta_ex': Box(-180.0, 180.0, (59,), "
"float32), 'theta_or': Box(-180.0, 180.0, (59,), float32), 'time_before_cooldown_line': Box(0, 96, (59,), int32), "
"'time_before_cooldown_sub': Box(0, 3, (36,), int32), 'time_next_maintenance': Box(-1, 2147483647, (59,), int32), "
"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. 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': Box(-734.88995, "
"[ 784.88995 802.08997 784.88995 984.88995 784.88995 768.4899\n 772.18994 772.18994 768.4899 809.58997 "
"834.88995 772.18994\n 772.18994 834.88995 809.58997 809.58997 884.88995 802.08997\n 809.58997 1134.8899 "
"1034.8899 1084.8899 ], (22,), float32), 'gen_p_before_curtail': Box(-734.88995, [ 784.88995 802.08997 784.88995 "
"984.88995 784.88995 768.4899\n 772.18994 772.18994 768.4899 809.58997 834.88995 772.18994\n 772.18994 "
"834.88995 809.58997 809.58997 884.88995 802.08997\n 809.58997 1134.8899 1034.8899 1084.8899 ], (22,), float32), "
"'gen_q': Box(-inf, inf, (22,), float32), 'gen_theta': Box(-180.0, 180.0, (22,), float32), 'gen_v': Box(0.0, inf, (22,), "
"float32), 'hour_of_day': Discrete(24), 'is_alarm_illegal': Discrete(2), 'line_status': MultiBinary(59), 'load_p': "
"Box(-inf, inf, (37,), float32), 'load_q': Box(-inf, inf, (37,), float32), 'load_theta': Box(-180.0, 180.0, (37,), "
"float32), 'load_v': Box(0.0, inf, (37,), float32), 'max_step': Box(-2147483648, 2147483647, (1,), int32), "
"'minute_of_hour': Discrete(60), 'month': Discrete(13), 'p_ex': Box(-inf, inf, (59,), float32), 'p_or': Box(-inf, inf, "
"(59,), float32), 'q_ex': Box(-inf, inf, (59,), float32), 'q_or': Box(-inf, inf, (59,), float32), 'rho': Box(0.0, inf, "
"(59,), float32), 'target_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. -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. 37.3\n 37.3 100. 74.7 74.7 150. 67.2 74.7 400. 300. 350. ], (22,), float32), "
"'target_flex': Box(-inf, inf, (37,), float32), 'thermal_limit': Box(0.0, inf, (59,), float32), 'theta_ex': Box(-180.0, "
"180.0, (59,), float32), 'theta_or': Box(-180.0, 180.0, (59,), float32), 'time_before_cooldown_line': Box(0, 96, (59,), "
"int32), 'time_before_cooldown_sub': Box(0, 3, (36,), int32), 'time_next_maintenance': Box(-1, 2147483647, (59,), int32), "
"'time_since_last_alarm': Box(-1, 2147483647, (1,), int32), 'time_since_last_alert': Box(-1, 2147483647, (10,), int32), "
"'time_since_last_attack': Box(-1, 2147483647, (10,), int32), 'timestep_overflow': Box(-2147483648, 2147483647, (59,), int32), "
"'topo_vect': Box(-1, 2, (177,), int32), 'total_number_of_alert': Box(0, 2147483647, (1,), int32), 'v_ex': Box(0.0, inf, "
"(59,), float32), 'v_or': Box(0.0, inf, (59,), float32), 'was_alarm_used_after_game_over': Discrete(2), "
"'was_alert_used_after_attack': Box(-1, 1, (10,), int32), 'year': Discrete(2100))")
"'time_since_last_attack': Box(-1, 2147483647, (10,), int32), 'timestep_overflow': Box(-2147483648, 2147483647, (59,), "
"int32), 'topo_vect': Box(-1, 2, (177,), int32), 'total_number_of_alert': Box(0, 2147483647, (1,), int32), "
"'v_ex': Box(0.0, inf, (59,), float32), 'v_or': Box(0.0, inf, (59,), float32), 'was_alarm_used_after_game_over': "
"Discrete(2), 'was_alert_used_after_attack': Box(-1, 1, (10,), int32), 'year': Discrete(2100))")
act = self.env.action_space()
act.raise_alert = [2]
act_gym = env_gym.action_space.to_gym(act)
act_str = act_gym.__str__()
assert act_str == ("OrderedDict([('change_bus', array([False, False, False, False, False, False, False, False, False,"
"\n False, False, False, False, False, False, False, False, False,\n "
"False, False, False, False, False, False, False, False, False,\n False, False, False, "
"False, False, False, False, False, False,\n False, False, False, False, False, False, False, "
"False, False,\n False, False, False, False, False, False, False, False, False,\n False, "
"False, False, False, False, False, False, False, False,\n False, False, False, False, False, False, "
"False, False, False,\n False, False, False, False, False, False, False, False, False,\n "
assert act_str == ("OrderedDict({'change_bus': array([False, False, False, False, False, False, False, False, False,\n "
"False, False, False, False, False, False, False, False, False,\n False, False, False, False, False, "
"False, False, False, False,\n False, False, False, False, False, False, False, False, False,\n "
"False, False, False, False, False, False, False, False, False,\n False, False, False, False, False, "
"False, False, False, False,\n False, False, False, False, False, False, False, False, False,\n "
"False, False, False, False, False, False, False, False, False,\n False, False, False, False, False, "
"False, False, False, False,\n False, False, False, False, False, False, False, False, False,\n "
"False, False, False, False, False, False, False, False, False,\n False, False, False, False, False, "
"False])), ('change_line_status', array([False, False, False, False, False, False, False, False, False,\n "
"False, False, False, False,\n False, False, False, False, False, False, False, False, False,\n "
"False, False, False, False, False, False, False, False, False,\n False, False, False, False, False, "
"False, False, False, False,\n False, False, False, False, False, False, False, False, False,\n "
"False, False, False, False, False, False, False, False, False,\n False, False, False, False, False, "
"False, False, False, False,\n False, False, False, False, False])), ('curtail', array([-1., -1., -1., "
"-1., -1., -1., -1., -1., -1., -1., -1., -1., -1.,\n -1., -1., -1., -1., -1., -1., -1., -1., -1.], "
"dtype=float32)), ('raise_alert', array([False, False, True, False, False, False, False, False, False,\n "
"False])), ('redispatch', array([0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0.,\n "
"0., 0., 0., 0., 0.], dtype=float32)), ('set_bus', array([0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, "
"0, 0, 0, 0, 0,\n 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,\n 0, 0, 0, 0, "
"0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,\n 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, "
"0, 0, 0, 0, 0,\n 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,\n 0, 0, 0, 0, 0, 0, "
"0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,\n 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, "
"0, 0,\n 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,\n 0], dtype=int32)), "
"('set_line_status', array([0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,\n 0, 0, 0, 0, 0, 0, "
"0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,\n 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], dtype=int32))])")
"False, False, False, False,\n False, False, False, False, False, False, False, False, False,\n "
"False, False, False, False, False, False]), 'change_line_status': array([False, False, False, False, False, "
"False, False, False, False,\n False, False, False, False, False, False, False, False, False,\n "
"False, False, False, False, False, False, False, False, False,\n False, False, False, False, False, False, "
"False, False, False,\n False, False, False, False, False, False, False, False, False,\n "
"False, False, False, False, False, False, False, False, False,\n False, False, False, False, False]), "
"'curtail': array([-1., -1., -1., -1., -1., -1., -1., -1., -1., -1., -1., -1., -1.,\n -1., -1., -1., -1., "
"-1., -1., -1., -1., -1.], dtype=float32), 'raise_alert': array([False, False, True, False, False, False, False, "
"False, False,\n False]), 'redispatch': array([0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., "
"0., 0.,\n 0., 0., 0., 0., 0.], dtype=float32), 'set_bus': array([0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, "
"0, 0, 0, 0, 0, 0, 0, 0,\n 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,\n 0, 0, "
"0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,\n 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, "
"0, 0, 0, 0, 0, 0, 0, 0,\n 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,\n "
"0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,\n 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, "
"0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,\n 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,\n "
"0], dtype=int32), 'set_line_status': array([0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,\n "
"0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,\n 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], "
"dtype=int32)})")

def test_convert_alert_to_gym(self):
"""test i can create the env"""
Expand All @@ -167,7 +164,8 @@ def test_convert_alert_to_gym(self):
for el in env_gym.observation_space.spaces
]
)
size_th = 1718 # as of grid2Op 1.9.1 (where alerts are added)
size_th = 1792 # as of grid2Op 1.9.1 (where alerts are added)
# as of grid2Op 1.11.0 (where flexibility was added)
assert (
dim_obs_space == size_th
), f"Size should be {size_th} but is {dim_obs_space}"
Expand Down
4 changes: 2 additions & 2 deletions grid2op/tests/test_issue_418.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,8 @@ def test_seed(self):
obs = gymenv.reset(seed=42)
curt = np.array([1,1.,0.18852758,0.5537014,0.43770432,1])
curt = np.array([-1,-1.,0.18852758,0.5537014,0.43770432,-1])
year = 571
day = 9
year = 229
day = 13
# year = 1887
# day = 9

Expand Down

0 comments on commit f72adae

Please sign in to comment.