Skip to content

Commit 2f9d846

Browse files
committed
adding base tests for the reset options in the runner, need to test the init_state now
1 parent a0f1b44 commit 2f9d846

File tree

4 files changed

+552
-14
lines changed

4 files changed

+552
-14
lines changed

CHANGELOG.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,8 @@ Change Log
4545
- [BREAKING] for all the `Handler` (*eg* `CSVForecastHandler`) the method `set_max_iter` is
4646
now private (for the same reason as the `env.chronics_handler`). We do not recommend to
4747
use it (will likely have no effect). Prefer using `env.set_max_iter` instead.
48+
- [BREAKING] now the `runner.run()` method only accept kwargs argument
49+
(because it should always have been like this)
4850
- [FIXED] a bug in the `MultiFolder` and `MultifolderWithCache` leading to the wrong
4951
computation of `max_iter` on some corner cases
5052
- [ADDED] possibility to skip some step when calling `env.reset(..., options={"init ts": ...})`

grid2op/Runner/aux_fun.py

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99
import copy
1010
import time
11-
11+
import warnings
1212
import numpy as np
1313

1414
from grid2op.Environment import Environment
@@ -51,11 +51,6 @@ def _aux_one_process_parrallel(
5151
reset_options=None,
5252
):
5353
"""this is out of the runner, otherwise it does not work on windows / macos"""
54-
# chronics_handler = ChronicsHandler(
55-
# chronicsClass=runner.gridStateclass,
56-
# path=runner.path_chron,
57-
# **runner.gridStateclass_kwargs
58-
# )
5954
parameters = copy.deepcopy(runner.parameters)
6055
nb_episode_this_process = len(episode_this_process)
6156
res = [(None, None, None) for _ in range(nb_episode_this_process)]

grid2op/Runner/runner.py

Lines changed: 24 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -29,18 +29,20 @@
2929
from grid2op.dtypes import dt_float
3030
from grid2op.Opponent import BaseOpponent, NeverAttackBudget
3131
from grid2op.operator_attention import LinearAttentionBudget
32+
from grid2op.Space import DEFAULT_N_BUSBAR_PER_SUB
33+
from grid2op.Episode import EpisodeData
34+
# on windows if i start using sequential, i need to continue using sequential
35+
# if i start using parallel i need to continue using parallel
36+
# so i force the usage of the "starmap" stuff even if there is one process on windows
37+
from grid2op._glop_platform_info import _IS_WINDOWS, _IS_LINUX, _IS_MACOS
38+
3239
from grid2op.Runner.aux_fun import (
3340
_aux_run_one_episode,
3441
_aux_make_progress_bar,
3542
_aux_one_process_parrallel,
3643
)
3744
from grid2op.Runner.basic_logger import DoNothingLog, ConsoleLog
38-
from grid2op.Episode import EpisodeData
3945

40-
# on windows if i start using sequential, i need to continue using sequential
41-
# if i start using parallel i need to continue using parallel
42-
# so i force the usage of the "starmap" stuff even if there is one process on windows
43-
from grid2op._glop_platform_info import _IS_WINDOWS, _IS_LINUX, _IS_MACOS
4446

4547
runner_returned_type = Union[Tuple[str, str, float, int, int],
4648
Tuple[str, str, float, int, int, EpisodeData],
@@ -57,7 +59,6 @@
5759

5860
KEY_TIME_SERIE_ID = "time serie id"
5961

60-
6162
class Runner(object):
6263
"""
6364
A runner is a utility tool that allows to run simulations more easily.
@@ -246,7 +247,7 @@ def __init__(
246247
init_env_path: str,
247248
init_grid_path: str,
248249
path_chron, # path where chronics of injections are stored
249-
n_busbar=2,
250+
n_busbar=DEFAULT_N_BUSBAR_PER_SUB,
250251
name_env="unknown",
251252
parameters_path=None,
252253
names_chronics_to_backend=None,
@@ -918,6 +919,7 @@ def _run_sequential(
918919
) = self.run_one_episode(
919920
path_save=path_save,
920921
indx=ep_id,
922+
episode_id=ep_id,
921923
pbar=next_pbar[0],
922924
env_seed=env_seed,
923925
agent_seed=agt_seed,
@@ -1184,6 +1186,7 @@ def _clean_up(self):
11841186
def run(
11851187
self,
11861188
nb_episode,
1189+
*, # force kwargs
11871190
nb_process=1,
11881191
path_save=None,
11891192
max_iter=None,
@@ -1452,7 +1455,13 @@ def run(
14521455
"either use dictionnary, grid2op actions or list / tuple of actions.")
14531456

14541457
if reset_options is not None:
1455-
if isinstance(reset_options, (dict)):
1458+
if isinstance(reset_options, dict):
1459+
for k in reset_options:
1460+
if not k in self.envClass.KEYS_RESET_OPTIONS:
1461+
raise RuntimeError("Wehn specifying `reset options` all keys of the dictionary should "
1462+
"be compatible with the available reset options of your environment "
1463+
f"class. You provided the key \"{k}\" for the provided dictionary but"
1464+
f"possible keys are limited to {self.envClass.KEYS_RESET_OPTIONS}.")
14561465
# user provided one initial state, I copy it to all
14571466
# evaluation
14581467
reset_options = [reset_options.copy() for _ in range(nb_episode)]
@@ -1469,6 +1478,13 @@ def run(
14691478
raise RuntimeError("When specifying `reset_options` kwargs with a list (or a tuple) "
14701479
"it should be a list (or a tuple) of dictionary or BaseAction. "
14711480
f"You provided {type(el)} at position {i}.")
1481+
for i, el in enumerate(reset_options):
1482+
for k in el:
1483+
if not k in self.envClass.KEYS_RESET_OPTIONS:
1484+
raise RuntimeError("Wehn specifying `reset options` all keys of the dictionary should "
1485+
"be compatible with the available reset options of your environment "
1486+
f"class. You provided the key \"{k}\" for the {i}th dictionary but"
1487+
f"possible keys are limited to {self.envClass.KEYS_RESET_OPTIONS}.")
14721488
else:
14731489
raise RuntimeError("When using `reset_options` in the runner, you should make sure to use "
14741490
"either use dictionnary, grid2op actions or list / tuple of actions.")

0 commit comments

Comments
 (0)