Skip to content

Commit f2398c0

Browse files
authored
Merge pull request #595 from BDonnot/master
Bump to version 1.10.1
2 parents be6acb2 + e18957b commit f2398c0

File tree

15 files changed

+435
-46
lines changed

15 files changed

+435
-46
lines changed

.circleci/config.yml

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,33 @@ jobs:
163163
cd /tmp
164164
grid2op.testinstall
165165
166+
legacy_lightsim:
167+
executor: python38
168+
resource_class: small
169+
steps:
170+
- checkout
171+
- run:
172+
command: |
173+
apt-get update
174+
apt-get install -y coinor-cbc
175+
- run: python -m pip install virtualenv
176+
- run: python -m virtualenv venv_test
177+
- run:
178+
command: |
179+
source venv_test/bin/activate
180+
python -m pip install -U pip setuptools wheel
181+
python -m pip install -U lightsim2grid==0.5.3 gymnasium "numpy<1.22"
182+
- run:
183+
command: |
184+
source venv_test/bin/activate
185+
python -m pip install -e .
186+
pip freeze
187+
- run:
188+
command: |
189+
source venv_test/bin/activate
190+
export _GRID2OP_FORCE_TEST=1
191+
python -m unittest grid2op/tests/test_basic_env_ls.py
192+
166193
install39:
167194
executor: python39
168195
resource_class: small
@@ -313,6 +340,7 @@ workflows:
313340
test:
314341
jobs:
315342
- test
343+
- legacy_lightsim
316344
install:
317345
jobs:
318346
- install38

CHANGELOG.rst

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,14 @@ Change Log
3131
- [???] "asynch" multienv
3232
- [???] properly model interconnecting powerlines
3333

34+
[1.10.1] - 2024-03-xx
35+
----------------------
36+
- [FIXED] issue https://github.com/rte-france/Grid2Op/issues/593
37+
- [FIXED] backward compatibility issues with "oldest" lightsim2grid versions
38+
(now tested in basic settings)
39+
- [ADDED] a "compact" way to store the data in the Runner
40+
- [IMPROVED] the "`train_val_split`" functions, now more names (for the folders)
41+
can be used
3442

3543
[1.10.0] - 2024-03-06
3644
----------------------

docs/conf.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
author = 'Benjamin Donnot'
2323

2424
# The full version, including alpha/beta/rc tags
25-
release = '1.10.0'
25+
release = '1.10.1.dev0'
2626
version = '1.10'
2727

2828

grid2op/Backend/backend.py

Lines changed: 23 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1844,8 +1844,9 @@ def get_action_to_set(self) -> "grid2op.Action.CompleteAction":
18441844
p_s, q_s, sh_v, bus_s = self.shunt_info()
18451845
dict_["shunt"] = {"shunt_bus": bus_s}
18461846
if (bus_s >= 1).sum():
1847-
p_s *= (self._sh_vnkv / sh_v) ** 2
1848-
q_s *= (self._sh_vnkv / sh_v) ** 2
1847+
sh_conn = bus_s > 0
1848+
p_s[sh_conn] *= (self._sh_vnkv[sh_conn] / sh_v[sh_conn]) ** 2
1849+
q_s[sh_conn] *= (self._sh_vnkv[sh_conn] / sh_v[sh_conn]) ** 2
18491850
p_s[bus_s == -1] = np.NaN
18501851
q_s[bus_s == -1] = np.NaN
18511852
dict_["shunt"]["shunt_p"] = p_s
@@ -1944,21 +1945,28 @@ def assert_grid_correct(self) -> None:
19441945
from grid2op.Action import CompleteAction
19451946
from grid2op.Action._backendAction import _BackendAction
19461947

