Skip to content

Commit

Permalink
huge renaming to clean src (cpp) repo
Browse files Browse the repository at this point in the history
  • Loading branch information
BDonnot committed Dec 18, 2023
1 parent d37aa42 commit 44cea30
Show file tree
Hide file tree
Showing 51 changed files with 919 additions and 897 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,9 @@ Change Log
- [ADDED] computation of PTPF (Power Transfer Distribution Factor) is now possible
- [IMPROVED] now performing the new grid2op `create_test_suite`
- [IMPROVED] now lightsim2grid properly throw `BackendError`
- [IMPROVED] clean ce cpp side by refactoring: making clearer the difference (linear) solver
vs powerflow algorithm and move same type of files in the same directory. This change
does not really affect python side at the moment (but will in future versions)

[0.7.5] 2023-10-05
--------------------
Expand Down
27 changes: 18 additions & 9 deletions docs/benchmarks.rst
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,8 @@ To run the benchmark `cd` in the [benchmark](./benchmarks) folder and type:
(we remind that these simulations correspond to simulation on one core of the CPU. Of course it is possible to
make use of all the available cores, which would increase the number of steps that can be performed)

We compare up to 19 different solvers:
We compare up to 19 different "solvers" (combination of "linear solver used" (*eg* Eigen, KLU, CKTSO, NICSLU)
and powerflow algorithm (*eg* "Newton Raphson", or "Fast Decoupled")):

- **PP**: PandaPowerBackend (default grid2op backend) which is the reference in our benchmarks (uses the numba
acceleration). It is our reference solver.
Expand Down Expand Up @@ -102,16 +103,24 @@ Computation time
In this first subsection we compare the computation times:

- **grid2op speed** from a grid2op point of view
(this include the time to compute the powerflow, plus the time to modify the powergrid plus the
time to read back the data once the powerflow has run plus the time to update the environment and
the observations etc.). It is reported in "iteration per second" (`it/s`) and represents the number of grid2op "step"
(this include the time to compute the powerflow, plus the time to modify
the powergrid plus the
time to read back the data once the powerflow has run plus the time to update
the environment and
the observations etc.). It is reported in "iteration per second" (`it/s`) and
represents the number of grid2op "step"
that can be computed per second.
- **grid2op 'backend.runpf' time** corresponds to the time the solver take to perform a powerflow
as seen from grid2op (counting the resolution time and some time to check the validity of the results but
not the time to update the grid nor the grid2op environment), for lightsim2grid it includes the time to read back the data
- **grid2op 'backend.runpf' time** corresponds to the time the solver take
to perform a powerflow
as seen from grid2op (counting the resolution time and some time to check
the validity of the results but
not the time to update the grid nor the grid2op environment), for lightsim2grid
it includes the time to read back the data
from c++ to python. It is reported in milli seconds (ms).
- **solver powerflow time** corresponds only to the time spent in the solver itself. It does not take into
account any of the checking, nor the transfer of the data python side etc. It is reported in milli seconds (ms) as well.
- **solver powerflow time** corresponds only to the time spent in the solver
itself. It does not take into
account any of the checking, nor the transfer of the data python side etc.
It is reported in milli seconds (ms) as well.

There are two major differences between **grid2op 'backend.runpf' time** and **solver powerflow time**. In **grid2op 'backend.runpf' time**
the time to initialize the solver (usually with the DC approximation) is counted (it is not in **solver powerflow time**). Secondly,
Expand Down
36 changes: 18 additions & 18 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@
"be available, which is maybe ~30% slower than \"KLU\". If you are using grid2op there "
"will still be a huge benefit.")

INCLUDE = INCLUDE_suitesparse
INCLUDE = ["src"] + INCLUDE_suitesparse

