Skip to content

Commit 777868b

Browse files
authored
Merge pull request #721 from Grid2op/dev_1.12.1
Minor fixes + great improvment in processing time
2 parents d87c5d1 + 67b4c75 commit 777868b

File tree

102 files changed

+5600
-1965
lines changed

Some content is hidden

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

102 files changed

+5600
-1965
lines changed

.circleci/config.yml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -175,6 +175,10 @@ jobs:
175175
source venv_test/bin/activate
176176
python -m pip install -U pip setuptools wheel
177177
python -m pip install -U numba
178+
- run:
179+
command: |
180+
rm pyproject.toml
181+
cp pyproject_38.toml pyproject.toml
178182
- run:
179183
command: |
180184
source venv_test/bin/activate
@@ -213,6 +217,10 @@ jobs:
213217
source venv_test/bin/activate
214218
python -m pip install -U pip setuptools wheel
215219
python -m pip install -U lightsim2grid==0.5.3 gymnasium "numpy<1.22"
220+
- run:
221+
command: |
222+
rm pyproject.toml
223+
cp pyproject_38.toml pyproject.toml
216224
- run:
217225
command: |
218226
source venv_test/bin/activate
@@ -236,6 +244,10 @@ jobs:
236244
source venv_test/bin/activate
237245
python -m pip install -U pip setuptools wheel
238246
python -m pip install -U lightsim2grid==0.6.0 gymnasium "numpy<1.22"
247+
- run:
248+
command: |
249+
rm pyproject.toml
250+
cp pyproject_38.toml pyproject.toml
239251
- run:
240252
command: |
241253
source venv_test/bin/activate

.github/workflows/main.yml

Lines changed: 29 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ jobs:
4444
version: '3.12',
4545
}
4646
- {
47-
name: cp313, # issue with pandapower atm
47+
name: cp313,
4848
abi: cp313,
4949
version: '3.13',
5050
}
@@ -61,13 +61,17 @@ jobs:
6161

6262
- name: Install Python dependencies
6363
run: |
64-
python -m pip install --upgrade pip
65-
python -m pip install --upgrade wheel
66-
python -m pip install --upgrade setuptools
67-
64+
python -m pip install --upgrade pip wheel setuptools build
65+
66+
- name: Rename pyproject_38.toml file (python 3.8)
67+
if: matrix.python.name == 'cp38'
68+
run: |
69+
rm pyproject.toml
70+
cp pyproject_38.toml pyproject.toml
71+
6872
- name: Build wheel
6973
run: |
70-
python setup.py bdist_wheel
74+
python -m build --wheel .
7175
7276
- name: Install wheel
7377
run: |
@@ -103,7 +107,7 @@ jobs:
103107
- name: Upload wheel
104108
uses: actions/upload-artifact@v4
105109
with:
106-
name: grid2op-wheel-${{ matrix.config.name }}-${{ matrix.python.name }}
110+
name: grid2op-wheel-${{ matrix.python.name }}
107111
path: dist/*.whl
108112

109113
macos_windows_build:
@@ -141,7 +145,7 @@ jobs:
141145
name: cp312,
142146
version: '3.12',
143147
}
144-
- { # issue with pandapower atm
148+
- {
145149
name: cp313,
146150
version: '3.13',
147151
}
@@ -160,12 +164,22 @@ jobs:
160164

161165
- name: Install Python dependencies
162166
run: |
163-
python -m pip install --upgrade pip
164-
python -m pip install --upgrade wheel
165-
python -m pip install --upgrade setuptools
167+
python -m pip install --upgrade pip wheel setuptools build
168+
169+
- name: Rename pyproject_38.toml file (python 3.8 - macos)
170+
if: ((matrix.python.name == 'cp38') && (matrix.config.name == 'darwin'))
171+
run: |
172+
rm pyproject.toml
173+
cp pyproject_38.toml pyproject.toml
174+
175+
- name: Rename pyproject_38.toml file (python 3.8 - windows)
176+
if: ((matrix.python.name == 'cp38') && (matrix.config.name == 'windows'))
177+
run: |
178+
del pyproject.toml
179+
cp pyproject_38.toml pyproject.toml
166180
167181
- name: Build wheel
168-
run: python setup.py bdist_wheel
182+
run: python -m build --wheel .
169183

170184
- name: Install wheel
171185
shell: bash
@@ -181,7 +195,7 @@ jobs:
181195
182196
- name: Build source archive
183197
if: matrix.config.name == 'darwin' && matrix.python.name == 'cp310'
184-
run: python setup.py sdist
198+
run: python -m build --sdist .
185199

186200
- name: Upload wheel
187201
uses: actions/upload-artifact@v4
@@ -238,10 +252,10 @@ jobs:
238252

239253
- name: Install Python dependencies
240254
run: |
241-
python -m pip install --upgrade pip wheel setuptools gymnasium
255+
python -m pip install --upgrade pip wheel setuptools gymnasium build
242256
243257
- name: Build wheel
244-
run: python setup.py bdist_wheel
258+
run: python -m build --wheel .
245259

246260
- name: Install wheel
247261
shell: bash

.gitignore

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -417,6 +417,26 @@ grid2op/tests/venv_test_autoclass/
417417
test_eduardo.py
418418
grid2op/tests/failed_test*
419419
venv_312
420+
grid2op_test_issue_discord.ipynb
421+
grid2op_test_issue_discord_orig.ipynb
422+
grid_bug_pp3.json
423+
grid_bug_pp3_3.json
424+
grid_bug_pp3_3_orig.json
425+
issue_new_pp.py
426+
log.txt
427+
venv_*/**
428+
TestLM.ipynb
429+
bug_pp3.py
430+
bug_pp3_repro.py
431+
change_file_mode.py
432+
file_changed.txt
433+
test_ljn_theta.py
434+
test_multiproc_shared_act.py
435+
saved_MANIFEST.in
436+
saved_setup.cfg
437+
saved_setup.py
438+
requirements_pp2.txt
439+
requirements_pp3.txt
420440

