Skip to content

Commit c167806

Browse files
committed
fixing conflict with master [skip ci]
Signed-off-by: DONNOT Benjamin <[email protected]>
2 parents 062b5d8 + 3f71f65 commit c167806

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

46 files changed

+1886
-372
lines changed

CHANGELOG.rst

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,16 @@ Native multi agents support:
133133
- [FIXED] deprecated call to `tostring_rgb` (replaced `tostring_argb`) in the env.render function.
134134
- [FIXED] warnings not properly issued in the AAA test when backend failed to call
135135
`can_handle_XXX` functions (*eg* `can_handle_more_than_2_busbar()` or `can_handle_detachment()`)
136+
- [FIXED] an issue with `obs.get_forecast_env` with changeNothing and DoNothingHandler time series
137+
- [FIXED] a bug in updating the shunt in PandaPowerBackend (depdending on pandas version)
138+
- [FIXED] a bug when action that reconnect loads, storage units or shunts are done
139+
in the "obs.simulate" (results could depend from previous "obs.simulate" calls)
140+
- [FIXED] a bug in "obs.simulate" and "obs.get_forecast_env" : when a line was disconnected
141+
and the user tried to reconnect it (without specifying on which bus) it could do something
142+
different than "env.step" (with the same action)
143+
- [FIXED] a powerflow is run when the environment is first created even before the initial "env.step"
144+
function is called. This is to ensure proper behaviour if env is used without being reset.
145+
- [FIXED] no error was catched if the backend could not properly apply the action sent by the environment.
136146
- [ADDED] possibility to set the "thermal limits" when calling `env.reset(..., options={"thermal limit": xxx})`
137147
- [ADDED] possibility to retrieve some structural information about elements with
138148
with `gridobj.get_line_info(...)`, `gridobj.get_load_info(...)`, `gridobj.get_gen_info(...)`
@@ -147,6 +157,7 @@ Native multi agents support:
147157
generators is not met (see `params.STOP_EP_IF_SLACK_BREAK_CONSTRAINTS`)
148158
- [ADDED] possibility to set the initial time stamp of the observation in the `env.reset`
149159
kwargs by using `env.reset(..., options={"init datetime": XXX})`
160+
- [ADDED] the `ChangeNothing` time series class now supports forecast
150161
- [IMPROVED] possibility to set the injections values with names
151162
to be consistent with other way to set the actions (*eg* set_bus)
152163
- [IMPROVED] error messages when creating an action which changes the injections
@@ -175,6 +186,7 @@ Native multi agents support:
175186
- [IMPROVED] the function `action.get_topological_impact(...)` has now a "caching" mechanism
176187
that allows not to recompute it over and over again (this is internal API please do not change
177188
it... unless you know what you are doing)
189+
- [IMPROVED] `ForecastEnv` is now part of the public API.
178190

179191
[1.10.5] - 2025-03-07
180192
------------------------

getting_started/grid2op

Lines changed: 0 additions & 1 deletion
This file was deleted.

