Skip to content

Commit

Permalink
Merge pull request #91 from Grid2op/bd-dev
Browse files Browse the repository at this point in the history
Upgrade to version 0.9.2
  • Loading branch information
BDonnot authored Oct 18, 2024
2 parents 275569f + d22a076 commit 535a65b
Show file tree
Hide file tree
Showing 25 changed files with 506 additions and 108 deletions.
10 changes: 5 additions & 5 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ jobs:
command: |
source venv_test/bin/activate
pip uninstall gym -y
pip install gymnasium
pip install "gymnasium<1" # issue with OrderedDict otherwise
pip install "grid2op~=1.9.0"
python -m unittest lightsim2grid/tests/test_compat_legacy_grid2op.py
- run:
Expand Down Expand Up @@ -210,7 +210,7 @@ jobs:
command: |
source venv_test/bin/activate
pip uninstall gym -y
pip install gymnasium
pip install "gymnasium<1" # issue with OrderedDict otherwise
pip install grid2op==1.9.0
python -m unittest lightsim2grid/tests/test_compat_legacy_grid2op.py
- run:
Expand Down Expand Up @@ -366,7 +366,7 @@ jobs:
command: |
source venv_test/bin/activate
pip install --upgrade pip setuptools wheel
git clone https://github.com/rte-france/grid2op.git _grid2op
git clone https://github.com/Grid2Op/grid2op.git _grid2op
pip install -e _grid2op
- run:
name: "Show package versions"
Expand Down Expand Up @@ -583,7 +583,7 @@ jobs:
command: |
source venv_test/bin/activate
pip install --upgrade pip setuptools wheel
git clone https://github.com/rte-france/grid2op.git _grid2op
git clone https://github.com/Grid2Op/grid2op.git _grid2op
pip install -e _grid2op
- run:
name: "Show package versions"
Expand Down Expand Up @@ -619,7 +619,7 @@ jobs:
command: |
.\venv_test\Scripts\activate
pip install gymnasium "numpy<2" pybind11 scipy
git clone https://github.com/rte-france/grid2op.git _grid2op
git clone https://github.com/Grid2Op/grid2op.git _grid2op
pip install -e _grid2op gymnasium
- run:
name: "Install lightsim2grid"
Expand Down
28 changes: 19 additions & 9 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,17 @@ TODO: in `main.cpp` check the returned policy of pybind11 and also the `py::call
TODO: a cpp class that is able to compute (DC powerflow) ContingencyAnalysis and TimeSeries using PTDF and LODF
TODO: integration test with pandapower (see `pandapower/contingency/contingency.py` and import `lightsim2grid_installed` and check it's True)

[0.9.1] 2024-xx-yy
[0.9.2] 2024-10-18
--------------------------
- [ADDED] support loading a grid when everything is NOT on the same bus
(`topo_vect` used to be wrong in this case). This is especially usefull
for grid loaded with `pypowsybl`
- [ADDED] a file benchmarking the timings for running powerflow on different
grid sizes.
- [UPDATED] urls to match the new repo location
- [UPDATED] urls to match new grid2op location

[0.9.1] 2024-09-30
--------------------------
- [FIXED] a bug due to wrong type (in a numpy array) for the element name which lead in turn
to a fail assertion (equality between two numpy arrays returning a bool and not an array)
Expand All @@ -46,7 +56,7 @@ TODO: integration test with pandapower (see `pandapower/contingency/contingency.
one substation in lightsim2grid.
- [IMPROVED] removing a weird `1j * h_` when initializing powerlines and transformers. This was
part of a pandapower "hack" which is not present anymore (see
https://github.com/BDonnot/lightsim2grid/issues/88#issue-2443299039)
https://github.com/Grid2Op/lightsim2grid/issues/88#issue-2443299039)

[0.9.0] 2024-07-29
--------------------------
Expand Down Expand Up @@ -225,7 +235,7 @@ gridmodel.get_Bf() gridmodel.get_Bf_solver()
- [IMPROVED] computation speed: grid is not read another time in some cases.
For example, if load and generators do not change, then Sbus is not
recomputed. Likewise, if the topology does not change, then the Ybus
is not recomputed either see https://github.com/BDonnot/lightsim2grid/issues/72
is not recomputed either see https://github.com/Grid2Op/lightsim2grid/issues/72

[0.7.5.post1] 2024-03-14
-------------------------
Expand All @@ -238,12 +248,12 @@ gridmodel.get_Bf() gridmodel.get_Bf_solver()
multiple powerflows used the same solver
- [FIXED] a bug in AC and DC powerflow when shunts had active values
- [ADDED] possibility to initialize a powergrid based on pypowsybl
see https://github.com/BDonnot/lightsim2grid/issues/53
see https://github.com/Grid2Op/lightsim2grid/issues/53
- [ADDED] some more algorithm to perform powerflow: Fast Decoupled Powerflow (in BX and XB variant)
see https://github.com/BDonnot/lightsim2grid/issues/63
see https://github.com/Grid2Op/lightsim2grid/issues/63
- [ADDED] build lightsim2grid for python 3.12
- [ADDED] support for non distributed slack but multiple slack buses
see https://github.com/BDonnot/lightsim2grid/issues/50 (ONLY FOR AC powerflow)
see https://github.com/Grid2Op/lightsim2grid/issues/50 (ONLY FOR AC powerflow)
- [IMPROVED] now shipping `src` and `eigen` directory in the source of
lightsim2grid to allow their installation if wheels are not provided.
- [IMPROVED] in the underlying cpp GridModel powerlines can now have 2
Expand All @@ -260,7 +270,7 @@ gridmodel.get_Bf() gridmodel.get_Bf_solver()
- [IMPROVED] initialize the underlying "PandaPowerBackend" without numba
- [IMPROVED] grid2op import to be more compliant with renaming of uppercased file names
- [IMPROVED] decoupling of the PandapowerBackend class and the class "internally" used by LightSimBackend
when loading the grid. This caused some issue, *eg* https://github.com/rte-france/Grid2Op/issues/508
when loading the grid. This caused some issue, *eg* https://github.com/Grid2Op/grid2op/issues/508

[0.7.2] 2023-06-06
--------------------
Expand Down Expand Up @@ -378,7 +388,7 @@ gridmodel.get_Bf() gridmodel.get_Bf_solver()
- [FIXED] a bug for static generator (wrong signed convention were used in some part of the c++ code). This has
no impact at all for provided grid2op environments.
- [FIXED] An issue where the backend could get "stuck" in a wrong state because of the way the Vinit was computed (see
`Issue 30 <https://github.com/BDonnot/lightsim2grid/issues/30>`_)
`Issue 30 <https://github.com/Grid2Op/lightsim2grid/issues/30>`_)
- [ADDED] experimental support for the `NICSLU` linear solver (requires a proper license and library, see
https://github.com/chenxm1986/nicslu for more information. Support does not include multi threaded at the moment).
- [IMPROVED] minor performance improvements for the solvers based on Newton Raphson (faster filling of the Jacobian
Expand Down Expand Up @@ -406,7 +416,7 @@ gridmodel.get_Bf() gridmodel.get_Bf_solver()
[0.5.1] 2021-04-09
-------------------
- [FIXED] yet another compilation issue with clang (see
`Issue 22 <https://github.com/BDonnot/lightsim2grid/issues/22>`_)
`Issue 22 <https://github.com/Grid2Op/lightsim2grid/issues/22>`_)
- [ADDED] circleci to check compilation for gcc
- [ADDED] circleci to check compilation for clang
- [ADDED] circleci to check compilation for msvc
Expand Down
2 changes: 1 addition & 1 deletion DISCLAIMER.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ This disclaimer only serves as a complement to the [`LICENSE`](LICENSE.md) file
replacement of this file.

The simulator implemented in this package is made for speed mainly to serve as a grid2op backend (see
https://github.com/rte-france/grid2op for more information). We recall here that grid2op is a research testbed platform
https://github.com/Grid2Op/grid2op for more information). We recall here that grid2op is a research testbed platform
aiming at emulating sequential decisions making in powergrids targeting mainly the "reinforcement learning"
community (though open to anyone).

Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,7 @@ If you use this package in one of your work, please cite:
year = {2020},
publisher = {GitHub},
journal = {GitHub repository},
howpublished = {\url{https://github.com/bdonnot/lightsim2grid}},
howpublished = {\url{https://github.com/Grid2Op/lightsim2grid}},
}
```
Expand Down Expand Up @@ -269,7 +269,7 @@ using the Newton-Raphson algorithm, with a single slack bus, without enforcing q
**NB** to run these tests you need to install grid2op from source otherwise all the test of the LightSim2gridBackend
will fail. In order to do so you can do:
```
git clone https://github.com/rte-france/Grid2Op.git
git clone https://github.com/Grid2Op/grid2op.git
cd Grid2Op
pip3 install -U -e .
cd ..
Expand Down
138 changes: 102 additions & 36 deletions benchmarks/benchmark_grid_size.py
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,53 @@ def get_loads_gens(load_p_init, load_q_init, gen_p_init, sgen_p_init, prng):
return load_p, load_q, gen_p, sgen_p


def run_grid2op_env(env_lightsim, case, reset_solver,
solver_preproc_solver_time,
g2op_speeds,
g2op_step_time,
ls_solver_time,
ls_gridmodel_time,
g2op_sizes
):
_ = env_lightsim.reset()
done = False
nb_step = 0
changed_sgen = case.sgen["in_service"].values
while not done:
# hack for static gen...
changed_sgen = copy.deepcopy(case.sgen["in_service"].values)
this_sgen = sgen_p[nb_step, :].astype(np.float32)
# this_sgen = sgen_p_init[changed_sgen].astype(np.float32)
env_lightsim.backend._grid.update_sgens_p(changed_sgen, this_sgen)
obs, reward, done, info = env_lightsim.step(env_lightsim.action_space())
if reset_solver:
env_lightsim.backend._grid.tell_solver_need_reset()
nb_step += 1

# NB lightsim2grid does not handle "static gen" because I cannot set "p" in gen in grid2op
# so results will vary between TimeSeries and grid2op !
# env_lightsim.backend._grid.tell_solver_need_reset()
# env_lightsim.backend._grid.dc_pf(env_lightsim.backend.V, 1, 1e-7)
# env_lightsim.backend._grid.get_bus_status()
if nb_step != nb_ts:
warnings.warn(f"only able to make {nb_step} (out of {nb_ts}) for {case_name} in grid2op. Results will not be availabe for grid2op step")
solver_preproc_solver_time.append(None)
g2op_speeds.append(None)
g2op_step_time.append(None)
ls_solver_time.append(None)
ls_gridmodel_time.append(None)
else:
total_time = env_lightsim.backend._timer_preproc + env_lightsim.backend._timer_solver # + env_lightsim.backend._timer_postproc
# total_time = env_lightsim._time_step
solver_preproc_solver_time.append(total_time)
g2op_speeds.append(1.0 * nb_step / total_time)
g2op_step_time.append(1.0 * env_lightsim._time_step / nb_step)
ls_solver_time.append(env_lightsim.backend.comp_time)
ls_gridmodel_time.append(env_lightsim.backend.timer_gridmodel_xx_pf)
g2op_sizes.append(env_lightsim.n_sub)
return nb_step


if __name__ == "__main__":
prng = np.random.default_rng(42)
case_names_displayed = [get_env_name_displayed(el) for el in case_names]
Expand All @@ -194,6 +241,13 @@ def get_loads_gens(load_p_init, load_q_init, gen_p_init, sgen_p_init, prng):
ls_solver_time = []
ls_gridmodel_time = []

solver_preproc_solver_time_reset = []
g2op_speeds_reset = []
g2op_sizes_reset = []
g2op_step_time_reset = []
ls_solver_time_reset = []
ls_gridmodel_time_reset = []

ts_times = []
ts_speeds = []
ts_sizes = []
Expand Down Expand Up @@ -269,40 +323,25 @@ def get_loads_gens(load_p_init, load_q_init, gen_p_init, sgen_p_init, prng):
gen_p_g2op,
sgen_p)
# Perform the computation using grid2op
_ = env_lightsim.reset()
done = False
nb_step = 0
changed_sgen = case.sgen["in_service"].values
while not done:
# hack for static gen...
changed_sgen = copy.deepcopy(case.sgen["in_service"].values)
this_sgen = sgen_p[nb_step, :].astype(np.float32)
# this_sgen = sgen_p_init[changed_sgen].astype(np.float32)
env_lightsim.backend._grid.update_sgens_p(changed_sgen, this_sgen)
obs, reward, done, info = env_lightsim.step(env_lightsim.action_space())
nb_step += 1
# NB lightsim2grid does not handle "static gen" because I cannot set "p" in gen in grid2op
# so results will vary between TimeSeries and grid2op !
# env_lightsim.backend._grid.tell_solver_need_reset()
# env_lightsim.backend._grid.dc_pf(env_lightsim.backend.V, 1, 1e-7)
# env_lightsim.backend._grid.get_bus_status()
if nb_step != nb_ts:
warnings.warn(f"only able to make {nb_step} (out of {nb_ts}) for {case_name} in grid2op. Results will not be availabe for grid2op step")
solver_preproc_solver_time.append(None)
g2op_speeds.append(None)
g2op_step_time.append(None)
ls_solver_time.append(None)
ls_gridmodel_time.append(None)
g2op_sizes.append(env_lightsim.n_sub)
else:
total_time = env_lightsim.backend._timer_preproc + env_lightsim.backend._timer_solver # + env_lightsim.backend._timer_postproc
# total_time = env_lightsim._time_step
solver_preproc_solver_time.append(total_time)
g2op_speeds.append(1.0 * nb_step / total_time)
g2op_step_time.append(1.0 * env_lightsim._time_step / nb_step)
ls_solver_time.append(env_lightsim.backend.comp_time)
ls_gridmodel_time.append(env_lightsim.backend.timer_gridmodel_xx_pf)
g2op_sizes.append(env_lightsim.n_sub)
reset_solver = True # non default
nb_step_reset = run_grid2op_env(env_lightsim, case, reset_solver,
solver_preproc_solver_time_reset,
g2op_speeds_reset,
g2op_step_time_reset,
ls_solver_time_reset,
ls_gridmodel_time_reset,
g2op_sizes_reset
)

reset_solver = False # default
nb_step = run_grid2op_env(env_lightsim, case, reset_solver,
solver_preproc_solver_time,
g2op_speeds,
g2op_step_time,
ls_solver_time,
ls_gridmodel_time,
g2op_sizes
)

# Perform the computation using TimeSerie
env_lightsim.reset()
Expand Down Expand Up @@ -362,8 +401,36 @@ def get_loads_gens(load_p_init, load_q_init, gen_p_init, sgen_p_init, prng):
print_configuration()
print(f"Solver used for linear algebra: {linear_solver_used_str}")
print()

print("Results using grid2op.steps (288 consecutive steps, only measuring 'dc pf [init] + ac pf') (no recycling allowed, non default)")
tab_g2op = []
for i, nm_ in enumerate(case_names_displayed):
tab_g2op.append((nm_,
ts_sizes[i],
1000. * g2op_step_time_reset[i] if g2op_step_time_reset[i] else None,
1000. / g2op_speeds_reset[i] if g2op_speeds_reset[i] else None,
g2op_speeds_reset[i],
1000. * ls_gridmodel_time_reset[i] / nb_step_reset if ls_gridmodel_time_reset[i] else None,
1000. * ls_solver_time_reset[i] / nb_step_reset if ls_solver_time_reset[i] else None,
))
if TABULATE_AVAIL:
res_use_with_grid2op_2 = tabulate(tab_g2op,
headers=["grid",
"size (nb bus)",
"avg step duration (ms)",
"time [DC + AC] (ms / pf)",
"speed (pf / s)",
"time in 'gridmodel' (ms / pf)",
"time in 'pf algo' (ms / pf)",
],
tablefmt="rst")
print(res_use_with_grid2op_2)
else:
print(tab_g2op)
print()


print("Results using grid2op.steps (288 consecutive steps, only measuring 'dc pf [init] + ac pf')")
print("Results using grid2op.steps (288 consecutive steps, only measuring 'dc pf [init] + ac pf') (recyling allowed, default)")
tab_g2op = []
for i, nm_ in enumerate(case_names_displayed):
tab_g2op.append((nm_,
Expand All @@ -390,7 +457,6 @@ def get_loads_gens(load_p_init, load_q_init, gen_p_init, sgen_p_init, prng):
print(tab_g2op)
print()


print("Results for TimeSeries (288 consecutive steps)")
tab_ts = []
for i, nm_ in enumerate(case_names_displayed):
Expand Down
2 changes: 1 addition & 1 deletion docs/benchmarks.rst
Original file line number Diff line number Diff line change
Expand Up @@ -365,7 +365,7 @@ The results can be found in:

.. note::
Any contribution here is more than welcomed. You can write a github discussion here
https://github.com/BDonnot/lightsim2grid/discussions/new?category=show-and-tell
https://github.com/Grid2Op/lightsim2grid/discussions/new?category=show-and-tell
and describe rapidly your setup and we'll make sure to include your benchmark in future release.

Thanks !
Expand Down
Loading

0 comments on commit 535a65b

Please sign in to comment.