Skip to content

Commit

Permalink
adding timers for PTDF and LODF, first attempt in providing whl for m…
Browse files Browse the repository at this point in the history
…ore linux
  • Loading branch information
BDonnot committed Apr 9, 2024
1 parent fdf1869 commit 1cf538a
Show file tree
Hide file tree
Showing 6 changed files with 61 additions and 5 deletions.
24 changes: 19 additions & 5 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ jobs:
# build wheels for some linux
name: Build linux ${{ matrix.python.name }} wheel
runs-on: ubuntu-latest
container: quay.io/pypa/manylinux2014_x86_64
container: ${{ matrix.cont.val }}
strategy:
matrix:
python:
Expand Down Expand Up @@ -46,6 +46,19 @@ jobs:
abi: cp312,
version: '3.12',
}
cont:
- {
name: manylinux2014_x86_64,
val: quay.io/pypa/manylinux2014_x86_64
}
- {
name: manylinux2014_aarch64,
val: quay.io/pypa/manylinux2014_aarch64
}
- {
name: musllinux_1_1_i686,
val: quay.io/pypa/musllinux_1_1_i686
}

steps:

Expand Down Expand Up @@ -80,11 +93,10 @@ jobs:
pip3 install wheelhouse/*.whl --user
pip freeze
# - name: Install GDB
# run: yum install -y gdb

- name: Check package can be imported (bare install)
run: |
mkdir tmp_for_import_checking
cd tmp_for_import_checking
python3 -c "import lightsim2grid"
python3 -c "from lightsim2grid import *"
python3 -c "from lightsim2grid.newtonpf import newtonpf"
Expand All @@ -106,6 +118,7 @@ jobs:
- name: Check extra can be imported can be imported (with grid2op)
run:
cd tmp_for_import_checking
python3 -v -c "from lightsim2grid import LightSimBackend"
python3 -c "from lightsim2grid.timeSerie import TimeSerie"
python3 -c "from lightsim2grid.contingencyAnalysis import ContingencyAnalysis"
Expand All @@ -114,12 +127,13 @@ jobs:

- name: Check LightSimBackend can be used to create env
run:
cd tmp_for_import_checking
python3 -v -c "from lightsim2grid import LightSimBackend; import grid2op; env = grid2op.make('l2rpn_case14_sandbox', test=True, backend=LightSimBackend())"

- name: Upload wheel
uses: actions/upload-artifact@v3 # v4 broken
with:
name: lightsim2grid-wheel-linux-${{ matrix.python.name }}
name: lightsim2grid-wheel-linux-${{ matrix.python.name }}-${{ matrix.cont.name }}
path: wheelhouse/*.whl

- name: Upload source archive
Expand Down
6 changes: 6 additions & 0 deletions src/ChooseSolver.h
Original file line number Diff line number Diff line change
Expand Up @@ -320,6 +320,12 @@ class ChooseSolver
return p_solver -> get_timers_jacobian();
}

TimerPTDFLODFType get_timers_ptdf_lodf() const
{
const BaseAlgo * p_solver = get_prt_solver("get_timers_ptdf_lodf", true);
return p_solver -> get_timers_ptdf_lodf();
}

ErrorType get_error() const{
auto p_solver = get_prt_solver("get_error", true);
return p_solver -> get_error();
Expand Down
1 change: 1 addition & 0 deletions src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -446,6 +446,7 @@ PYBIND11_MODULE(lightsim2grid_cpp, m)
.def("get_computation_time", &ChooseSolver::get_computation_time, DocSolver::get_computation_time.c_str())
.def("get_timers", &ChooseSolver::get_timers, "TODO")
.def("get_timers_jacobian", &ChooseSolver::get_timers_jacobian, "TODO")
.def("get_timers_ptdf_lodf", &ChooseSolver::get_timers_ptdf_lodf, "TODO")
.def("get_fdpf_xb_lu", &ChooseSolver::get_fdpf_xb_lu, py::return_value_policy::reference, DocGridModel::_internal_do_not_use.c_str()) // TODO this for all solver !
.def("get_fdpf_bx_lu", &ChooseSolver::get_fdpf_bx_lu, py::return_value_policy::reference, DocGridModel::_internal_do_not_use.c_str());

Expand Down
11 changes: 11 additions & 0 deletions src/powerflow_algorithm/BaseAlgo.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ class GridModel;
typedef std::tuple<double, double, double, double,
double, double, double, double,
double> TimerJacType;
typedef std::tuple<double, double, double> TimerPTDFLODFType;

/**
This class represents a algorithm to compute powerflow.
Expand Down Expand Up @@ -104,6 +105,16 @@ class BaseAlgo : public BaseConstants
};
return res;
}

virtual TimerPTDFLODFType get_timers_ptdf_lodf() const
{
TimerPTDFLODFType res = {
-1., // not available for non NR solver, so I put -1
-1., // not available for non NR solver, so I put -1
-1., // not available for non NR solver, so I put -1
};
return res;
}

virtual
bool compute_pf(const Eigen::SparseMatrix<cplx_type> & Ybus,
Expand Down
20 changes: 20 additions & 0 deletions src/powerflow_algorithm/BaseDCAlgo.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,29 @@ class BaseDCAlgo: public BaseAlgo
BaseAlgo(false),
_linear_solver(),
need_factorize_(true),
timer_ptdf_(0.),
timer_lodf_(0.),
sizeYbus_with_slack_(0),
sizeYbus_without_slack_(0){};

~BaseDCAlgo(){}

virtual void reset();
virtual void reset_timer(){
BaseAlgo::reset_timer();
timer_ptdf_ = 0.;
timer_lodf_ = 0.;
}

virtual TimerPTDFLODFType get_timers_ptdf_lodf() const
{
TimerPTDFLODFType res = {
timer_ptdf_,
timer_lodf_ - timer_ptdf_,
-1., // not available yet so I put -1
};
return res;
}

// TODO SLACK : this should be handled in Sbus by the gridmodel maybe ?
virtual
Expand Down Expand Up @@ -62,6 +79,9 @@ class BaseDCAlgo: public BaseAlgo
LinearSolver _linear_solver;
bool need_factorize_;

double timer_ptdf_;
double timer_lodf_;

// save this not to recompute them when not needed
int sizeYbus_with_slack_;
int sizeYbus_without_slack_;
Expand Down
4 changes: 4 additions & 0 deletions src/powerflow_algorithm/BaseDCAlgo.tpp
Original file line number Diff line number Diff line change
Expand Up @@ -234,6 +234,7 @@ void BaseDCAlgo<LinearSolver>::reset(){

template<class LinearSolver>
RealMat BaseDCAlgo<LinearSolver>::get_ptdf(const Eigen::SparseMatrix<cplx_type> & dcYbus){
auto timer = CustTimer();
Eigen::SparseMatrix<real_type> Bf_T_with_slack;
RealMat PTDF;
RealVect rhs = RealVect::Zero(sizeYbus_without_slack_); // TODO dist slack: -1 or -mat_bus_id_.size() here ????
Expand Down Expand Up @@ -277,6 +278,7 @@ RealMat BaseDCAlgo<LinearSolver>::get_ptdf(const Eigen::SparseMatrix<cplx_type>
rhs.array() = 0.;
// rhs = RealVect::Zero(sizeYbus_without_slack_);
}
timer_ptdf_ = timer.duration();
// TODO PTDF: if the solver can solve the MAT directly, do that instead
return PTDF;
}
Expand All @@ -285,6 +287,7 @@ template<class LinearSolver>
RealMat BaseDCAlgo<LinearSolver>::get_lodf(const Eigen::SparseMatrix<cplx_type> & dcYbus,
const IntVect & from_bus,
const IntVect & to_bus){
auto timer = CustTimer();
const RealMat PTDF = get_ptdf(dcYbus); // size n_line x n_bus
RealMat LODF = RealMat::Zero(from_bus.size(), from_bus.rows()); // nb_line, nb_line
for(Eigen::Index line_id=0; line_id < from_bus.size(); ++line_id){
Expand All @@ -297,6 +300,7 @@ RealMat BaseDCAlgo<LinearSolver>::get_lodf(const Eigen::SparseMatrix<cplx_type>
LODF.col(line_id).array() = std::numeric_limits<real_type>::quiet_NaN();
}
}
timer_lodf_ = timer.duration();
return LODF;
}

Expand Down

0 comments on commit 1cf538a

Please sign in to comment.