Skip to content

Commit ae241f1

Browse files
authored
Merge pull request #194 from BDonnot/bd_dev
version dev1: with reset options added in runner and more reset options
2 parents d615fa2 + 79988ff commit ae241f1

22 files changed

+1834
-98
lines changed

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -410,6 +410,9 @@ grid2op/tests/req_38_np121
410410
test_make_2_envs.py
411411
getting_started/env_py38_grid2op110_ray110.ipynb
412412
getting_started/env_py38_grid2op110_ray210.ipynb
413+
grid2op/tests/req_chronix2grid
414+
grid2op/tests/venv_test_chronix2grid/
415+
413416

414417
# profiling files
415418
**.prof

CHANGELOG.rst

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,23 @@ Change Log
3636
- TODO A number of max buses per sub
3737
- TODO Automatic "experimental_read_from_local_dir"
3838
- TODO Notebook for stable baselines
39-
- TODO in the reset options: datetime start and max number of steps
39+
- TODO reset options in the runner
40+
41+
- [BREAKING] `env.chronics_hander.set_max_iter(xxx)` is now a private function. Use
42+
`env.set_max_iter(xxx)` or even better `env.reset(options={"max step": xxx})`.
43+
Indeed, `env.chronics_hander.set_max_iter()` will likely have
44+
no effect at all on your environment.
45+
- [BREAKING] for all the `Handler` (*eg* `CSVForecastHandler`) the method `set_max_iter` is
46+
now private (for the same reason as the `env.chronics_handler`). We do not recommend to
47+
use it (will likely have no effect). Prefer using `env.set_max_iter` instead.
48+
- [BREAKING] now the `runner.run()` method only accept kwargs argument
49+
(because it should always have been like this)
50+
- [FIXED] a bug in the `MultiFolder` and `MultifolderWithCache` leading to the wrong
51+
computation of `max_iter` on some corner cases
52+
- [ADDED] possibility to skip some step when calling `env.reset(..., options={"init ts": ...})`
53+
- [ADDED] possibility to limit the duration of an episode with `env.reset(..., options={"max step": ...})`
54+
- [ADDED] possibility to specify the "reset_options" used in `env.reset` when
55+
using the runner with `runner.run(..., reset_options=xxx)`
4056

4157
[1.10.2] - 2024-05-27
4258
-------------------------

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.3.dev0'
25+
release = '1.10.3.dev1'
2626
version = '1.10'
2727

2828

grid2op/Chronics/chronicsHandler.py

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -160,13 +160,21 @@ def get_name(self):
160160
"""
161161
return str(os.path.split(self.get_id())[-1])
162162

163-
def set_max_iter(self, max_iter: int):
163+
def _set_max_iter(self, max_iter: int):
164164
"""
165165
This function is used to set the maximum number of
166166
iterations possible before the chronics ends.
167167
168168
You can reset this by setting it to `-1`.
169169
170+
.. danger::
171+
As for grid2op 1.10.3, due to the fix of a bug when
172+
max_iter and fast_forward were used at the same time
173+
you should not use this function anymore.
174+
175+
Please use `env.set_max_iter()` instead of
176+
`env.chronics_hander.set_max_iter()`
177+
170178
Parameters
171179
----------
172180
max_iter: ``int``
@@ -175,9 +183,9 @@ def set_max_iter(self, max_iter: int):
175183
176184
"""
177185

178-
if not isinstance(max_iter, int):
186+
if not isinstance(max_iter, (int, dt_int, np.int64)):
179187
raise Grid2OpException(
180-
"The maximum number of iterations possible for this chronics, before it ends."
188+
"The maximum number of iterations possible for this time series, before it ends should be an int"
181189
)
182190
if max_iter == 0:
183191
raise Grid2OpException(

grid2op/Chronics/handlers/baseHandler.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ def __init__(self, array_name, max_iter=-1, h_forecast=(5, )):
7373
self.path : Optional[os.PathLike] = None
7474
self.max_episode_duration : Optional[int] = None
7575

76-
def set_max_iter(self, max_iter: Optional[int]) -> None:
76+
def _set_max_iter(self, max_iter: Optional[int]) -> None:
7777
"""
7878
INTERNAL
7979

grid2op/Chronics/handlers/csvForecastHandler.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -93,8 +93,8 @@ def load_next(self, dict_):
9393
def set_chunk_size(self, chunk_size):
9494
super().set_chunk_size(self._nb_row_per_step * int(chunk_size))
9595

