Skip to content

Commit 0183478

Browse files
authored
Merge pull request #609 from BDonnot/master
Upgrade to 1.10.2.dev3
2 parents 3b0b687 + 0feefd9 commit 0183478

File tree

71 files changed

+1520
-273
lines changed

Some content is hidden

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

71 files changed

+1520
-273
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -408,6 +408,8 @@ grid2op/tests/20240429_failed_tests_small.txt
408408
grid2op/tests/20240429_teq_test.txt
409409
grid2op/tests/req_38_np121
410410
test_make_2_envs.py
411+
getting_started/env_py38_grid2op110_ray110.ipynb
412+
getting_started/env_py38_grid2op110_ray210.ipynb
411413

412414
# profiling files
413415
**.prof

CHANGELOG.rst

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,9 @@ Change Log
5252
and `FromChronix2grid` are not supported at the moment.
5353
- [ADDED] an "Handler" (`JSONInitStateHandler`) that can set the grid to an initial state (so as to make
5454
compatible the `FromHandlers` time series class with this new feature)
55+
- [ADDED] some more type hints in the `GridObject` class
56+
- [ADDED] Possibility to deactive the support of shunts if subclassing `PandaPowerBackend`
57+
(and add some basic tests)
5558
- [FIXED] a small issue that could lead to having
5659
"redispatching_unit_commitment_availble" flag set even if the redispatching
5760
data was not loaded correctly
@@ -68,6 +71,8 @@ Change Log
6871
and most of the time incorrectly)
6972
- [FIXED] on `RemoteEnv` class (impact all multi process environment): the kwargs used to build then backend
7073
where not used which could lead to"wrong" backends being used in the sub processes.
74+
- [FIXED] a bug when the name of the times series and the names of the elements in the backend were
75+
different: it was not possible to set `names_chronics_to_grid` correctly when calling `env.make`
7176
- [IMPROVED] documentation about `obs.simulate` to make it clearer the
7277
difference between env.step and obs.simulate on some cases
7378
- [IMPROVED] type hints on some methods of `GridObjects`
@@ -79,6 +84,8 @@ Change Log
7984
- [IMPROVED] the way the "grid2op compat" mode is handled
8085
- [IMPROVED] the coverage of the tests in the "test_basic_env_ls.py" to test more in depth lightsim2grid
8186
(creation of multiple environments, grid2op compatibility mode)
87+
- [IMPROVED] the function to test the backend interface in case when shunts are not supported
88+
(improved test `AAATestBackendAPI.test_01load_grid`)
8289

8390
[1.10.1] - 2024-03-xx
8491
----------------------

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.2.dev2'
25+
release = '1.10.2.dev3'
2626
version = '1.10'
2727

2828

docs/environment.rst

Lines changed: 59 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,58 @@ increase the training time, especially at the beginning. This is due to the fact
104104
`env.reset` is called, the whole chronics is read from the hard drive. If you want to lower this
105105
impact then you might consult the :ref:`environment-module-data-pipeline` page of the doc.
106106

107+
Go to the next scenario
108+
++++++++++++++++++++++++
109+
110+
Starting grid2op 1.9.8 we attempt to make an easier user experience in the
111+
selection of time series, seed, initial state of the grid, etc.
112+
113+
All of the above can be done when calling `env.reset()` function.
114+
115+
For customizing the seed, you can for example do:
116+
117+
.. code-block:: python
118+
119+
import grid2op
120+
env_name = "l2rpn_case14_sandbox"
121+
env = grid2op.make(env_name)
122+
123+
obs = env.reset(seed=0)
124+
125+
For customizing the time series id you want to use:
126+
127+
.. code-block:: python
128+
129+
import grid2op
130+
env_name = "l2rpn_case14_sandbox"
131+
env = grid2op.make(env_name)
132+
133+
obs = env.reset(options={"time serie id": 1}) # time serie by id (sorted alphabetically)
134+
# or
135+
obs = env.reset(options={"time serie id": "0001"}) # time serie by name (folder name)
136+
137+
For customizing the initial state of the grid, for example forcing the
138+
powerline 0 to be disconnected in the initial observation:
139+
140+
.. code-block:: python
141+
142+
import grid2op
143+
env_name = "l2rpn_case14_sandbox"
144+
env = grid2op.make(env_name)
145+
146+
init_state_dict = {"set_line_status": [(0, -1)]}
147+
obs = env.reset(options={"init state": init_state_dict})
148+
149+
150+
Feel free to consult the documentation of the :func:`Environment.reset` function
151+
for more information (this doc might be outdated, the one of the function should
152+
be more up to date with the code).
153+
154+
.. info::
155+
In the near future (next few releases) we will also attempt to make the
156+
customization of the `parameters` or the `skip number of steps`, `maximum duration
157+
of the scenarios` also available in `env.reset()` options.
158+
107159
.. _environment-module-chronics-info:
108160