421441
# profiling files
422442
**.prof

CHANGELOG.rst

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,40 @@ Native multi agents support:
100100
- add detachment
101101
- add change_bus / set_bus
102102

103+
[1.12.1] - 2025-08-28
104+
----------------------
105+
- [BREAKING] (small impact) action "property" `shunt_p`, `shunt_q` and `shunt_bus`
106+
are now named `_shunt_p`, `_shunt_q` and `_shunt_bus`.
107+
- [BREAKING] (small impact): new convention for `env._gen_uptime` and
108+
`env._gen_downtime`: if a generator `gen_id` is disconnected, then
109+
`env._gen_uptime[gen_id] = -1` and if it is connected, then
110+
`env._gen_downtime[gen_id] = -1`
111+
- [BREAKING] (small impact): new convention for `env._gen_uptime` and
112+
`env._gen_downtime`: they are 0 (and not 1) at the initial observation
113+
(`env._gen_uptime` is 0 after the env.reset for connected generator and
114+
still -1 - see point above- for disconnected ones)
115+
- [FIXED] when using the default action converter from gym_compat module,
116+
it only generates actions that can be performed by the user (authorized by
117+
the rules and the action class)
118+
- [FIXED] `env._gen_uptime` and `env._gen_downtime` are now properly updated
119+
after a generator has been detached from the grid.
120+
- [ADDED] the possibility to act on the backend directly from the action
121+
with the "act."
122+
- [ADDED] set `pandas<3` in the dependencies, to make sure PandapowerBackend
123+
still work (ChainedAssignmentError still occur)
124+
- [IMPROVED] some pandas `ChainedAssignmentError` warning in pandapower backend
125+
(more work is required in this direction)
126+
- [IMPROVED] consistency between AmbiguousAction and IllegalAction exceptions:
127+
when an action cannot be built, it is ambiguous now and not illegal.
128+
- [IMPROVED] cleaner installation, relying only on "pyproject.toml"
129+
- [IMPROVED] documentation of "how to create a new grid2op observation"
130+
having different attributes.
131+
- [IMPROVED] documentation of the "action" class
132+
- [IMPROVED] computation speed, especially in cases of "do nothing"
133+
- [IMPROVED] if the same action is used multiple times, the "is_ambiguous()"
134+
method will be computed only once (results will be cached).
135+
- [IMPROVED] computation times at various places (*eg* by avoiding unnecessary copies)
136+
103137
[1.12.0] - 2025-07-24
104138
--------------------------
105139
- [BREAKING] the `info` returned argument of `env.step(...)` function

Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ WORKDIR /Grid2Op
3535
RUN git pull
3636
RUN git remote update
3737
RUN git fetch --all --tags
38-
RUN git checkout "tags/v1.12.0" -b "v1.12.0-branch"
38+
RUN git checkout "tags/v1.12.1" -b "v1.12.1-branch"
3939
# Install Dependencies
4040
RUN pip3 install .[optional,challenge]
4141
WORKDIR /

