Skip to content

Commit

Permalink
Refact: Reduce Complexity of baseEnv.reset
Browse files Browse the repository at this point in the history
Signed-off-by: Xavier Weiss <[email protected]>
  • Loading branch information
DEUCE1957 committed Nov 23, 2024
1 parent 89bb2f5 commit 91383c6
Showing 1 changed file with 7 additions and 8 deletions.
15 changes: 7 additions & 8 deletions grid2op/Environment/baseEnv.py
Original file line number Diff line number Diff line change
Expand Up @@ -1463,20 +1463,19 @@ def set_id(self, id_: Union[int, str]) -> None:
def reset(self,
*,
seed: Union[int, None] = None,
options: RESET_OPTIONS_TYPING = None):
options: RESET_OPTIONS_TYPING = {}):
"""
Reset the base environment (set the appropriate variables to correct initialization).
It is (and must be) overloaded in other :class:`grid2op.Environment`
"""
if self.__closed:
raise EnvError("This environment is closed. You cannot use it anymore.")
if options is not None:
for el in options:
if el not in type(self).KEYS_RESET_OPTIONS:
raise EnvError(f"You tried to customize the `reset` call with some "
f"`options` using the key `{el}` which is invalid. "
f"Only keys in {sorted(list(type(self).KEYS_RESET_OPTIONS))} "
f"can be used.")
for el in options:
if el not in type(self).KEYS_RESET_OPTIONS:
raise EnvError(f"You tried to customize the `reset` call with some "
f"`options` using the key `{el}` which is invalid. "
f"Only keys in {sorted(list(type(self).KEYS_RESET_OPTIONS))} "
f"can be used.")

self.__is_init = True
# current = None is an indicator that this is the first step of the environment
Expand Down

0 comments on commit 91383c6

Please sign in to comment.