Skip to content

Commit

Permalink
fix some minor things, before handling actions [skip ci]
Browse files Browse the repository at this point in the history
Signed-off-by: DONNOT Benjamin <[email protected]>
  • Loading branch information
BDonnot committed Nov 25, 2024
1 parent 62f5428 commit e921057
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 17 deletions.
2 changes: 1 addition & 1 deletion docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
author = 'Benjamin Donnot'

# The full version, including alpha/beta/rc tags
release = '1.11.0.dev1'
release = '1.11.0.dev2'
version = '1.11'


Expand Down
16 changes: 6 additions & 10 deletions grid2op/Backend/backend.py
Original file line number Diff line number Diff line change
Expand Up @@ -1081,26 +1081,22 @@ def _runpf_with_diverging_exception(self, is_dc : bool) -> Optional[Exception]:
exc_me = None

try:
conv, exc_me = self.runpf(is_dc=is_dc) # run powerflow

# Check if loads/gens have been detached and if this is allowed, otherwise raise an error
# .. versionadded:: 1.11.0
if hasattr(self, "_get_topo_vect"):
topo_vect = self._get_topo_vect()
else:
topo_vect = self.get_topo_vect()

load_buses = topo_vect[self.load_pos_topo_vect]

cls = type(self)
topo_vect = self.get_topo_vect()
load_buses = topo_vect[cls.load_pos_topo_vect]
if not self.detachment_is_allowed and (load_buses == -1).any():
raise Grid2OpException(f"One or more loads were detached before powerflow in Backend {type(self).__name__}"
"but this is not allowed or not supported (Game Over)")

gen_buses = topo_vect[self.gen_pos_topo_vect]

gen_buses = topo_vect[cls.gen_pos_topo_vect]
if not self.detachment_is_allowed and (gen_buses == -1).any():
raise Grid2OpException(f"One or more generators were detached before powerflow in Backend {type(self).__name__}"
"but this is not allowed or not supported (Game Over)")

conv, exc_me = self.runpf(is_dc=is_dc) # run powerflow
except Grid2OpException as exc_:
exc_me = exc_

Expand Down
16 changes: 12 additions & 4 deletions grid2op/Space/GridObjects.py
Original file line number Diff line number Diff line change
Expand Up @@ -2040,7 +2040,16 @@ def assert_grid_correct_cls(cls):
if isinstance(cls.n_busbar_per_sub, (int, dt_int, np.int32, np.int64)):
cls.n_busbar_per_sub = dt_int(cls.n_busbar_per_sub)
else:
raise EnvError("Grid2op cannot handle a different number of busbar per substations at the moment.")
raise EnvError("Grid2op cannot handle a different number "
"of busbar per substations with provided input "
"(make sure `n_busbar_per_sub` is an int)")

if isinstance(cls.detachment_is_allowed, (bool, dt_bool)):
cls.detachment_is_allowed = dt_bool(cls.detachment_is_allowed)
else:
raise EnvError("Grid2op cannot handle disconnection of loads / generators "
"at the moment (make sure `detachment_is_allowed` "
"is a bool)")

if (cls.n_busbar_per_sub < 1).any():
raise EnvError(f"`n_busbar_per_sub` should be >= 1 found {cls.n_busbar_per_sub}")
Expand Down Expand Up @@ -3091,7 +3100,7 @@ def process_grid2op_compat(cls):
cls.n_busbar_per_sub = DEFAULT_N_BUSBAR_PER_SUB
res = True

if glop_ver < version.parse("1.11.0.dev0"):
if glop_ver < version.parse("1.11.0.dev2"):
# Detachment did not exist, default value should have
# no effect
cls.detachment_is_allowed = DEFAULT_ALLOW_DETACHMENT
Expand Down Expand Up @@ -4211,7 +4220,7 @@ class res(GridObjects):
elif dict_["detachment_is_allowed"] == "False":
cls.detachment_is_allowed = False
else:
raise ValueError(f"'detachment_is_allowed' (value: {dict_['detachment_is_allowed']}'')" +
raise ValueError(f"'detachment_is_allowed' (value: {dict_['detachment_is_allowed']}'')"
"could not be converted to Boolean ")
else: # Compatibility for older versions
cls.detachment_is_allowed = DEFAULT_ALLOW_DETACHMENT
Expand Down Expand Up @@ -4984,7 +4993,6 @@ class {cls.__name__}({cls._INIT_GRID_CLS.__name__}):
sub_info = {sub_info_str}
dim_topo = {cls.dim_topo}
detachment_is_allowed = {cls.detachment_is_allowed}
# to which substation is connected each element
load_to_subid = {load_to_subid_str}
Expand Down
2 changes: 1 addition & 1 deletion grid2op/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
Grid2Op
"""
__version__ = '1.11.0.dev1'
__version__ = '1.11.0.dev2'

__all__ = [
"Action",
Expand Down
3 changes: 2 additions & 1 deletion grid2op/gym_compat/box_gym_obsspace.py
Original file line number Diff line number Diff line change
Expand Up @@ -849,7 +849,8 @@ def get_indexes(self, key: str) -> Tuple[int, int]:
key = "redispatch" # "redispatch", "curtail", "set_storage"
start_, end_ = gym_env.action_space.get_indexes(key)
act[start_:end_] = np.random.uniform(high=1, low=-1, size=env.gen_redispatchable.sum())
# act only modifies the redispatch with the input given (here a uniform redispatching between -1 and 1)
# act only modifies the redispatch with the input given
# (here a uniform redispatching between -1 and 1)
"""
error_msg =(f"Impossible to use the grid2op action property \"{key}\""
Expand Down

0 comments on commit e921057

Please sign in to comment.