1947-
if self._missing_two_busbars_support_info:
1948-
warnings.warn("The backend implementation you are using is probably too old to take advantage of the "
1949-
"new feature added in grid2op 1.10.0: the possibility "
1950-
"to have more than 2 busbars per substations (or not). "
1951-
"To silence this warning, you can modify the `load_grid` implementation "
1952-
"of your backend and either call:\n"
1953-
"- self.can_handle_more_than_2_busbar if the current implementation "
1954-
" can handle more than 2 busbsars OR\n"
1955-
"- self.cannot_handle_more_than_2_busbar if not."
1956-
"\nAnd of course, ideally, if the current implementation "
1957-
"of your backend cannot "
1958-
"handle more than 2 busbars per substation, then change it :-)\n"
1959-
"Your backend will behave as if it did not support it.")
1948+
if hasattr(self, "_missing_two_busbars_support_info"):
1949+
if self._missing_two_busbars_support_info:
1950+
warnings.warn("The backend implementation you are using is probably too old to take advantage of the "
1951+
"new feature added in grid2op 1.10.0: the possibility "
1952+
"to have more than 2 busbars per substations (or not). "
1953+
"To silence this warning, you can modify the `load_grid` implementation "
1954+
"of your backend and either call:\n"
1955+
"- self.can_handle_more_than_2_busbar if the current implementation "
1956+
" can handle more than 2 busbsars OR\n"
1957+
"- self.cannot_handle_more_than_2_busbar if not."
1958+
"\nAnd of course, ideally, if the current implementation "
1959+
"of your backend cannot "
1960+
"handle more than 2 busbars per substation, then change it :-)\n"
1961+
"Your backend will behave as if it did not support it.")
1962+
self._missing_two_busbars_support_info = False
1963+
self.n_busbar_per_sub = DEFAULT_N_BUSBAR_PER_SUB
1964+
else:
19601965
self._missing_two_busbars_support_info = False
19611966
self.n_busbar_per_sub = DEFAULT_N_BUSBAR_PER_SUB
1967+
warnings.warn("Your backend is missing the `_missing_two_busbars_support_info` "
1968+
"attribute. This is known issue in lightims2grid <= 0.7.5. Please "
1969+
"upgrade your backend. This will raise an error in the future.")
19621970

19631971
orig_type = type(self)
19641972
if orig_type.my_bk_act_class is None:

grid2op/Environment/environment.py

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ class Environment(BaseEnv):
7373
7474
"""
7575

76-
REGEX_SPLIT = r"^[a-zA-Z0-9]*$"
76+
REGEX_SPLIT = r"^[a-zA-Z0-9_\\.]*$"
7777

7878
def __init__(
7979
self,
@@ -1362,21 +1362,22 @@ def train_val_split(
13621362
13631363
"""
13641364
# define all the locations
1365-
if re.match(self.REGEX_SPLIT, add_for_train) is None:
1365+
cls = type(self)
1366+
if re.match(cls.REGEX_SPLIT, add_for_train) is None:
13661367
raise EnvError(
13671368
f"The suffixes you can use for training data (add_for_train) "
1368-
f'should match the regex "{self.REGEX_SPLIT}"'
1369+
f'should match the regex "{cls.REGEX_SPLIT}"'
13691370
)
1370-
if re.match(self.REGEX_SPLIT, add_for_val) is None:
1371+
if re.match(cls.REGEX_SPLIT, add_for_val) is None:
13711372
raise EnvError(
13721373
f"The suffixes you can use for validation data (add_for_val)"
1373-
f'should match the regex "{self.REGEX_SPLIT}"'
1374+
f'should match the regex "{cls.REGEX_SPLIT}"'
13741375
)
13751376
if add_for_test is not None:
1376-
if re.match(self.REGEX_SPLIT, add_for_test) is None:
1377+
if re.match(cls.REGEX_SPLIT, add_for_test) is None:
13771378
raise EnvError(
13781379
f"The suffixes you can use for test data (add_for_test)"
1379-
f'should match the regex "{self.REGEX_SPLIT}"'
1380+
f'should match the regex "{cls.REGEX_SPLIT}"'
13801381
)
13811382

13821383
if add_for_test is None and test_scen_id is not None:

grid2op/MakeEnv/MakeFromPath.py