MANIFEST.in

Lines changed: 0 additions & 5 deletions
This file was deleted.

README.md

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,12 @@ but is also compatible with other *Backend*. If you have at your disposal anothe
127127
the documentation of [grid2op/Backend](grid2op/Backend/Backend.py) can help you integrate it into a proper "Backend"
128128
and have Grid2Op using this powerflow instead of PandaPower.
129129

130+
As of writing, the publically availavble solvers are:
131+
132+
- lightsim2grid : https://github.com/Grid2op/lightsim2grid
133+
- powsybl : https://github.com/Grid2op/pypowsybl2grid
134+
- powermodels (julia) : https://github.com/MOSSLab-MIT/PandaModelsBackend
135+
130136
## Getting Started
131137

132138
Some Jupyter notebook are provided as tutorials for the Grid2Op package. They are located in the
@@ -315,7 +321,6 @@ The complete test suit is run on linux with the latest numpy version on python 3
315321

316322
### Known issues
317323

318-
319324
#### Multi processing
320325
Due to the underlying behaviour of the "multiprocessing" package on windows based python versions,
321326
the "multiprocessing" of the grid2op "Runner" is not supported on windows. This might change in the future,
@@ -328,6 +333,18 @@ Sometimes, on some configuration (python version) we do not recommend to use gri
328333
If you encounter any trouble, please downgrade to pandas<2.2. This behaviour occured in our continuous
329334
integration environment for python >=3.9 but could not be reproduced locally.
330335

336+
#### python 3.8
337+
338+
From grid2op 1.12.1, the python 3.8 install is a bit more complicated.
339+
340+
If you want to install it from source, you have to delete "pyproject.toml" file.
341+
342+
Then rename the "pyproject_38.toml" file to (new name) "pyproject.toml".
343+
344+
Finally "pip install grid2op" normally.
345+
346+
This is due to the "cleaning" of the installation process that now uses only *pyproject.toml*. And because pyproject has changed the way it identifies "licenses" (before it uses "license" with a table, but this way is deprecated, now it uses "license-files", but it is not supported by a setuptools usable in python 3.8)
347+
331348
#### python 3.11
332349
Some version of grid2op (*eg* 1.6.3) are not compatible with python 3.10 or 3.11.
333350

