Skip to content

Commit 79988ff

Browse files
committed
added docs and readme [skip ci]
1 parent 8a38327 commit 79988ff

File tree

4 files changed

+86
-7
lines changed

4 files changed

+86
-7
lines changed

CHANGELOG.rst

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,8 @@ Change Log
5151
computation of `max_iter` on some corner cases
5252
- [ADDED] possibility to skip some step when calling `env.reset(..., options={"init ts": ...})`
5353
- [ADDED] possibility to limit the duration of an episode with `env.reset(..., options={"max step": ...})`
54-
54+
- [ADDED] possibility to specify the "reset_options" used in `env.reset` when
55+
using the runner with `runner.run(..., reset_options=xxx)`
5556

5657
[1.10.2] - 2024-05-27
5758
-------------------------

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/Runner/runner.py

Lines changed: 82 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1333,7 +1333,7 @@ def run(
13331333
13341334
You can use the runner this way:
13351335
1336-
.. code-block: python
1336+
.. code-block:: python
13371337
13381338
import grid2op
13391339
from gri2op.Runner import Runner
@@ -1345,7 +1345,7 @@ def run(
13451345
13461346
If you would rather to provide an agent instance (and not a class) you can do it this way:
13471347
1348-
.. code-block: python
1348+
.. code-block:: python
13491349
13501350
import grid2op
13511351
from gri2op.Runner import Runner
@@ -1361,7 +1361,7 @@ def run(
13611361
by passing `env_seeds` and `agent_seeds` parameters (on the example bellow, the agent will be seeded with 42
13621362
and the environment with 0.
13631363
1364-
.. code-block: python
1364+
.. code-block:: python
13651365
13661366
import grid2op
13671367
from gri2op.Runner import Runner
@@ -1375,7 +1375,7 @@ def run(
13751375
Since grid2op 1.10.2 you can also set the initial state of the grid when
13761376
calling the runner. You can do that with the kwargs `init_states`, for example like this:
13771377
1378-
.. code-block: python
1378+
.. code-block:: python
13791379
13801380
import grid2op
13811381
from gri2op.Runner import Runner
@@ -1405,7 +1405,85 @@ def run(
14051405
that you can control what exactly is done (set the `"method"`) more
14061406
information about this on the doc of the :func:`grid2op.Environment.Environment.reset`
14071407
function.
1408+
1409+
Since grid2op 1.10.3 you can also customize the way the runner will "reset" the
1410+
environment with the kwargs `reset_options`.
1411+
1412+
Concretely, if you specify `runner.run(..., reset_options=XXX)` then the environment
1413+
will be reset with a call to `env.reset(options=reset_options)`.
1414+
1415+
As for the init states kwargs, reset_options can be either a dictionnary, in this
1416+
case the same dict will be used for running all the episode or a list / tuple
1417+
of dictionnaries with the same size as the `nb_episode` kwargs.
1418+
1419+
.. code-block:: python
1420+
1421+
import grid2op
1422+
from gri2op.Runner import Runner
1423+
from grid2op.Agent import RandomAgent
1424+
1425+
env = grid2op.make("l2rpn_case14_sandbox")
1426+
my_agent = RandomAgent(env.action_space)
1427+
runner = Runner(**env.get_params_for_runner(), agentClass=None, agentInstance=my_agent)
1428+
res = runner.run(nb_episode=2,
1429+
agent_seeds=[42, 43],
1430+
env_seeds=[0, 1],
1431+
reset_options={"init state": {"set_line_status": [(0, -1)]}}
1432+
)
1433+
# same initial state will be used for the two epusode
1434+
1435+
res2 = runner.run(nb_episode=2,
1436+
agent_seeds=[42, 43],
1437+
env_seeds=[0, 1],
1438+
reset_options=[{"init state": {"set_line_status": [(0, -1)]}},
1439+
{"init state": {"set_line_status": [(1, -1)]}}]
1440+
)
1441+
# two different initial states will be used: the first one for the
1442+
# first episode and the second one for the second
1443+
1444+
.. note::
1445+
In case of conflicting inputs, for example when you specify:
1446+
1447+
.. code-block:: python
1448+
1449+
runner.run(...,
1450+
init_states=XXX,
1451+
reset_options={"init state"=YYY}
1452+
)
1453+
1454+
or
14081455
1456+
.. code-block:: python
1457+
1458+
runner.run(...,
1459+
max_iter=XXX,
1460+
reset_options={"max step"=YYY}
1461+
)
1462+
1463+
or
1464+
1465+
.. code-block:: python
1466+
1467+
runner.run(...,
1468+
episode_id=XXX,
1469+
reset_options={"time serie id"=YYY}
1470+
)
1471+
1472+
Then: 1) a warning is issued to inform you that you might have
1473+
done something wrong and 2) the value in `XXX` above (*ie* the
1474+
value provided in the `runner.run` kwargs) is always used
1475+
instead of the value `YYY` (*ie* the value present in the
1476+
reset_options).
1477+
1478+
In other words, the arguments of the `runner.run` have the
1479+
priority over the arguments passed to the `reset_options`.
1480+
1481+
.. danger::
1482+
If you provide the key "time serie id" in one of the `reset_options`
1483+
dictionary, we recommend
1484+
you do it for all `reset_options` otherwise you might not end up
1485+
computing the correct episodes.
1486+
14091487
"""
14101488
if nb_episode < 0:
14111489
raise RuntimeError("Impossible to run a negative number of scenarios.")

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.3.dev0'
14+
__version__ = '1.10.3.dev1'
1515

1616
__all__ = [
1717
"Action",

0 commit comments

Comments
 (0)