Lines changed: 25 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -556,21 +556,22 @@ def make_from_dataset_path(
556556
default_chronics_kwargs = {
557557
"path": chronics_path_abs,
558558
"chronicsClass": chronics_class_cfg,
559-
# "gridvalueClass": grid_value_class_cfg,
560559
}
561560

561+
dfkwargs_cfg = {} # in the config
562562
if "data_feeding_kwargs" in config_data and config_data["data_feeding_kwargs"] is not None:
563563
dfkwargs_cfg = config_data["data_feeding_kwargs"]
564564
for el in dfkwargs_cfg:
565565
default_chronics_kwargs[el] = dfkwargs_cfg[el]
566566

567-
data_feeding_kwargs = _get_default_aux(
567+
data_feeding_kwargs_user_prov = _get_default_aux(
568568
"data_feeding_kwargs",
569569
kwargs,
570570
defaultClassApp=dict,
571571
defaultinstance=default_chronics_kwargs,
572572
msg_error=ERR_MSG_KWARGS["data_feeding_kwargs"],
573573
)
574+
data_feeding_kwargs = data_feeding_kwargs_user_prov.copy()
574575
for el in default_chronics_kwargs:
575576
if el not in data_feeding_kwargs:
576577
data_feeding_kwargs[el] = default_chronics_kwargs[el]
@@ -586,7 +587,9 @@ def make_from_dataset_path(
586587
isclass=True,
587588
)
588589
if (
589-
(chronics_class_used != ChangeNothing) and (chronics_class_used != FromNPY) and (chronics_class_used != FromChronix2grid)
590+
((chronics_class_used != ChangeNothing) and
591+
(chronics_class_used != FromNPY) and
592+
(chronics_class_used != FromChronix2grid))
590593
) and exc_chronics is not None:
591594
raise EnvError(
592595
f"Impossible to find the chronics for your environment. Please make sure to provide "
@@ -599,7 +602,25 @@ def make_from_dataset_path(
599602
# parameters is not given in the "make" function but present in the config file
600603
if "gridvalueClass" not in data_feeding_kwargs:
601604
data_feeding_kwargs["gridvalueClass"] = grid_value_class_cfg
602-
605+
606+
607+
# code bellow is added to fix
608+
# https://github.com/rte-france/Grid2Op/issues/593
609+
import inspect
610+
possible_params = inspect.signature(data_feeding_kwargs["gridvalueClass"].__init__).parameters
611+
data_feeding_kwargs_res = data_feeding_kwargs.copy()
612+
for el in data_feeding_kwargs:
613+
if el == "gridvalueClass":
614+
continue
615+
if el == "chronicsClass":
616+
continue
617+
if el not in possible_params:
618+
# if it's in the config but is not supported by the
619+
# user, then we ignore it
620+
# see https://github.com/rte-france/Grid2Op/issues/593
621+
if el in dfkwargs_cfg and not el in data_feeding_kwargs_user_prov:
622+
del data_feeding_kwargs_res[el]
623+
data_feeding_kwargs = data_feeding_kwargs_res
603624
# now build the chronics handler
604625
data_feeding = _get_default_aux(
605626
"data_feeding",

grid2op/MakeEnv/__init__.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,15 @@
77
"change_local_dir",
88
"list_available_test_env",
99
"update_env",
10-
# deprecated in v 0.8.0
11-
"make_old",
1210
]
11+
try:
12+
from grid2op.MakeEnv.MakeOld import make_old
13+
14+
# deprecated in v 0.8.0
15+
__all__.append("make_old")
16+
except ImportError:
17+
pass
1318

14-
from grid2op.MakeEnv.MakeOld import make_old
1519
from grid2op.MakeEnv.MakeFromPath import make_from_dataset_path
1620
from grid2op.MakeEnv.Make import make
1721
from grid2op.MakeEnv.UserUtils import (

grid2op/Runner/runner.py

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -615,12 +615,32 @@ def __init__(
615615

616616
self.__used = False
617617

618+
def _make_new_backend(self):
619+
try:
620+
res = self.backendClass(**self._backend_kwargs)
621+
except TypeError:
622+
# for backward compatibility, some backend might not
623+
# handle full kwargs (that might be added later)
624+
import inspect
625+
possible_params = inspect.signature(self.backendClass.__init__).parameters
626+
this_kwargs = {}
627+
for el in self._backend_kwargs:
628+
if el in possible_params:
629+
this_kwargs[el] = self._backend_kwargs[el]
630+
else:
631+
warnings.warn("Runner: your backend does not support the kwargs "
632+
f"`{el}={self._backend_kwargs[el]}`. This usually "
633+
"means it is outdated. Please upgrade it.")
634+
res = self.backendClass(**this_kwargs)
635+
return res
636+
618637
def _new_env(self, chronics_handler, parameters) -> Tuple[BaseEnv, BaseAgent]:
619638
# the same chronics_handler is used for all the environments.
620639
# make sure to "reset" it properly
621640
# (this is handled elsewhere in case of "multi chronics")
622641
if not self.chronics_handler.chronicsClass.MULTI_CHRONICS:
623642
self.chronics_handler.next_chronics()
643+
backend = self._make_new_backend()
624644
with warnings.catch_warnings():
625645
warnings.filterwarnings("ignore")
626646
res = self.envClass.init_obj_from_kwargs(
@@ -629,7 +649,7 @@ def _new_env(self, chronics_handler, parameters) -> Tuple[BaseEnv, BaseAgent]:
629649
init_env_path=self.init_env_path,
630650
init_grid_path=self.init_grid_path,
631651
chronics_handler=chronics_handler,
632-
backend=self.backendClass(**self._backend_kwargs),
652+
backend=backend,
633653
parameters=parameters,
634654
name=self.name_env,
635655
names_chronics_to_backend=self.names_chronics_to_backend,

grid2op/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
Grid2Op
1212
1313
"""
14-
__version__ = '1.10.0'
14+
__version__ = '1.10.1.dev0'
1515

1616
__all__ = [
1717
"Action",

grid2op/tests/aaa_test_backend_interface.py

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1593,9 +1593,10 @@ def test_30_n_busbar_per_sub_ok(self):
15931593
15941594
"""
15951595
self.skip_if_needed()
1596-
backend = self.aux_make_backend(n_busbar=3)
1596+
n_busbar = 3
1597+
backend = self.aux_make_backend(n_busbar=n_busbar)
15971598
cls = type(backend)
1598-
if cls.n_busbar_per_sub != 3:
1599+
if cls.n_busbar_per_sub != n_busbar:
15991600
self.skipTest("Your backend does not support more than 2 busbars.")
16001601

16011602
res = backend.runpf(is_dc=False)
@@ -1604,11 +1605,11 @@ def test_30_n_busbar_per_sub_ok(self):
16041605

16051606
# line or
16061607
line_id = 0
1607-
busbar_id = 3
1608+
busbar_id = n_busbar
16081609
backend.reset(self.get_path(), self.get_casefile())
1609-
action = type(backend)._complete_action_class()
1610+
action = cls._complete_action_class()
16101611
action.update({"set_bus": {"lines_or_id": [(line_id, busbar_id)]}})
1611-
bk_act = type(backend).my_bk_act_class()
1612+
bk_act = cls.my_bk_act_class()
16121613
bk_act += action
16131614
backend.apply_action(bk_act)
16141615
res = backend.runpf(is_dc=False)
@@ -1620,11 +1621,11 @@ def test_30_n_busbar_per_sub_ok(self):
16201621

16211622
# line ex
16221623
line_id = 0
1623-
busbar_id = 3
1624+
busbar_id = n_busbar
16241625
backend.reset(self.get_path(), self.get_casefile())
1625-
action = type(backend)._complete_action_class()
1626+
action = cls._complete_action_class()
16261627
action.update({"set_bus": {"lines_ex_id": [(line_id, busbar_id)]}})
1627-
bk_act = type(backend).my_bk_act_class()
1628+
bk_act = cls.my_bk_act_class()
16281629
bk_act += action
16291630
backend.apply_action(bk_act)
16301631
res = backend.runpf(is_dc=False)
@@ -1636,7 +1637,7 @@ def test_30_n_busbar_per_sub_ok(self):
16361637

16371638
# load
16381639
backend.reset(self.get_path(), self.get_casefile())
1639-
busbar_id = 3
1640+
busbar_id = n_busbar
16401641
nb_el = cls.n_load
16411642
el_to_subid = cls.load_to_subid
16421643
el_nm = "load"
@@ -1647,7 +1648,7 @@ def test_30_n_busbar_per_sub_ok(self):
16471648

16481649
# generator
16491650
backend.reset(self.get_path(), self.get_casefile())
1650-
busbar_id = 3
1651+
busbar_id = n_busbar
16511652
nb_el = cls.n_gen
16521653
el_to_subid = cls.gen_to_subid
16531654
el_nm = "generator"
@@ -1659,7 +1660,7 @@ def test_30_n_busbar_per_sub_ok(self):
16591660
# storage
16601661
if cls.n_storage > 0:
16611662
backend.reset(self.get_path(), self.get_casefile())
1662-
busbar_id = 3
1663+
busbar_id = n_busbar
16631664
nb_el = cls.n_storage
16641665
el_to_subid = cls.storage_to_subid
16651666
el_nm = "storage"

0 commit comments

Comments
 (0)