Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Upgrade to version 1.7.0 #309

Merged
merged 126 commits into from
Apr 29, 2022
Merged
Changes from 10 commits
Commits
Show all changes
126 commits
Select commit Hold shift + click to select a range
e4ab5c5
fixing issue rte-france#281
BDonnot Jan 25, 2022
8752708
fixing issue rte-france#282
BDonnot Jan 25, 2022
4befde9
fixing rte-france#283
BDonnot Jan 25, 2022
ffdcbe4
making difference between env_path and grid_path in Environment
BDonnot Jan 26, 2022
b34fc3b
fixing broken tests
BDonnot Jan 26, 2022
6ea4a5b
Merge pull request #147 from BDonnot/bd_dev
BDonnot Jan 27, 2022
1a13dab
Merge pull request #284 from BDonnot/master
BDonnot Jan 27, 2022
53a98c7
fixing rte-france#285
BDonnot Jan 27, 2022
c3af41a
fix a typo in a property definition
BDonnot Jan 27, 2022
415b0c0
fix another typo in a property definition
BDonnot Jan 27, 2022
b698d25
a few modif i need to integrate properly [skip ci]
BDonnot Feb 2, 2022
c7ae389
adding an exception to the error message of the environment
BDonnot Feb 3, 2022
99a9b41
update the changelog [skip ci]
BDonnot Feb 7, 2022
4a70c57
fixing bug rte-france#286
BDonnot Feb 7, 2022
c405668
fixing broken tests
BDonnot Feb 7, 2022
53035a1
Merge pull request #148 from BDonnot/bd_dev
BDonnot Feb 7, 2022
f76069a
Merge pull request #287 from BDonnot/master
BDonnot Feb 7, 2022
9f4d881
adding seeds in the gym compat to make tests reproducible
BDonnot Feb 8, 2022
15d943e
fix a bug of the shunts in the update_from_obs and start to add simul…
BDonnot Feb 8, 2022
316987f
adding attributes to the observation: gen_margin_up and gen_margin_down
BDonnot Feb 9, 2022
149619f
adding icaps env in the doc
BDonnot Feb 9, 2022
79e3833
adding some tests for the simulator, need more tests then documentation
BDonnot Feb 9, 2022
6cdd4e1
adding some tests for the simulator, need more tests then documentation
BDonnot Feb 9, 2022
06cd667
adding an 'automaton' in the enviornment to improve resiliency when h…
BDonnot Feb 10, 2022
70e2ba1
trying to add an option to limit the curtailment to make the redispat…
BDonnot Feb 10, 2022
51b81b8
limit curtailment starts to work on some simple cases
BDonnot Feb 11, 2022
71d477d
passing more tests for the extreme curtailment
BDonnot Feb 11, 2022
19d474f
quite robust tests for the redispatching in extreme cases
BDonnot Feb 11, 2022
64db946
adding some tests for the correct implementation of slack power needed
BDonnot Feb 11, 2022
79ba5dc
identify the possible location of the bug in the tests [skip ci]
BDonnot Feb 11, 2022
526d08c
one more case taken into account when limiting curtailment
BDonnot Feb 15, 2022
f3bd27c
adding new test env, moving _ObsEnv [skip ci]
BDonnot Feb 15, 2022
b3121f0
adding support for max_iter in the pandapowerr backend
BDonnot Feb 16, 2022
8d448a6
progressing in limiting the storage unit actions, some tests does not…
BDonnot Feb 16, 2022
3177b3a
still a weird bug when both storage and curtailment are limited [skip…
BDonnot Feb 16, 2022
f49c9ef
all tests work, will refacto the step functions now
BDonnot Feb 17, 2022
d08d36b
finishing the refactoring of env.step and to code the limit of curtai…
BDonnot Feb 17, 2022
e9a92bc
fixing tests for sonarcloud
BDonnot Feb 18, 2022
3edc78c
fixing broken tests for the environment
BDonnot Feb 18, 2022
43e9304
adding some tests and storage units support in the Simulator
BDonnot Feb 18, 2022
48f5646
adding a utility to plot and possibility to create an env without the…
BDonnot Mar 14, 2022
84da515
Merge branch 'bd_dev' of https://github.com/bdonnot/grid2op into bd_dev
BDonnot Mar 14, 2022
93429cf
update changelog
BDonnot Mar 14, 2022
488b358
Merge branch 'bd_dev' of https://github.com/bdonnot/grid2op into bd_dev
BDonnot Mar 14, 2022
027a183
start to add the method to generate data from grid2op [skipci]
BDonnot Mar 17, 2022
a1299f9
fix a bug in networkx
BDonnot Mar 22, 2022
35b6370
fixing conflict
BDonnot Mar 22, 2022
5a6c4ea
adding a seed to a test that appear random
BDonnot Mar 22, 2022
205f5d9
adding python 3.10 in circleci tests
BDonnot Mar 22, 2022
d4eb4be
adding the start of a doc for the simulator [skip ci]
BDonnot Mar 22, 2022
9a7f1cd
formatting the code with black
BDonnot Mar 23, 2022
e651956
adding documentation to the simulator class
BDonnot Mar 23, 2022
5ee45e3
improving code quality for sonarcloud
BDonnot Mar 23, 2022
754c934
Merge pull request #149 from BDonnot/bd_dev
BDonnot Mar 23, 2022
485c058
Merge pull request #292 from BDonnot/master
BDonnot Mar 24, 2022
cb53b70
fix a bug in runner for max_iter
BDonnot Mar 29, 2022
b45cad6
fix the test grid to silence lightsim2grid warnings
BDonnot Mar 29, 2022
b4967cc
improve the hashing of the environments
BDonnot Mar 29, 2022
0bd5efe
adding explicit action / observation classes for the competition envi…
BDonnot Mar 29, 2022
3f7638e
adding support for changing the opponent space type
BDonnot Mar 29, 2022
41b6a34
silence lightsim2grid warnings for l2rpn_* envs
BDonnot Mar 29, 2022
c98b03f
Merge pull request #150 from BDonnot/bd_dev
BDonnot Mar 30, 2022
aa7221f
Merge pull request #295 from BDonnot/master
BDonnot Mar 30, 2022
b1d86db
adding l2rpn_utils module for dedicated action / observation class fo…
BDonnot Mar 30, 2022
6decea7
Improving error message when environment cannot be updated [skip ci]
BDonnot Mar 30, 2022
a6af965
Merge pull request #151 from BDonnot/bd_dev
BDonnot Mar 30, 2022
7385d88
Merge pull request #296 from BDonnot/master
BDonnot Mar 30, 2022
1580f9c
fix the computation of the reward and scores - bug due to conversion …
BDonnot Mar 30, 2022
ed5931c
adding another thing to do before release [skip ci]
BDonnot Mar 30, 2022
94b5ece
start to add a method to limit the curtailment / storage of an action…
BDonnot Apr 1, 2022
d9f9244
fix two small
Apr 2, 2022
af15164
fix two small malformations
Apr 2, 2022
4b25843
Merge branch 'dev_1.6.6' of github.com:mowang111/Grid2Op into dev_1.6.6
Apr 2, 2022
babb17d
test past for limiting curtailment down [skip ci]
BDonnot Apr 4, 2022
b96f28a
adding functionality to limit the storage / curtailment in the action
BDonnot Apr 4, 2022
0f3d746
Merge pull request #299 from mowang111/dev_1.6.6
BDonnot Apr 4, 2022
819c1d8
improve readme.md [skip ci]
BDonnot Apr 4, 2022
21fcd85
Merge remote-tracking branch 'upstream/dev_1.6.6' into bd_dev
BDonnot Apr 4, 2022
afc83e1
improve readme and notebook on action [skip ci]
BDonnot Apr 5, 2022
82a0a10
adding the doc of act.limit_curtail_storage [skip ci]
BDonnot Apr 5, 2022
43b8ceb
adding some typing for the BaseAction [skip ci]
BDonnot Apr 5, 2022
bcbfd4f
adding a method to compute the chronix 'on the fly' using chronix2gri…
BDonnot Apr 6, 2022
2ddc6df
[skip ci] adding a first dev version of l2rpn 2022, adding some tests…
BDonnot Apr 7, 2022
fb201e4
make sure tests are made for the new functionalities
BDonnot Apr 8, 2022
0a09437
fixing a first bug of config.yaml
BDonnot Apr 8, 2022
d740eff
fixing a second bug of config.yaml
BDonnot Apr 8, 2022
5afa9c5
fixing a second bug of config.yaml 2
BDonnot Apr 8, 2022
a2651ac
fixing a second bug of config.yaml 3
BDonnot Apr 8, 2022
1d7761f
fixing a second bug of config.yaml 4
BDonnot Apr 8, 2022
787811b
fixing a second bug of config.yaml 5
BDonnot Apr 8, 2022
b355e88
fixing a second bug of config.yaml 6
BDonnot Apr 8, 2022
d96b5e1
fixing a second bug of config.yaml 7
BDonnot Apr 8, 2022
5f8ff8a
fixing a second bug of config.yaml 8
BDonnot Apr 8, 2022
abc01f1
fixing a second bug of config.yaml 9
BDonnot Apr 8, 2022
05038d7
fixing a second bug of config.yaml 10
BDonnot Apr 8, 2022
58b9671
fixing a second bug of config.yaml 11
BDonnot Apr 8, 2022
2349042
fixing a second bug of config.yaml 12
BDonnot Apr 8, 2022
6b66609
fixing a second bug of config.yaml 13
BDonnot Apr 8, 2022
ebeda0a
fixing a second bug of config.yaml 14
BDonnot Apr 8, 2022
52009a9
fixing a second bug of config.yaml 15
BDonnot Apr 8, 2022
a310539
fixing a second bug of config.yaml 16
BDonnot Apr 8, 2022
1df8f62
fixing a second bug of config.yaml 17
BDonnot Apr 8, 2022
bb4e74f
fixing a second bug of config.yaml 18
BDonnot Apr 8, 2022
56608b9
fixing broken tests
BDonnot Apr 12, 2022
ba52a7e
fix test and add doc for the new chronix class and improve some docs
BDonnot Apr 12, 2022
d3a6664
updating the changelog [skip ci]
BDonnot Apr 12, 2022
0e171c3
update config of l2rpn_wcci_2022 test env [skip ci]
BDonnot Apr 12, 2022
cbb4fed
resetting the chronix2grid dependency to master instead of bd-dev [sk…
BDonnot Apr 12, 2022
9cca5ba
refactoring the fromChronixGrid class to reduce copy paste
BDonnot Apr 12, 2022
d468241
Merge pull request #152 from BDonnot/bd_dev
BDonnot Apr 12, 2022
06b7848
Merge pull request #300 from BDonnot/master
BDonnot Apr 12, 2022
a07e87b
fix a bug when limiting the action automatically in the env
BDonnot Apr 22, 2022
87f305d
Merge pull request #153 from BDonnot/bd_dev
BDonnot Apr 22, 2022
b9c9fc9
Merge pull request #306 from BDonnot/master
BDonnot Apr 22, 2022
16a9c4e
introducing basic compatibility with 'new' openai reset api [skip ci]
BDonnot Apr 22, 2022
98bc50c
finishing the notebook 4 on the training agent
BDonnot Apr 26, 2022
8431630
adding readme [skip ci]
BDonnot Apr 26, 2022
7e1cd77
adapting the redispatching algorithm, fixing the notebook 4, 5 and 6 …
BDonnot Apr 26, 2022
d5bcc63
updating the last notebooks with more up to date information
BDonnot Apr 27, 2022
02f4026
adapt tests for modification of redispatching algorithm
BDonnot Apr 28, 2022
42797cb
update the changelog [skip ci]
BDonnot Apr 28, 2022
0f2f7a9
Merge pull request #154 from BDonnot/bd_dev
BDonnot Apr 28, 2022
5997b0a
Merge pull request #308 from BDonnot/master
BDonnot Apr 28, 2022
b4a7310
fixing rte-france#310 rte-france#311 and add tests for env.generate_c…
BDonnot Apr 29, 2022
056eb47
Merge pull request #155 from BDonnot/bd_dev
BDonnot Apr 29, 2022
823046f
Merge pull request #312 from BDonnot/master
BDonnot Apr 29, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -345,6 +345,7 @@ test_n1_reward.py
test_copy_env_close.py
!grid2op/tests/test_copy_env_close.py
grid2op/tests/output_unittest.txt
test_utils_multiproc.py

# profiling files
**.prof
20 changes: 20 additions & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
@@ -3,6 +3,10 @@ Change Log

[TODO]
--------------------
- [???] Create a "Simulator" class that is like a backend but with which
you can interact more easily with grid2op actions for example (it should
also returns grid2op observations !)
- [???] add the attributes "gen_margin_up" and "gen_margin_down" in the observations.
- [???] use some kind of "env.get_state()" when simulating instead of recoding everything "by hand"
- [???] use "backend.get_action_to_set()" in simulate
- [???] use the prod_p_forecasted and co in the "next_chronics" of simulate
@@ -39,7 +43,23 @@ Change Log
Before it has the size of `env.n_gen` now `np.sum(env.gen_redispatchable)`.
- [FIXED] a bug in the gym action space: see issue https://github.com/rte-france/Grid2Op/issues/281
- [FIXED] a bug in the gym box action space: see issue https://github.com/rte-france/Grid2Op/issues/283
- [FIXED] a bug when using `MultifolderWithCache` and `Runner` (see issue https://github.com/rte-france/Grid2Op/issues/285)
- [FIXED] a bug in the `env.train_val_split_random` where sometimes some wrong chronics
name were sampled.
- [FIXED] the `max` value of the observation space is now 1.3 * pmax to account for the slack bus (it was
1.01 of pmax before and was not sufficient in some cases)
- [FIXED] a proper exception is added to the "except" kwargs of the "info" return argument of `env.step(...)`
(previously it was only a string) when redispatching was illegal.
- [FIXED] a bug in `env.train_val_split_random` when some non chronics files where present in the
"chronics" folder of the environment.
- [ADDED] a function `normalize_attr` allowing to easily scale some data for the
`BoxGymObsSpace` and `BoxGymActSpace`
- [ADDED] support for distributed slack in pandapower (if supported)
- [ADDED] an attribute `self.infos` for the BaseEnv that contains the "info" return value of `env.step(...)`
- [ADDED] the possibility to shuffle the chronics of a `GymEnv` (the default behavior is now to shuffle them)
- [IMPROVED] better difference between env_path and grid_path in environments.
- [IMPROVED] addition of a flag to control whether pandapower can use lightsim2grid (to solve the powerflows) or not
- [IMPROVED] clean the warnings issued by pandas when used with pandapower

[1.6.5] - 2022-01-19
---------------------
Original file line number Diff line number Diff line change
@@ -574,7 +574,7 @@
" from ray.rllib.agents import ppo # import the type of agents\n",
" # nb_step_train = 100 # Do not forget to turn on the actual training !\n",
" # fist initialize ray\n",
" ray.init()\n",
" \n",
" try:\n",
" # then define a \"trainer\"\n",
" trainer = ppo.PPOTrainer(env=MyEnv, config={\n",
71 changes: 55 additions & 16 deletions grid2op/Backend/PandaPowerBackend.py
Original file line number Diff line number Diff line change
@@ -104,7 +104,11 @@ class PandaPowerBackend(Backend):
# and use "env" as any open ai gym environment.

"""
def __init__(self, detailed_infos_for_cascading_failures=False):
def __init__(self,
detailed_infos_for_cascading_failures=False,
ligthsim2grid=False, # use lightsim2grid as pandapower powerflow solver
dist_slack=False
):
Backend.__init__(self, detailed_infos_for_cascading_failures=detailed_infos_for_cascading_failures)
self.prod_pu_to_kv = None
self.load_pu_to_kv = None
@@ -186,6 +190,9 @@ def __init__(self, detailed_infos_for_cascading_failures=False):
self.load_theta = None
self.gen_theta = None
self.storage_theta = None

self._ligthsim2grid = ligthsim2grid
self._dist_slack = dist_slack

def _check_for_non_modeled_elements(self):
"""This function check for elements in the pandapower grid that will have no impact on grid2op.
@@ -292,6 +299,7 @@ def load_grid(self, path=None, filename=None):
with warnings.catch_warnings():
# remove deprecationg warnings for old version of pandapower
warnings.filterwarnings("ignore", category=DeprecationWarning)
warnings.filterwarnings("ignore", category=FutureWarning)
self._grid = pp.from_json(full_path)

self._check_for_non_modeled_elements()
@@ -303,7 +311,16 @@ def load_grid(self, path=None, filename=None):
self._id_bus_added = None
with warnings.catch_warnings():
warnings.filterwarnings("ignore")
pp.runpp(self._grid, numba=numba_)
pp.runpp(self._grid,
numba=numba_,
lightsim2grid=self._ligthsim2grid,
distributed_slack=self._dist_slack)
new_pp_version = False
if not "slack_weight" in self._grid.gen:
self._grid.gen["slack_weight"] = 1.0
else:
new_pp_version = True

if np.all(~self._grid.gen["slack"]):
# there are not defined slack bus on the data, i need to hack it up a little bit
pd2ppc = self._grid._pd2ppc_lookups["bus"] # pd2ppc[pd_id] = ppc_id
@@ -318,17 +335,30 @@ def load_grid(self, path=None, filename=None):

bus_gen_added = ppc2pd[int(el)]
# see https://matpower.org/docs/ref/matpower5.0/idx_gen.html for details on the comprehension of self._grid._ppc
id_added = pp.create_gen(self._grid,
bus_gen_added,
p_mw=self._grid._ppc['gen'][gen_id_pp, 1],
vm_pu=self._grid._ppc['gen'][gen_id_pp, 5],
min_p_mw=self._grid._ppc['gen'][gen_id_pp, 9],
max_p_mw=self._grid._ppc['gen'][gen_id_pp, 8],
max_q_mvar=self._grid._ppc['gen'][gen_id_pp, 3],
min_q_mvar=self._grid._ppc['gen'][gen_id_pp, 4],
slack=i_ref is None,
controllable=True)

if new_pp_version:
id_added = pp.create_gen(self._grid,
bus_gen_added,
p_mw=self._grid._ppc['gen'][gen_id_pp, 1],
vm_pu=self._grid._ppc['gen'][gen_id_pp, 5],
min_p_mw=self._grid._ppc['gen'][gen_id_pp, 9],
max_p_mw=self._grid._ppc['gen'][gen_id_pp, 8],
max_q_mvar=self._grid._ppc['gen'][gen_id_pp, 3],
min_q_mvar=self._grid._ppc['gen'][gen_id_pp, 4],
slack=i_ref is None,
slack_weight=1.0,
controllable=True)
else:
id_added = pp.create_gen(self._grid,
bus_gen_added,
p_mw=self._grid._ppc['gen'][gen_id_pp, 1],
vm_pu=self._grid._ppc['gen'][gen_id_pp, 5],
min_p_mw=self._grid._ppc['gen'][gen_id_pp, 9],
max_p_mw=self._grid._ppc['gen'][gen_id_pp, 8],
max_q_mvar=self._grid._ppc['gen'][gen_id_pp, 3],
min_q_mvar=self._grid._ppc['gen'][gen_id_pp, 4],
slack=i_ref is None,
controllable=True)

if i_ref is None:
i_ref = gen_id_pp
self._iref_slack = i_ref
@@ -337,10 +367,14 @@ def load_grid(self, path=None, filename=None):
self._grid.ext_grid = self._grid.ext_grid.iloc[:1]
else:
self.slack_id = np.where(self._grid.gen["slack"])[0]

with warnings.catch_warnings():
warnings.filterwarnings("ignore")
pp.runpp(self._grid, numba=numba_)
pp.runpp(self._grid,
numba=numba_,
lightsim2grid=self._ligthsim2grid,
distributed_slack=self._dist_slack)

self.__nb_bus_before = self._grid.bus.shape[0]
self.__nb_powerline = self._grid.line.shape[0]
self._init_bus_load = self.cst_1 * self._grid.load["bus"].values
@@ -815,7 +849,12 @@ def runpf(self, is_dc=False):
pp.rundcpp(self._grid, check_connectivity=False)
self._nb_bus_before = None # if dc i start normally next time i call an ac powerflow
else:
pp.runpp(self._grid, check_connectivity=False, init=self._pf_init, numba=numba_)
pp.runpp(self._grid,
check_connectivity=False,
init=self._pf_init,
numba=numba_,
ligthsim2grid=self._ligthsim2grid,
distributed_slack=self._dist_slack)

# stores the computation time
if "_ppc" in self._grid:
14 changes: 13 additions & 1 deletion grid2op/Chronics/chronicsHandler.py
Original file line number Diff line number Diff line change
@@ -6,6 +6,7 @@
# SPDX-License-Identifier: MPL-2.0
# This file is part of Grid2Op, Grid2Op a testbed platform to model sequential decision making in power systems.

import copy
import os
import numpy as np
from datetime import timedelta
@@ -58,7 +59,7 @@ def __init__(self, chronicsClass=ChangeNothing, time_interval=timedelta(minutes=
"\"Grid2Op.GridValue\" type and not {}.".format(type(chronicsClass)))

self.chronicsClass = chronicsClass
self.kwargs = kwargs
self._kwargs = kwargs
self.max_iter = max_iter

self.path = None
@@ -73,6 +74,17 @@ def __init__(self, chronicsClass=ChangeNothing, time_interval=timedelta(minutes=
raise ChronicsError("Impossible to build a chronics of type {} with arguments in "
"{}".format(chronicsClass, self.kwargs)) from exc_

@property
def kwargs(self):
res = copy.deepcopy(self._kwargs)
if self._real_data is not None:
self._real_data.get_kwargs(res)
return res

@kwargs.setter
def kwargs(self, new_value):
raise ChronicsError("Impossible to set the \"kwargs\" attribute")

@property
def real_data(self):
return self._real_data
7 changes: 7 additions & 0 deletions grid2op/Chronics/gridValue.py
Original file line number Diff line number Diff line change
@@ -101,6 +101,13 @@ def __init__(self,
self.maintenance_duration = None
self.hazard_duration = None

def get_kwargs(self, dict_):
"""
Overload this function if you want to pass some data when building
a new instance of this class.
"""
pass

@abstractmethod
def initialize(self, order_backend_loads, order_backend_prods, order_backend_lines, order_backend_subs,
names_chronics_to_backend):
15 changes: 13 additions & 2 deletions grid2op/Chronics/multiFolder.py
Original file line number Diff line number Diff line change
@@ -57,7 +57,8 @@ def __init__(self, path,
gridvalueClass=GridStateFromFile,
sep=";",
max_iter=-1,
chunk_size=None):
chunk_size=None,
filter_func=None):
GridValue.__init__(self, time_interval=time_interval, max_iter=max_iter, chunk_size=chunk_size,
start_datetime=start_datetime)
self.gridvalueClass = gridvalueClass
@@ -87,10 +88,20 @@ def __init__(self, path,
self._names_chronics_to_backend = None

# improving looping strategy
self._filter = self._default_filter
if filter_func is None:
self._filter = self._default_filter
else:
if not callable(filter_func):
raise ChronicsError("The filtering function you provided ("
"kwargs: filter_func) is not callable.")
self._filter = filter_func
self._prev_cache_id = 0
self._order = None

def get_kwargs(self, dict_):
if self._filter != self._default_filter:
dict_["filter_func"] = self._filter

def available_chronics(self):
"""return the list of available chronics.

6 changes: 4 additions & 2 deletions grid2op/Chronics/multifolderWithCache.py
Original file line number Diff line number Diff line change
@@ -64,15 +64,17 @@ def __init__(self, path,
gridvalueClass=GridStateFromFile,
sep=";",
max_iter=-1,
chunk_size=None):
chunk_size=None,
filter_func=None):
Multifolder.__init__(self,
path=path,
time_interval=time_interval,
start_datetime=start_datetime,
gridvalueClass=gridvalueClass,
sep=sep,
max_iter=max_iter,
chunk_size=None)
chunk_size=None,
filter_func=filter_func)
self._cached_data = None
self.cache_size = 0
if not issubclass(self.gridvalueClass, GridStateFromFile):
41 changes: 22 additions & 19 deletions grid2op/Environment/BaseEnv.py
Original file line number Diff line number Diff line change
@@ -2113,12 +2113,14 @@ def step(self, action):
is_illegal_redisp = True
except_.append(except_tmp)
is_done = True
except_.append("Game over due to infeasible redispatching state. "
"The routine used to compute the \"next state\" has diverged. "
"This means that there is no way to compute a physically valid generator state "
"(one that meets all pmin / pmax - ramp min / ramp max with the information "
"provided. As one of the physical constraints would be violated, this means that "
"a generator would be damaged in real life. This is a game over.")
except_.append(
InvalidRedispatching("Game over due to infeasible redispatching state. "
"The routine used to compute the \"next state\" has diverged. "
"This means that there is no way to compute a physically valid generator state "
"(one that meets all pmin / pmax - ramp min / ramp max with the information "
"provided. As one of the physical constraints would be violated, this means that "
"a generator would be damaged in real life. This is a game over.")
)

# check the validity of min downtime and max uptime
except_tmp = self._handle_updown_times(gen_up_before, self._actual_dispatch)
@@ -2236,26 +2238,27 @@ def step(self, action):
self._backend_action.reset()
if conv_ is not None:
except_.append(conv_)
infos = {"disc_lines": self._disc_lines,
"is_illegal": is_illegal,
"is_ambiguous": is_ambiguous,
"is_dispatching_illegal": is_illegal_redisp,
"is_illegal_reco": is_illegal_reco,
"reason_alarm_illegal": reason_alarm_illegal,
"opponent_attack_line": lines_attacked,
"opponent_attack_sub": subs_attacked,
"opponent_attack_duration": attack_duration,
"exception": except_,}
self.infos = {"disc_lines": self._disc_lines,
"is_illegal": is_illegal,
"is_ambiguous": is_ambiguous,
"is_dispatching_illegal": is_illegal_redisp,
"is_illegal_reco": is_illegal_reco,
"reason_alarm_illegal": reason_alarm_illegal,
"opponent_attack_line": lines_attacked,
"opponent_attack_sub": subs_attacked,
"opponent_attack_duration": attack_duration,
"exception": except_,}

if self.backend.detailed_infos_for_cascading_failures:
infos["detailed_infos_for_cascading_failures"] = detailed_info
self.infos["detailed_infos_for_cascading_failures"] = detailed_info

self.done = self._is_done(has_error, is_done)
self.current_reward, other_reward = self._get_reward(action,
has_error,
self.done, # is_done
is_illegal or is_illegal_redisp or is_illegal_reco,
is_ambiguous)
infos["rewards"] = other_reward
self.infos["rewards"] = other_reward
if has_error and self.current_obs is not None:
# forward to the observation if an alarm is used or not
if hasattr(self._reward_helper.template_reward, "has_alarm_component"):
@@ -2267,7 +2270,7 @@ def step(self, action):
# TODO documentation on all the possible way to be illegal now
if self.done:
self.__is_init = False
return self.current_obs, self.current_reward, self.done, infos
return self.current_obs, self.current_reward, self.done, self.infos

def _get_reward(self, action, has_error, is_done, is_illegal, is_ambiguous):
res = self._reward_helper(action, self, has_error, is_done, is_illegal, is_ambiguous)
9 changes: 6 additions & 3 deletions grid2op/Environment/Environment.py
Original file line number Diff line number Diff line change
@@ -1411,15 +1411,17 @@ def train_val_split_random(self,
my_path = self.get_path_env()
chronics_path = os.path.join(my_path, self._chronics_folder_name())
all_chron = sorted(os.listdir(chronics_path))
all_chron = [el for el in all_chron if os.path.isdir(os.path.join(chronics_path, el))]
nb_init = len(all_chron)
to_val = self.space_prng.choice(all_chron, int(nb_init * pct_val * 0.01), replace=False)

to_val = self.space_prng.choice(all_chron, size=int(nb_init * pct_val * 0.01), replace=False)

test_scen_id = None
if pct_test is not None:
all_chron = set(all_chron) - set(to_val)
all_chron = list(all_chron)
test_scen_id = self.space_prng.choice(all_chron, int(nb_init * pct_test * 0.01), replace=False)
test_scen_id = self.space_prng.choice(all_chron, size=int(nb_init * pct_test * 0.01), replace=False)

return self.train_val_split(to_val,
add_for_train=add_for_train,
add_for_val=add_for_val,
@@ -1464,6 +1466,7 @@ def get_params_for_runner(self):
res["gridStateclass"] = self.chronics_handler.chronicsClass
res["backendClass"] = self._raw_backend_class
res["verbose"] = False

dict_ = copy.deepcopy(self.chronics_handler.kwargs)
if 'path' in dict_:
# path is handled elsewhere
Loading