96-
def set_max_iter(self, max_iter):
97-
super().set_max_iter(self._nb_row_per_step * int(max_iter))
96+
def _set_max_iter(self, max_iter):
97+
super()._set_max_iter(self._nb_row_per_step * int(max_iter))
9898

9999
def set_h_forecast(self, h_forecast):
100100
super().set_h_forecast(h_forecast)

grid2op/Chronics/multiFolder.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -441,6 +441,7 @@ def initialize(
441441
)
442442
if self.action_space is not None:
443443
self.data.action_space = self.action_space
444+
self._max_iter = self.data.max_iter
444445

445446
def done(self):
446447
"""

grid2op/Chronics/multifolderWithCache.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ class MultifolderWithCache(Multifolder):
7070
env = make(...,chronics_class=MultifolderWithCache)
7171
7272
# set the chronics to limit to one week of data (lower memory footprint)
73-
env.chronics_handler.set_max_iter(7*288)
73+
env.set_max_iter(7*288)
7474
# assign a filter, use only chronics that have "december" in their name
7575
env.chronics_handler.real_data.set_filter(lambda x: re.match(".*december.*", x) is not None)
7676
# create the cache
@@ -239,6 +239,7 @@ def initialize(
239239
id_scenario = self._order[self._prev_cache_id]
240240
self.data = self._cached_data[id_scenario]
241241
self.data.next_chronics()
242+
self._max_iter = self.data.max_iter
242243

243244
@property
244245
def max_iter(self):

grid2op/Chronics/time_series_from_handlers.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -204,7 +204,7 @@ def __init__(
204204
self.set_chunk_size(chunk_size)
205205

206206
if max_iter != -1:
207-
self.set_max_iter(max_iter)
207+
self._set_max_iter(max_iter)
208208

209209
self.init_datetime()
210210
self.current_inj = None
@@ -389,10 +389,10 @@ def set_chunk_size(self, new_chunk_size):
389389
for el in self._active_handlers:
390390
el.set_chunk_size(new_chunk_size)
391391

392-
def set_max_iter(self, max_iter):
392+
def _set_max_iter(self, max_iter):
393393
self.max_iter = int(max_iter)
394394
for el in self._active_handlers:
395-
el.set_max_iter(max_iter)
395+
el._set_max_iter(max_iter)
396396

397397
def init_datetime(self):
398398
for handl in self._active_handlers:

grid2op/Environment/baseEnv.py

Lines changed: 26 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -299,8 +299,7 @@ def foo(manager):
299299

300300
#: this are the keys of the dictionnary `options`
301301
#: that can be used when calling `env.reset(..., options={})`
302-
KEYS_RESET_OPTIONS = {"time serie id", "init state"}
303-
302+
KEYS_RESET_OPTIONS = {"time serie id", "init state", "init ts", "max step"}
304303

305304
def __init__(
306305
self,
@@ -3776,14 +3775,38 @@ def fast_forward_chronics(self, nb_timestep):
37763775
00:00). This can lead to suboptimal exploration, as during this phase, only a few time steps are managed by
37773776
the agent, so in general these few time steps will correspond to grid state around Jan 1st at 00:00.
37783777
3778+
.. seealso::
3779+
From grid2op version 1.10.3, a similar objective can be
3780+
obtained directly by calling :func:`grid2op.Environment.Environment.reset` with `"init ts"`
3781+
as option, for example like `obs = env.reset(options={"init ts": 12})`
3782+
3783+
3784+
.. danger::
3785+
The usage of both :func:`BaseEnv.fast_forward_chronics` and :func:`Environment.set_max_iter`
3786+
is not recommended at all and might not behave correctly. Please use `env.reset` with
3787+
`obs = env.reset(options={"max step": xxx, "init ts": yyy})` for a correct behaviour.
3788+
37793789
Parameters
37803790
----------
37813791
nb_timestep: ``int``
37823792
Number of time step to "fast forward"
37833793
37843794
Examples
37853795
---------
3786-
This can be used like this:
3796+
3797+
From grid2op version 1.10.3 we recommend not to use this function (which will be deprecated)
3798+
but to use the :func:`grid2op.Environment.Environment.reset` functon with the `"init ts"`
3799+
option.
3800+
3801+
.. code-block:: python
3802+
3803+
import grid2op
3804+
env_name = "l2rpn_case14_sandbox"
3805+
env = grid2op.make(env_name)
3806+
3807+
obs = env.reset(options={"init ts": 123})
3808+
3809+
For the legacy usave, this can be used like this:
37873810
37883811
.. code-block:: python
37893812

0 commit comments

Comments
 (0)