# now add the Eigen library (header only)
eigen_path = os.path.abspath(".")
Expand Down Expand Up @@ -137,31 +137,31 @@
f"-DVERSION_MEDIUM={VERSION_MEDIUM}",
f"-DVERSION_MINOR={VERSION_MINOR}"]
src_files = ['src/main.cpp',
"src/powerflow_algorithm/GaussSeidelAlgo.cpp",
"src/powerflow_algorithm/GaussSeidelSynchAlgo.cpp",
"src/powerflow_algorithm/BaseAlgo.cpp",
"src/linear_solvers/SparseLUSolver.cpp",
"src/help_fun_msg.cpp",
"src/SparseLUSolver.cpp",
"src/BaseConstants.cpp",
"src/GridModel.cpp",
"src/DataConverter.cpp",
"src/DataLine.cpp",
"src/DataGeneric.cpp",
"src/DataShunt.cpp",
"src/DataTrafo.cpp",
"src/DataLoad.cpp",
"src/DataGen.cpp",
"src/DataSGen.cpp",
"src/DataDCLine.cpp",
"src/ChooseSolver.cpp",
"src/GaussSeidelSolver.cpp",
"src/GaussSeidelSynchSolver.cpp",
"src/BaseSolver.cpp",
"src/BaseMultiplePowerflow.cpp",
"src/Computers.cpp",
"src/SecurityAnalysis.cpp",
"src/Solvers.cpp",
"src/Utils.cpp"]
"src/Utils.cpp",
"src/DataConverter.cpp",
"src/element_container/LineContainer.cpp",
"src/element_container/GenericContainer.cpp",
"src/element_container/ShuntContainer.cpp",
"src/element_container/TrafoContainer.cpp",
"src/element_container/LoadContainer.cpp",
"src/element_container/GeneratorContainer.cpp",
"src/element_container/SGenContainer.cpp",
"src/element_container/DCLineContainer.cpp"]

if KLU_SOLVER_AVAILABLE:
src_files.append("src/KLUSolver.cpp")
src_files.append("src/linear_solvers/KLUSolver.cpp")
extra_compile_args_tmp.append("-DKLU_SOLVER_AVAILABLE")
print("INFO: Using KLU package")

Expand Down Expand Up @@ -208,7 +208,7 @@
if include_nicslu and libnicslu_path is not None:
LIBS.append(os.path.join(path_nicslu, libnicslu_path))
include_dirs.append(os.path.join(path_nicslu, "include"))
src_files.append("src/NICSLUSolver.cpp")
src_files.append("src/linear_solvers/NICSLUSolver.cpp")
extra_compile_args.append("-DNICSLU_SOLVER_AVAILABLE")
print("INFO: Using NICSLU package")

Expand Down Expand Up @@ -255,7 +255,7 @@
if include_cktso and libcktso_path is not None:
LIBS.append(os.path.join(path_cktso, libcktso_path))
include_dirs.append(os.path.join(path_cktso, "include"))
src_files.append("src/CKTSOSolver.cpp")
src_files.append("src/linear_solvers/CKTSOSolver.cpp")
extra_compile_args.append("-DCKTSO_SOLVER_AVAILABLE")
print("INFO: Using CKTSO package")

