Skip to content

Commit 0672167

Browse files
committed
clean a bit commented code, ready for version 0.12.1
Signed-off-by: DONNOT Benjamin <benjamin.donnot@rte-france.com>
1 parent 9633be8 commit 0672167

File tree

10 files changed

+15
-105
lines changed

10 files changed

+15
-105
lines changed

CHANGELOG.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ TODO: in `main.cpp` check the returned policy of pybind11 and also the `py::call
2929
TODO: a cpp class that is able to compute (DC powerflow) ContingencyAnalysis and TimeSeries using PTDF and LODF
3030
TODO: integration test with pandapower (see `pandapower/contingency/contingency.py` and import `lightsim2grid_installed` and check it's True)
3131

32-
[0.12.1] 2026-xx-yy
32+
[0.12.1] 2026-01-09
3333
---------------------
3434
- [FIXED] phase shift transformers are now properly modeled
3535
for both pandapower (new in this version) and pypowsybl (already

benchmarks/test_profile.py

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
prng = np.random.default_rng(42)
2525

2626
CASE_NAME = "case9241pegase.json"
27-
NB_TS = 10
27+
NB_TS = 1000
2828

2929

3030
def my_grid2op_env(case_name, nb_ts, prng):
@@ -88,9 +88,13 @@ def main_gridmodel(case_name=CASE_NAME, nb_ts=NB_TS, reset_algo=True, solver_use
8888
ls_timer_Va_Vm = 0.
8989
ls_timer_pre_proc = 0.
9090
ls_timer_total_nr = 0.
91-
92-
with open(f"gridmodel_{case_name}.pickle", "rb") as f:
93-
ls_grid = pickle.load(f)
91+
try:
92+
with open(f"gridmodel_{case_name}.pickle", "rb") as f:
93+
ls_grid = pickle.load(f)
94+
except FileNotFoundError:
95+
raise RuntimeError("You need to comment 'main_gridmodel(...)` in test_profile.py then uncomment `my_grid2op_env(...)`, "
96+
"run it (without perf it's fine). Then uncomment `main_gridmodel` and comment `my_grid2op_env` "
97+
"and run the benchkmark (with perf) again.")
9498
ls_grid.change_solver(solver_used)
9599
v_init = ls_grid.dc_pf(np.ones(ls_grid.get_bus_vn_kv().shape[0], dtype=complex) * 1.04, 1, 0.1)
96100
for _ in range(nb_ts):

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 = "0.12.1.dev0"
25+
release = "0.12.1"
2626
version = '0.12'
2727

2828
# -- General configuration ---------------------------------------------------

lightsim2grid/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
# SPDX-License-Identifier: MPL-2.0
77
# This file is part of LightSim2grid, LightSim2grid implements a c++ backend targeting the Grid2Op platform.
88

9-
__version__ = "0.12.1.dev0"
9+
__version__ = "0.12.1"
1010

1111
__all__ = [
1212
"newtonpf",

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
from pybind11.setup_helpers import Pybind11Extension, build_ext
1515

1616

17-
__version__ = "0.12.1.dev0"
17+
__version__ = "0.12.1"
1818
KLU_SOLVER_AVAILABLE = False
1919

2020
# Try to link against SuiteSparse (if available)

src/GridModel.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -218,7 +218,7 @@ void GridModel::set_orig_to_ls(const IntVect & orig_to_ls){
218218
}
219219
}
220220