_profiling/profiler_do_nothing.py

Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
# Copyright (c) 2019-2020, RTE (https://www.rte-france.com)
2+
# See AUTHORS.txt
3+
# This Source Code Form is subject to the terms of the Mozilla Public License, version 2.0.
4+
# If a copy of the Mozilla Public License, version 2.0 was not distributed with this file,
5+
# you can obtain one at http://mozilla.org/MPL/2.0/.
6+
# SPDX-License-Identifier: MPL-2.0
7+
# This file is part of Grid2Op, Grid2Op a testbed platform to model sequential decision making in power systems.
8+
9+
"""
10+
This file should be used to assess the performance of grid2op in "runner" mode: the loading time are not studied,
11+
neither are the import times.
12+
13+
Data are loaded only once, when the environment is "done" the programm stops.
14+
15+
This corresponds to the situation: you have a trained agent, you want to assess its performance using the runner
16+
"""
17+
18+
import numpy as np
19+
import os
20+
21+
from grid2op import make
22+
from grid2op.Parameters import Parameters
23+
from grid2op.Rules import AlwaysLegal
24+
from grid2op.Backend import PandaPowerBackend
25+
from grid2op.Agent import DoNothingAgent
26+
import cProfile
27+
28+
from utils_benchmark import run_env, str2bool
29+
30+
try:
31+
from lightsim2grid import LightSimBackend
32+
light_sim_avail = True
33+
except ImportError:
34+
light_sim_avail = False
35+
36+
ENV_NAME = "rte_case5_example"
37+
ENV_NAME = "rte_case14_realistic"
38+
ENV_NAME = "l2rpn_case14_sandbox"
39+
MAX_TS = 1000
40+
41+
42+
def main(max_ts, name, use_lightsim=False, test_env=True):
43+
param = Parameters()
44+
if use_lightsim:
45+
if light_sim_avail:
46+
backend = LightSimBackend()
47+
else:
48+
raise RuntimeError("LightSimBackend not available")
49+
else:
50+
backend = PandaPowerBackend()
51+
52+
param.init_from_dict({"NO_OVERFLOW_DISCONNECTION": True})
53+
54+
env_klu = make(name, backend=backend, param=param, gamerules_class=AlwaysLegal, test=test_env)
55+
agent = DoNothingAgent(action_space=env_klu.action_space)
56+
57+
cp = cProfile.Profile()
58+
cp.enable()
59+
nb_ts_klu, time_klu, aor_klu, gen_p_klu, gen_q_klu, time_step = run_env(env_klu, max_ts, agent)
60+
cp.disable()
61+
print(f'Time for {nb_ts_klu} steps: {time_step} => {time_step / nb_ts_klu} s/step or {nb_ts_klu / time_step:.3e} step / s')
62+
nm_f, ext = os.path.splitext(__file__)
63+
nm_out = "{}_{}_{}.prof".format(nm_f, "lightsim" if use_ls else "pp", name)
64+
cp.dump_stats(nm_out)
65+
print("You can view profiling results with:\n\tsnakeviz {}".format(nm_out))
66+
67+
68+
if __name__ == "__main__":
69+
import argparse
70+
parser = argparse.ArgumentParser(description='Benchmark pyKLU and Pandapower Backend for an agent that takes every '
71+
'topological action possible')
72+
parser.add_argument('--name', default=ENV_NAME, type=str,
73+
help='Environment name to be used for the benchmark.')
74+
parser.add_argument('--number', type=int, default=MAX_TS,
75+
help='Maximum number of time steps for which the benchamark will be run.')
76+
parser.add_argument("--use_ls", type=str2bool, nargs='?',
77+
const=True, default=False,
78+
help="Use the LightSim2Grid Backend.")
79+
parser.add_argument("--no_test", type=str2bool, nargs='?',
80+
const=True, default=False,
81+
help="Do not use a test environment for the profiling (default to False: meaning you use a test env)")
82+
83+
args = parser.parse_args()
84+
85+
max_ts = int(args.number)
86+
name = str(args.name)
87+
use_ls = args.use_ls
88+
test_env = not args.no_test
89+
main(max_ts, name, use_lightsim=use_ls, test_env=test_env)

_profiling/utils_benchmark.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -190,10 +190,13 @@ def run_env(env, max_ts, agent):
190190
nb_ts = 0
191191
prev_act = None
192192
beg_ = time.perf_counter()
193+
time_step = 0.
193194
with tqdm(total=nb_rows) as pbar:
194195
while not done:
195196
act = agent.act(obs, reward, done)
197+
beg_step = time.perf_counter()
196198
obs, reward, done, info = env.step(act)
199+
time_step += time.perf_counter() - beg_step
197200
aor[nb_ts, :] = obs.a_or
198201
gen_p[nb_ts, :] = obs.prod_p
199202
gen_q[nb_ts, :] = obs.prod_q
@@ -208,7 +211,7 @@ def run_env(env, max_ts, agent):
208211
# print(act)
209212
end_ = time.perf_counter()
210213
total_time = end_ - beg_
211-
return nb_ts, total_time, aor, gen_p, gen_q
214+
return nb_ts, total_time, aor, gen_p, gen_q, time_step
212215

213216

214217
def run_env_with_reset(env, max_ts, agent, seed=None):

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.12.0'
25+
release = '1.12.1'
2626
version = '1.12'
2727

2828

0 commit comments

Comments
 (0)