Skip to content

Commit c3c5be0

Browse files
committed
adding possibility to pickle / unpickle each gridmodel container independantly
Signed-off-by: DONNOT Benjamin <[email protected]>
1 parent 8a20401 commit c3c5be0

21 files changed

+608
-135
lines changed

CHANGELOG.rst

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,9 @@ TODO: integration test with pandapower (see `pandapower/contingency/contingency.
3434
- [FIXED] phase shift transformers are now properly modeled
3535
for both pandapower (new in this version) and pypowsybl (already
3636
the case in previous version)
37+
- [ADDED] possibility to pickle independantly all part of the grid (*eg* gridmodel.get_lines()
38+
can be pickled independantly from anything else) **NB** pickling and un-pickling
39+
lightsim2grid objects can only be used for the same lightsim2grid version.
3740

3841
[0.12.0] 2026-01-06
3942
--------------------

env_compile_all.sh

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
export __COMPILE_MARCHNATIVE=1
2+
export __O3_OPTIM=1
3+
export PATH_CKTSO=`pwd`/cktso
4+
export PATH_NICSLU=`pwd`/nicslu/nicslu202110

lightsim2grid/gridmodel/from_pandapower/_aux_add_trafo.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ def _aux_add_trafo(
8080
if np.any(pp_net.trafo3w["tap_changer_type"].values == "Ideal"):
8181
raise RuntimeError("Ideal phase shifters are not modeled. Please remove all 3-winding trafos "
8282
"with \"tap_changer_type\" set to \"Ideal\".")
83-
83+
8484
tap_angles_ = 1.0 * pp_net.trafo["tap_step_degree"].values
8585
if np.any(~np.isfinite(tap_angles_)):
8686
warnings.warn("There were some Nan in the pp_net.trafo[\"tap_step_degree\"], they have been replaced by 0")
@@ -133,6 +133,7 @@ def _aux_add_trafo(
133133
)
134134

135135
# initialize the grid
136+
do_ignore_tap_side_for_phase_shift = True
136137
model.init_trafo_pandapower(trafo_r,
137138
trafo_x,
138139
trafo_b,
@@ -141,7 +142,8 @@ def _aux_add_trafo(
141142
shift_,
142143
is_tap_hv_side,
143144
pp_bus_to_ls(pp_net.trafo["hv_bus"].values, pp_to_ls),
144-
pp_bus_to_ls(pp_net.trafo["lv_bus"].values, pp_to_ls))
145+
pp_bus_to_ls(pp_net.trafo["lv_bus"].values, pp_to_ls),
146+
do_ignore_tap_side_for_phase_shift)
145147

146148
for tr_id, is_connected in enumerate(pp_net.trafo["in_service"].values):
147149
if not is_connected:

lightsim2grid/gridmodel/from_pypowsybl/_from_pypowsybl.py

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -361,15 +361,16 @@ def init(net : pypo.network.Network,
361361
ratio_tap_changer = net_pu.get_ratio_tap_changers()
362362

363363
if 'alpha' in df_trafo_pu:
364-
shift_ = -np.rad2deg(df_trafo_pu['alpha'].values) # given in radian by pypowsybl
364+
shift_ = np.rad2deg(df_trafo_pu['alpha'].values) # given in radian by pypowsybl
365365
else:
366366
if net.get_phase_tap_changers().shape[0] > 0:
367367
raise RuntimeError("Phase tap changer are not handled by the pypowsybl converter "
368368
"when not accessible using the 'alpha' columns "
369369
"of the net (once per unit). Please upgrade pypowsybl."
370370
"NB: phase tap change are handled by lightsim2grid)")
371371
shift_ = np.zeros(df_trafo.shape[0])
372-
is_tap_hv_side = np.zeros(df_trafo.shape[0], dtype=bool) # TODO
372+
# tap is side 2 in IIDM
373+
is_tap_side1 = np.zeros(df_trafo.shape[0], dtype=bool)
373374
trafo_r = df_trafo_pu["r"].values
374375
trafo_x = df_trafo_pu["x"].values
375376
trafo_h = (df_trafo_pu["g"].values + 1j * df_trafo_pu["b"].values)
@@ -398,9 +399,11 @@ def init(net : pypo.network.Network,
398399
trafo_h,
399400
ratio,
400401
shift_, # in degree !
401-
is_tap_hv_side,
402+
is_tap_side1,
402403
tor_bus,
403-
tex_bus)
404+
tex_bus,
405+
False, # ignore_tap_side_for_phase_shift is False for pypowsybl
406+
)
404407
for t_id, (is_or_disc, is_ex_disc) in enumerate(zip(tor_disco, tex_disco)):
405408
if is_or_disc or is_ex_disc:
406409
model.deactivate_trafo(t_id)
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
import os
2+
import pickle
3+
import warnings
4+
import grid2op
5+
from lightsim2grid import LightSimBackend
6+
7+
8+
def main():
9+
with warnings.catch_warnings():
10+
warnings.filterwarnings("ignore")
11+
env = grid2op.make("l2rpn_idf_2023", test=True, backend=LightSimBackend())
12+
gridmodel = env.backend._grid
13+
14+
with open(os.path.join("test_pickle.pickle"), "wb") as f:
15+
pickle.dump(gridmodel, f)
16+
17+
for fun_name in [
18+
"get_loads",
19+
"get_lines",
20+
"get_trafos",
21+
"get_storages",
22+
"get_generators",
23+
"get_shunts",
24+
"get_substations",
25+
]:
26+
with open(os.path.join(f"test_pickle_{fun_name}.pickle"), "wb") as f:
27+
pickle.dump(getattr(gridmodel, fun_name)(), f)
28+
29+
if __name__ == "__main__":
30+
main()
31.4 KB
Binary file not shown.
Binary file not shown.
16 KB
Binary file not shown.
3.82 KB
Binary file not shown.
419 Bytes
Binary file not shown.

0 commit comments

Comments
 (0)