grid2op/Action/_backendAction.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -881,6 +881,9 @@ def _assign_0_to_disco_el(self) -> None:
881881
Do not consider disconnected elements are modified for there active / reactive / voltage values
882882
"""
883883
cls = type(self)
884+
if not cls.detachment_is_allowed:
885+
# is detachment is not allowed, this should not happen
886+
return
884887
gen_changed = self.current_topo.changed[cls.gen_pos_topo_vect]
885888
gen_bus = self.current_topo.values[cls.gen_pos_topo_vect]
886889
self.prod_p.force_unchanged(gen_changed, gen_bus)

grid2op/Action/baseAction.py

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
from grid2op.typing_variables import DICT_ACT_TYPING
2424
from grid2op.dtypes import dt_int, dt_bool, dt_float
2525
from grid2op.Exceptions import *
26-
from grid2op.Space import GridObjects
26+
from grid2op.Space import GridObjects, GRID2OP_CURRENT_VERSION_STR
2727

2828
# TODO time delay somewhere (eg action is implemented after xxx timestep, and not at the time where it's proposed)
2929

@@ -471,10 +471,10 @@ def __init__(self, _names_chronics_to_backend: Optional[Dict[Literal["loads", "p
471471
# shunts
472472
if cls.shunts_data_available:
473473
self.shunt_p = np.full(
474-
shape=cls.n_shunt, fill_value=np.NaN, dtype=dt_float
474+
shape=cls.n_shunt, fill_value=np.nan, dtype=dt_float
475475
)
476476
self.shunt_q = np.full(
477-
shape=cls.n_shunt, fill_value=np.NaN, dtype=dt_float
477+
shape=cls.n_shunt, fill_value=np.nan, dtype=dt_float
478478
)
479479
self.shunt_bus = np.full(shape=cls.n_shunt, fill_value=0, dtype=dt_int)
480480
else:
@@ -1805,8 +1805,8 @@ def reset(self):
18051805

18061806
# shunts
18071807
if type(self).shunts_data_available:
1808-
self.shunt_p[:] = np.NaN
1809-
self.shunt_q[:] = np.NaN
1808+
self.shunt_p[:] = np.nan
1809+
self.shunt_q[:] = np.nan
18101810
self.shunt_bus[:] = 0
18111811

18121812
# alarm
@@ -2425,7 +2425,7 @@ def _digest_storage(self, dict_):
24252425
except IllegalAction as exc_:
24262426
cls = type(self)
24272427
# only raise the error if I am not in compat mode
2428-
if cls.glop_version == grid2op.__version__:
2428+
if cls.glop_version == GRID2OP_CURRENT_VERSION_STR:
24292429
raise exc_
24302430
else:
24312431
# TODO be more specific on the version
@@ -2439,7 +2439,7 @@ def _digest_curtailment(self, dict_):
24392439
except IllegalAction as exc_:
24402440
cls = type(self)
24412441
# only raise the error if I am not in compat mode
2442-
if cls.glop_version == grid2op.__version__:
2442+
if cls.glop_version == GRID2OP_CURRENT_VERSION_STR:
24432443
raise exc_
24442444
else:
24452445
# TODO be more specific on the version
@@ -3990,7 +3990,7 @@ def _aux_effect_on_load(self, load_id):
39903990
)
39913991
if load_id < 0:
39923992
raise Grid2OpException(f"`load_id` should be positive.")
3993-
res = {"new_p": np.NaN, "new_q": np.NaN, "change_bus": False, "set_bus": 0}
3993+
res = {"new_p": np.nan, "new_q": np.nan, "change_bus": False, "set_bus": 0}
39943994
if "load_p" in self._dict_inj:
39953995
res["new_p"] = self._dict_inj["load_p"][load_id]
39963996
if "load_q" in self._dict_inj:
@@ -4008,7 +4008,7 @@ def _aux_effect_on_gen(self, gen_id):
40084008
)
40094009
if gen_id < 0:
40104010
raise Grid2OpException(f"`gen_id` should be positive.")
4011-
res = {"new_p": np.NaN, "new_v": np.NaN, "set_bus": 0, "change_bus": False}
4011+
res = {"new_p": np.nan, "new_v": np.nan, "set_bus": 0, "change_bus": False}
40124012
if "prod_p" in self._dict_inj:
40134013
res["new_p"] = self._dict_inj["prod_p"][gen_id]
40144014
if "prod_v" in self._dict_inj:
@@ -4051,7 +4051,7 @@ def _aux_effect_on_storage(self, storage_id):
40514051
)
40524052
if storage_id < 0:
40534053
raise Grid2OpException(f"`storage_id` should be positive.")
4054-
res = {"power": np.NaN, "set_bus": 0, "change_bus": False}
4054+
res = {"power": np.nan, "set_bus": 0, "change_bus": False}
40554055
my_id = self.storage_pos_topo_vect[storage_id]
40564056
res["change_bus"] = self._change_bus_vect[my_id]
40574057
res["set_bus"] = self._set_topo_vect[my_id]
@@ -4266,7 +4266,7 @@ def get_load_modif(self) -> Tuple[np.ndarray, np.ndarray, np.ndarray, np.ndarray
42664266
New bus of the loads, affected with "change_bus" command
42674267
"""
42684268
cls = type(self)
4269-
load_p = np.full(cls.n_load, fill_value=np.NaN, dtype=dt_float)
4269+
load_p = np.full(cls.n_load, fill_value=np.nan, dtype=dt_float)
42704270
if "load_p" in self._dict_inj:
42714271
load_p[:] = self._dict_inj["load_p"]
42724272
load_q = 1.0 * load_p
@@ -4295,7 +4295,7 @@ def get_gen_modif(self) -> Tuple[np.ndarray, np.ndarray, np.ndarray, np.ndarray]
42954295
42964296
"""
42974297
cls = type(self)
4298-
gen_p = np.full(cls.n_gen, fill_value=np.NaN, dtype=dt_float)
4298+
gen_p = np.full(cls.n_gen, fill_value=np.nan, dtype=dt_float)
42994299
if "prod_p" in self._dict_inj:
43004300
gen_p[:] = self._dict_inj["prod_p"]
43014301
gen_v = 1.0 * gen_p

grid2op/Action/serializableActionSpace.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1517,7 +1517,7 @@ def _aux_get_back_to_ref_state_curtail(self, res, obs):
15171517
)
15181518
return
15191519

1520-
curtail = np.full(obs.n_gen, fill_value=np.NaN)
1520+
curtail = np.full(obs.n_gen, fill_value=np.nan)
15211521
curtail[is_curtailed] = 1.0
15221522
act = self.actionClass()
15231523
act.curtail = curtail

grid2op/Agent/greedyAgent.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ def act(self, observation: BaseObservation, reward: float, done : bool=False) ->
6161
self.tested_action = self._get_tested_action(observation)
6262
if len(self.tested_action) > 1:
6363
self.resulting_rewards = np.full(
64-
shape=len(self.tested_action), fill_value=np.NaN, dtype=dt_float
64+
shape=len(self.tested_action), fill_value=np.nan, dtype=dt_float
6565
)
6666
for i, action in enumerate(self.tested_action):
6767
(

grid2op/Backend/backend.py

Lines changed: 19 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
from abc import ABC, abstractmethod
1616
import numpy as np
1717
import pandas as pd
18-
from typing import Tuple, Optional, Any, Dict, Union
18+
from typing import Tuple, Optional, Any, Dict, Type, Union
1919

2020
try:
2121
from typing import Self
@@ -36,6 +36,9 @@
3636
Grid2OpException,
3737
)
3838
from grid2op.Space import GridObjects, ElTypeInfo, DEFAULT_N_BUSBAR_PER_SUB, DEFAULT_ALLOW_DETACHMENT
39+
import grid2op.Observation # for type hints
40+
import grid2op.Action # for type hints
41+
import grid2op.Action._BackendAction # for type hints
3942

4043

4144
# TODO method to get V and theta at each bus, could be in the same shape as check_kirchoff
@@ -116,8 +119,8 @@ class Backend(GridObjects, ABC):
116119
IS_BK_CONVERTER : bool = False
117120

118121
# action to set me
119-
my_bk_act_class : "Optional[grid2op.Action._backendAction._BackendAction]" = None
120-
_complete_action_class : "Optional[grid2op.Action.CompleteAction]" = None
122+
my_bk_act_class : "Optional[Type[grid2op.Action._BackendAction._BackendAction]]" = None
123+
_complete_action_class : "Optional[Type[grid2op.Action.CompleteAction]]" = None
121124

122125
ERR_INIT_POWERFLOW : str = "Power cannot be computed on the first time step, please check your data."
123126
ERR_DETACHMENT : str = ("One or more {} were isolated from the grid "
@@ -1906,8 +1909,8 @@ def get_action_to_set(self) -> "grid2op.Action.CompleteAction":
19061909
sh_conn = bus_s > 0
19071910
p_s[sh_conn] *= (self._sh_vnkv[sh_conn] / sh_v[sh_conn]) ** 2
19081911
q_s[sh_conn] *= (self._sh_vnkv[sh_conn] / sh_v[sh_conn]) ** 2
1909-
p_s[bus_s == -1] = np.NaN
1910-
q_s[bus_s == -1] = np.NaN
1912+
p_s[bus_s == -1] = np.nan
1913+
q_s[bus_s == -1] = np.nan
19111914
dict_["shunt"]["shunt_p"] = p_s
19121915
dict_["shunt"]["shunt_q"] = q_s
19131916

@@ -1920,7 +1923,7 @@ def get_action_to_set(self) -> "grid2op.Action.CompleteAction":
19201923

19211924
def update_from_obs(self,
19221925
obs: "grid2op.Observation.CompleteObservation",
1923-
force_update: Optional[bool]=False):
1926+
force_update: Optional[bool]=False) -> "grid2op.Action._BackendAction._BackendAction":
19241927
"""
19251928
Takes an observation as input and update the internal state of `self` to match the state of the backend
19261929
that produced this observation.
@@ -1954,23 +1957,23 @@ def update_from_obs(self,
19541957
)
19551958