221-
void GridModel::set_ls_to_orig_internal(const IntVect & ls_to_orig){
221+
void GridModel::set_ls_to_orig_internal(const IntVect & ls_to_orig) noexcept{
222222
if(ls_to_orig.size() == 0){
223223
_ls_to_orig = IntVect();
224224
_orig_to_ls = IntVect();

src/GridModel.hpp

Lines changed: 2 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@
4141
#include "ChooseSolver.hpp"
4242

4343
//TODO implement a BFS check to make sure the Ymatrix is "connected" [one single component]
44-
class GridModel final // : public GenericContainer // TODO remove that inheritance
44+
class GridModel final
4545
{
4646
public:
4747
typedef Eigen::Array<int, Eigen::Dynamic, Eigen::RowMajor> IntVectRowMaj;
@@ -53,7 +53,6 @@ class GridModel final // : public GenericContainer // TODO remove that inherita
5353
std::vector<int>, // ls_to_orig
5454
real_type, // init_vm_pu
5555
real_type, //sn_mva
56-
// std::vector<real_type>, // bus_vn_kv
5756
std::vector<bool>, // bus_status
5857
SubstationContainer::StateRes,
5958
// powerlines
@@ -1190,11 +1189,6 @@ class GridModel final // : public GenericContainer // TODO remove that inherita
11901189
real_type get_computation_time() const{ return _solver.get_computation_time();}
11911190
real_type get_dc_computation_time() const{ return _dc_solver.get_computation_time();}
11921191

1193-
// private:
1194-
// using GenericContainer::update_bus_status; // to silence clang warnings (overload-virtual)
1195-
// public:
1196-
// void update_bus_status(int nb_bus_before,
1197-
// Eigen::Ref<Eigen::Array<bool, Eigen::Dynamic, 2, Eigen::RowMajor> > active_bus);
11981192
// part dedicated to grid2op backend, optimized for grid2op data representation (for speed)
11991193
// this is not recommended to use it outside of its intended usage within grid2op !
12001194
void update_gens_p(Eigen::Ref<Eigen::Array<bool, Eigen::Dynamic, Eigen::RowMajor> > has_changed,
@@ -1325,21 +1319,13 @@ class GridModel final // : public GenericContainer // TODO remove that inherita
13251319
const SolverControl & solver_control);
13261320

13271321
//for FDPF
1328-
// private:
1329-
// using GenericContainer::fillBp_Bpp; // silence clang warning overload-virtual
1330-
public:
13311322
void fillBp_Bpp(Eigen::SparseMatrix<real_type> & Bp,
13321323
Eigen::SparseMatrix<real_type> & Bpp,
13331324
FDPFMethod xb_or_bx) const;
1334-
13351325
void init_fdpf_coeffs(){
13361326
powerlines_.init_fdpf_coeffs();
13371327
trafos_.init_fdpf_coeffs();
13381328
}
1339-
1340-
// private:
1341-
// using GenericContainer::fillBf_for_PTDF; // silence clang warning overload-virtual
1342-
public:
13431329
void fillBf_for_PTDF(Eigen::SparseMatrix<real_type> & Bf, bool transpose=false) const;
13441330

13451331
Eigen::SparseMatrix<real_type> debug_get_Bp_python(FDPFMethod xb_or_bx){
@@ -1358,13 +1344,7 @@ class GridModel final // : public GenericContainer // TODO remove that inherita
13581344
}
13591345

13601346
protected:
1361-
void set_ls_to_orig_internal(const IntVect & ls_to_orig); // set both _ls_to_orig and _orig_to_ls
1362-
1363-
// compute admittance matrix
1364-
// dc powerflow
1365-
// void init_dcY(Eigen::SparseMatrix<real_type> & dcYbus);
1366-
1367-
// ac powerflows
1347+
void set_ls_to_orig_internal(const IntVect & ls_to_orig) noexcept; // set both _ls_to_orig and _orig_to_ls
13681348

13691349
// init the Ybus matrix (its size, it is filled up elsewhere) and also the
13701350
// converter from "my bus id" to the "solver bus id" (id_me_to_solver and id_solver_to_me)
@@ -1489,9 +1469,6 @@ class GridModel final // : public GenericContainer // TODO remove that inherita
14891469
}
14901470
return res;
14911471
}
1492-
1493-
// private:
1494-
// using GenericContainer::fillYbus; // to silence the overload-virtual warning in clang
14951472

14961473
protected:
14971474
void fillYbus(Eigen::SparseMatrix<cplx_type> & res, bool ac, const std::vector<SolverBusId>& id_me_to_solver);

src/element_container/LineContainer.cpp

Lines changed: 0 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -68,41 +68,4 @@ void LineContainer::init(const RealVect & branch_r,
6868
init_tsc(branch_from_id, branch_to_id, "trafo");
6969
_update_model_coeffs();
7070
reset_results();
71-
// init_tsc_rxha();
7271
}
73-
74-
// void LineContainer::_update_model_coeffs()
75-
// {
76-
// const auto my_size = r_.size();
77-
78-
// yac_11_ = CplxVect::Zero(my_size);
79-
// yac_12_ = CplxVect::Zero(my_size);
80-
// yac_21_ = CplxVect::Zero(my_size);
81-
// yac_22_ = CplxVect::Zero(my_size);
82-
83-
// ydc_11_ = CplxVect::Zero(my_size);
84-
// ydc_12_ = CplxVect::Zero(my_size);
85-
// ydc_21_ = CplxVect::Zero(my_size);
86-
// ydc_22_ = CplxVect::Zero(my_size);
87-
// for(int i = 0; i < my_size; ++i)
88-
// {
89-
// // for AC
90-
// // see https://matpower.org/docs/MATPOWER-manual.pdf eq. 3.2
91-
// const cplx_type ys = 1. / cplx_type(r_(i), x_(i));
92-
// const cplx_type h_or = h_side_1_(i);
93-
// const cplx_type h_ex = h_side_2_(i);
94-
// yac_11_(i) = (ys + h_or);
95-
// yac_22_(i) = (ys + h_ex);
96-
// yac_12_(i) = -ys;
97-
// yac_21_(i) = -ys;
98-
99-
// // for DC
100-
// // see https://matpower.org/docs/MATPOWER-manual.pdf eq. 3.21
101-
// // except here I only care about the real part, so I remove the "1/j"
102-
// cplx_type tmp = 1. / cplx_type(x_(i), 0.);
103-
// ydc_11_(i) = tmp;
104-
// ydc_22_(i) = tmp;
105-
// ydc_21_(i) = -tmp;
106-
// ydc_12_(i) = -tmp;
107-
// }
108-
// }

src/element_container/LineContainer.hpp

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -88,9 +88,6 @@ class LineContainer : public TwoSidesContainer_rxh_A<OneSideContainer_ForBranch>
8888

8989
// for consistency with trafo, when used for example in BaseMultiplePowerflow...
9090
Eigen::Ref<const RealVect> dc_x_tau_shift() const {return RealVect();}
91-
92-
protected:
93-
// void _update_model_coeffs();
9491

9592
protected:
9693
// physical properties

src/element_container/TrafoContainer.cpp

Lines changed: 0 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -67,13 +67,9 @@ void TrafoContainer::init(
6767
shift_ = trafo_shift_degree / my_180_pi_; // do not forget conversion degree / rad here !
6868
is_tap_side1_ = trafo_tap_side1;
6969
ignore_tap_side_for_shift_ = ignore_tap_side_for_shift;
70-
// bus_hv_id_ = trafo_hv_id;
71-
// bus_lv_id_ = trafo_lv_id;
72-
// status_ = std::vector<bool>(trafo_r.size(), true);
7370
init_tsc(trafo_hv_id, trafo_lv_id, "trafo");
7471
_update_model_coeffs();
7572
reset_results();
76-
// init_tsc_rxha();
7773
}
7874

7975
TrafoContainer::StateRes TrafoContainer::get_state() const
@@ -111,26 +107,6 @@ void TrafoContainer::set_state(TrafoContainer::StateRes & my_state)
111107
reset_results();
112108
}
113109

114-
// void TrafoContainer::_update_model_coeffs()
115-
// {
116-
// const Eigen::Index my_size = r_.size();
117-
118-
// yac_11_ = CplxVect::Zero(my_size);
119-
// yac_12_ = CplxVect::Zero(my_size);
120-
// yac_21_ = CplxVect::Zero(my_size);
121-
// yac_22_ = CplxVect::Zero(my_size);
122-
123-
// ydc_11_ = CplxVect::Zero(my_size);
124-
// ydc_12_ = CplxVect::Zero(my_size);
125-
// ydc_21_ = CplxVect::Zero(my_size);
126-
// ydc_22_ = CplxVect::Zero(my_size);
127-
// dc_x_tau_shift_ = RealVect::Zero(my_size);
128-
// for(Eigen::Index i = 0; i < my_size; ++i)
129-
// {
130-
// _update_model_coeffs_one_el(i);
131-
// }
132-
// }
133-
134110
void TrafoContainer::_update_model_coeffs_one_el(int el_id)
135111
{
136112
// for AC
@@ -171,13 +147,6 @@ void TrafoContainer::_update_model_coeffs_one_el(int el_id)
171147
ydc_12_(el_id) = -tmp;
172148

173149
dc_x_tau_shift_(el_id) = -std::real(tmp) * theta_shift;
174-
// if(ignore_tap_side_for_shift_)
175-
// {
176-
// dc_x_tau_shift_(el_id) = -std::real(tmp) * theta_shift;
177-
// } else {
178-
// if(is_tap_side1_[el_id]) dc_x_tau_shift_(el_id) = -std::real(tmp) * theta_shift;
179-
// else dc_x_tau_shift_(el_id) = std::real(tmp) * theta_shift;
180-
// }
181150
}
182151

183152
void TrafoContainer::hack_Sbus_for_dc_phase_shifter(

0 commit comments

Comments
 (0)