109161
Time series Customization
@@ -141,10 +193,15 @@ the call to "env.reset". This gives the following code:
141193
# and now the loop starts
142194
for i in range(episode_count):
143195
###################################
144-
env.set_id(THE_CHRONIC_ID)
196+
# with recent grid2op
197+
obs = env.reset(options={"time serie id": THE_CHRONIC_ID})
145198
###################################
146199
147-
obs = env.reset()
200+
###################################
201+
# 'old method (oldest grid2op version)'
202+
# env.set_id(THE_CHRONIC_ID)
203+
# obs = env.reset()
204+
###################################
148205
149206
# now play the episode as usual
150207
while True:

getting_started/11_IntegrationWithExistingRLFrameworks.ipynb

Lines changed: 48 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,37 @@
135135
"\n",
136136
"More information are provided here: https://grid2op.readthedocs.io/en/latest/environment.html#splitting-into-raining-validation-test-scenarios\n",
137137
"\n",
138+
"### Use the `experimental_read_from_local_dir` flag\n",
139+
"\n",
140+
"This flag allows python to better \"understands\" the classes in grid2op and avoid lots of issue with pickle / multi processing etc.\n",
141+
"\n",
142+
"The complete documentation is available here https://grid2op.readthedocs.io/en/latest/environment.html#grid2op.Environment.BaseEnv.generate_classes\n",
143+
"\n",
144+
"Basically, once, and only once, outside of this process, you can call:\n",
145+
"\n",
146+
"```python\n",
147+
"import grid2op\n",
148+
"env_name = \"l2rpn_case14_sandbox\" # or any other name\n",
149+
"\n",
150+
"env = grid2op.make(env_name, ...) # again: redo this step each time you customize \"...\"\n",
151+
"# for example if you change the `action_class` or the `backend` etc.\n",
152+
"\n",
153+
"env.generate_classes()\n",
154+
"```\n",
155+
"\n",
156+
"Then, each time you want to reload the same environment, you can do:\n",
157+
"\n",
158+
"```python\n",
159+
"import grid2op\n",
160+
"env_name = SAME NAME AS ABOVE\n",
161+
"env = grid2op.make(env_name,\n",
162+
" experimental_read_from_local_dir=True,\n",
163+
" ..., # SAME ENV CUSTOMIZATION AS ABOVE\n",
164+
" )\n",
165+
"```\n",
166+
"\n",
167+
"This is known to solve bug related to multi processing, but also to reduce the amount of RAM taken (in some cases) as well as creation time (in some cases)\n",
168+
"\n",
138169
"### Other steps\n",
139170
"\n",
140171
"The grid2op documentation is full of details to \"optimize\" the number of steps you can do per seconds. This number can rise from a few dozen per seconds to around a thousands per seconds with proper care.\n",
@@ -190,25 +221,13 @@
190221
"metadata": {},
191222
"outputs": [],
192223
"source": [
193-
"import gym\n",
224+
"import gymnasium\n",
194225
"import numpy as np\n",
195226
"from grid2op.gym_compat import GymEnv\n",
196227
"env_gym_init = GymEnv(env_glop)\n",
197228
"env_gym = GymEnv(env_glop)\n",
198-
"print(f\"The \\\"env_gym\\\" is a gym environment: {isinstance(env_gym, gym.Env)}\")\n",
199-
"obs_gym = env_gym.reset()"
200-
]
201-
},
202-
{
203-
"cell_type": "markdown",
204-
"metadata": {},
205-
"source": [
206-
"<font size=\"3\" color=\"red\"> In this notebook, we only present some basic (and really \"detailed\" use of the `GymEnv`). </font>\n",
207-
" \n",
208-
"<font size=\"3\" color=\"red\"> This is especially suited for advanced users wanting a deep control over everything happening. </font>\n",
209-
"\n",
210-
"<font size=\"3\" color=\"red\"> For a less advanced usage, feel free to consult the l2rpn baselines package, that embed some usefull environments, compatible with gym, that can embed some heuristics and other \"quality of life\" features. Feel free to use the l2rpn baselines package for more information.\n",
211-
"</font>"
229+
"print(f\"The \\\"env_gym\\\" is a gym environment: {isinstance(env_gym, gymnasium.Env)}\")\n",
230+
"obs_gym, info = env_gym.reset()"
212231
]
213232
},
214233
{
@@ -388,7 +407,7 @@
388407
"outputs": [],
389408
"source": [
390409
"from grid2op.gym_compat import ScalerAttrConverter\n",
391-
"from gym.spaces import Box\n",
410+
"from gymnasium.spaces import Box\n",
392411
"ob_space = env_gym.observation_space\n",
393412
"ob_space = ob_space.reencode_space(\"actual_dispatch\",\n",
394413
" ScalerAttrConverter(substract=0.,\n",
@@ -518,11 +537,11 @@
518537
"source": [
519538
"# gym specific, we simply do a copy paste of what we did in the previous cells, wrapping it in the\n",
520539
"# MyEnv class, and train a Proximal Policy Optimisation based agent\n",
521-
"import gym\n",
540+
"import gymnasium\n",
522541
"import ray\n",
523542
"import numpy as np\n",
524543
" \n",
525-
"class MyEnv(gym.Env):\n",
544+
"class MyEnv(gymnasium.Env):\n",
526545
" def __init__(self, env_config):\n",
527546
" import grid2op\n",
528547
" from grid2op.gym_compat import GymEnv\n",
@@ -537,7 +556,7 @@
537556
"\n",
538557
" # 2. create the gym environment\n",
539558
" self.env_gym = GymEnv(self.env_glop)\n",
540-
" obs_gym = self.env_gym.reset()\n",
559+
" obs_gym, info = self.env_gym.reset()\n",
541560
"\n",
542561
" # 3. (optional) customize it (see section above for more information)\n",
543562
" ## customize action space\n",
@@ -576,9 +595,9 @@
576595
" # 4. bis: to avoid other type of issues, we recommend to build the action space and observation\n",
577596
" # space directly from the spaces class.\n",
578597
" d = {k: v for k, v in self.env_gym.observation_space.spaces.items()}\n",
579-
" self.observation_space = gym.spaces.Dict(d)\n",
598+
" self.observation_space = gymnasium.spaces.Dict(d)\n",
580599
" a = {k: v for k, v in self.env_gym.action_space.items()}\n",
581-
" self.action_space = gym.spaces.Dict(a)\n",
600+
" self.action_space = gymnasium.spaces.Dict(a)\n",
582601
"\n",
583602
" def reset(self):\n",
584603
" obs = self.env_gym.reset()\n",
@@ -791,7 +810,7 @@
791810
" )\n",
792811
" }\n",
793812
" )\n",
794-
"obs_gym = env_sb.reset()"
813+
"obs_gym, info = env_sb.reset()"
795814
]
796815
},
797816
{
@@ -877,13 +896,13 @@
877896
"outputs": [],
878897
"source": [
879898
"from grid2op.gym_compat import BoxGymActSpace\n",
880-
"scale_gen = env_sb.init_env.gen_max_ramp_up + env_sb.init_env.gen_max_ramp_down\n",
881-
"scale_gen[~env_sb.init_env.gen_redispatchable] = 1.0\n",
899+
"scaler_gen = env_sb.init_env.gen_max_ramp_up + env_sb.init_env.gen_max_ramp_down\n",
900+
"scaler_gen = scaler_gen[env_sb.init_env.gen_redispatchable]\n",
882901
"env_sb.action_space = BoxGymActSpace(env_sb.init_env.action_space,\n",
883902
" attr_to_keep=[\"redispatch\"],\n",
884-
" multiply={\"redispatch\": scale_gen},\n",
903+
" multiply={\"redispatch\": scaler_gen},\n",
885904
" )\n",
886-
"obs_gym = env_sb.reset()"
905+
"obs_gym, info = env_sb.reset()"
887906
]
888907
},
889908
{
@@ -937,7 +956,7 @@
937956
"reencoded_act_space = MultiDiscreteActSpace(env_sb.init_env.action_space,\n",
938957
" attr_to_keep=[\"set_line_status\", \"set_bus\", \"redispatch\"])\n",
939958
"env_sb.action_space = reencoded_act_space\n",
940-
"obs_gym = env_sb.reset()"
959+
"obs_gym, info = env_sb.reset()"
941960
]
942961
},
943962
{
@@ -1041,7 +1060,7 @@
10411060
" )\n",
10421061
" }\n",
10431062
" )\n",
1044-
"obs_gym = env_tfa.reset()"
1063+
"obs_gym, info = env_tfa.reset()"
10451064
]
10461065
},
10471066
{
@@ -1297,7 +1316,7 @@
12971316
"name": "python",
12981317
"nbconvert_exporter": "python",
12991318
"pygments_lexer": "ipython3",
1300-
"version": "3.8.10"
1319+
"version": "3.10.13"
13011320
}
13021321
},
13031322
"nbformat": 4,

0 commit comments

Comments
 (0)