19561959
cls = type(self)
1957-
backend_action = cls.my_bk_act_class()
1960+
backend_action : "grid2op.Action._BackendAction._BackendAction" = cls.my_bk_act_class()
19581961
act = cls._complete_action_class()
19591962
line_status = self._aux_get_line_status_to_set(obs.line_status)
19601963
# skip the action part and update directly the backend action !
19611964
dict_ = {
19621965
"set_bus": obs.topo_vect,
19631966
"set_line_status": line_status,
19641967
"injection": {
1965-
"prod_p": obs.prod_p,
1966-
"prod_v": obs.prod_v,
1967-
"load_p": obs.load_p,
1968-
"load_q": obs.load_q,
1968+
"prod_p": obs._get_gen_p_for_forecasts(),
1969+
"prod_v": obs._get_gen_v_for_forecasts(),
1970+
"load_p": obs._get_load_p_for_forecasts(),
1971+
"load_q": obs._get_load_q_for_forecasts(),
19691972
},
19701973
}
19711974

19721975
if cls.shunts_data_available and type(obs).shunts_data_available:
1973-
if cls.n_shunt > 0 and "_shunt_bus" not in type(obs).attr_list_set:
1976+
if cls.n_shunt > 0 and "_shunt_bus" not in (type(obs).attr_list_set | set(type(obs).attr_list_json)):
19741977
raise BackendError(
19751978
"Impossible to set the backend to the state given by the observation: shunts data "
19761979
"are not present in the observation."
@@ -1982,15 +1985,17 @@ def update_from_obs(self,
19821985
mults = (self._sh_vnkv / obs._shunt_v) ** 2
19831986
sh_p = obs._shunt_p * mults
19841987
sh_q = obs._shunt_q * mults
1985-
sh_p[~shunt_co] = np.NaN
1986-
sh_q[~shunt_co] = np.NaN
1988+
sh_p[~shunt_co] = np.nan
1989+
sh_q[~shunt_co] = np.nan
19871990
dict_["shunt"]["shunt_p"] = sh_p
19881991
dict_["shunt"]["shunt_q"] = sh_q
19891992
elif cls.shunts_data_available and not type(obs).shunts_data_available:
19901993
warnings.warn("Backend supports shunt but not the observation. This behaviour is non standard.")
19911994
act.update(dict_)
19921995
backend_action += act
19931996
self.apply_action(backend_action)
1997+
backend_action.reset() # already processed by the backend
1998+
return backend_action
19941999

19952000
def assert_grid_correct(self, _local_dir_cls=None) -> None:
19962001
"""

grid2op/Backend/educPandaPowerBackend.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -351,7 +351,7 @@ def get_topo_vect(self) -> np.ndarray:
351351
352352
Function is verbose (~40 lines of code), but pretty straightforward.
353353
"""
354-
res = np.full(self.dim_topo, fill_value=np.NaN, dtype=dt_int)
354+
res = np.full(self.dim_topo, fill_value=np.nan, dtype=dt_int)
355355

356356
line_status = self.get_line_status()
357357

0 commit comments

Comments
 (0)