Expand Down
4 changes: 2 additions & 2 deletions src/BaseMultiplePowerflow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@ bool BaseMultiplePowerflow::compute_one_powerflow(const Eigen::SparseMatrix<cplx

void BaseMultiplePowerflow::compute_flows_from_Vs(bool amps)
{
// TODO find a way to factorize that with DataTrafo::compute_results
// TODO and DataLine::compute_results
// TODO find a way to factorize that with TrafoContainer::compute_results
// TODO and LineContainer::compute_results

if (_voltages.size() == 0)
{
Expand Down
17 changes: 7 additions & 10 deletions src/ChooseSolver.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,6 @@

// import newton raphson solvers using different linear algebra solvers
#include "Solvers.h"
#include "GaussSeidelSolver.h"
#include "GaussSeidelSynchSolver.h"
#include "DCSolver.h"

enum class SolverType {SparseLU, KLU, GaussSeidel, DC, GaussSeidelSynch, NICSLU,
SparseLUSingleSlack, KLUSingleSlack, NICSLUSingleSlack,
Expand Down Expand Up @@ -189,7 +186,7 @@ class ChooseSolver
return p_solver -> reset();
}

// benefit from dynamic stuff and inheritance by having a method that returns a BaseSolver *
// benefit from dynamic stuff and inheritance by having a method that returns a BaseAlgo *
bool compute_pf(const Eigen::SparseMatrix<cplx_type> & Ybus, // size (nb_bus, nb_bus)
CplxVect & V, // size nb_bus
const CplxVect & Sbus, // size nb_bus
Expand Down Expand Up @@ -388,9 +385,9 @@ class ChooseSolver
/**
returns a pointer to the current solver used
**/
const BaseSolver * get_prt_solver(const std::string & error_msg, bool check_right_solver_=true) const {
const BaseAlgo * get_prt_solver(const std::string & error_msg, bool check_right_solver_=true) const {
if (check_right_solver_) check_right_solver(error_msg);
const BaseSolver * res;
const BaseAlgo * res;
if(_solver_type == SolverType::SparseLU){res = &_solver_lu;}
else if(_solver_type == SolverType::SparseLUSingleSlack){res = &_solver_lu_single;}
else if(_solver_type == SolverType::DC){res = &_solver_dc;}
Expand Down Expand Up @@ -422,9 +419,9 @@ class ChooseSolver
else throw std::runtime_error("Unknown solver type encountered (ChooseSolver get_prt_solver const)");
return res;
}
BaseSolver * get_prt_solver(const std::string & error_msg, bool check_right_solver_=true) {
BaseAlgo * get_prt_solver(const std::string & error_msg, bool check_right_solver_=true) {
if (check_right_solver_) check_right_solver(error_msg);
BaseSolver * res;
BaseAlgo * res;
if(_solver_type == SolverType::SparseLU){res = &_solver_lu;}
else if(_solver_type == SolverType::SparseLUSingleSlack){res = &_solver_lu_single;}
else if(_solver_type == SolverType::DC){res = &_solver_dc;}
Expand Down Expand Up @@ -464,8 +461,8 @@ class ChooseSolver
// TODO have a way to use Union here https://en.cppreference.com/w/cpp/language/union
SparseLUSolver _solver_lu;
SparseLUSolverSingleSlack _solver_lu_single;
GaussSeidelSolver _solver_gaussseidel;
GaussSeidelSynchSolver _solver_gaussseidelsynch;
GaussSeidelAlgo _solver_gaussseidel;
GaussSeidelSynchAlgo _solver_gaussseidelsynch;
DCSolver _solver_dc;
FDPF_XB_SparseLUSolver _solver_fdpf_xb_lu;
FDPF_BX_SparseLUSolver _solver_fdpf_bx_lu;
Expand Down
20 changes: 9 additions & 11 deletions src/GridModel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -146,21 +146,21 @@ void GridModel::set_state(GridModel::StateRes & my_state)
std::vector<bool> & bus_status = std::get<7>(my_state);

// powerlines
DataLine::StateRes & state_lines = std::get<8>(my_state);
LineContainer::StateRes & state_lines = std::get<8>(my_state);
// shunts
DataShunt::StateRes & state_shunts = std::get<9>(my_state);
ShuntContainer::StateRes & state_shunts = std::get<9>(my_state);
// trafos
DataTrafo::StateRes & state_trafos = std::get<10>(my_state);
TrafoContainer::StateRes & state_trafos = std::get<10>(my_state);
// generators
DataGen::StateRes & state_gens = std::get<11>(my_state);
GeneratorContainer::StateRes & state_gens = std::get<11>(my_state);
// loads
DataLoad::StateRes & state_loads = std::get<12>(my_state);
LoadContainer::StateRes & state_loads = std::get<12>(my_state);
// static gen
DataSGen::StateRes & state_sgens= std::get<13>(my_state);
SGenContainer::StateRes & state_sgens= std::get<13>(my_state);
// storage units
DataLoad::StateRes & state_storages = std::get<14>(my_state);
LoadContainer::StateRes & state_storages = std::get<14>(my_state);
// dc lines
DataDCLine::StateRes & state_dc_lines = std::get<15>(my_state);
DCLineContainer::StateRes & state_dc_lines = std::get<15>(my_state);

// assign it to this instance

Expand Down Expand Up @@ -338,7 +338,7 @@ CplxVect GridModel::ac_pf(const CplxVect & Vinit,
};

void GridModel::check_solution_q_values_onegen(CplxVect & res,
const DataGen::GenInfo& gen,
const GeneratorContainer::GenInfo& gen,
bool check_q_limits) const{
if(check_q_limits)
{
Expand Down Expand Up @@ -626,8 +626,6 @@ void GridModel::init_slack_bus(const CplxVect & Sbus,
const std::vector<int>& id_solver_to_me,
const Eigen::VectorXi & slack_bus_id_me,
Eigen::VectorXi & slack_bus_id_solver){

const int nb_bus = static_cast<int>(id_solver_to_me.size());
// slack_bus_id_solver = Eigen::VectorXi::Zero(slack_bus_id_.size());
slack_bus_id_solver = Eigen::VectorXi::Constant(slack_bus_id_me.size(), _deactivated_bus_id);

Expand Down
Loading

0 comments on commit 44cea30

Please sign in to comment.