BDonnot / lightsim2grid

LightSim2grid implements a c++ backend targeting the Grid2Op (https://github.com/rte-france/grid2op) platform.
https://lightsim2grid.readthedocs.io/en/latest/
Mozilla Public License 2.0
49 stars 9 forks source link

Support the latest cktso sparse solver #52

Closed mzy2240 closed 1 year ago

mzy2240 commented 1 year ago

CKTSO is the successor of NICSLU, with better performance. Support of CKTSO should be beneficial for pushing the computing of power flow to the next level.

BDonnot commented 1 year ago

Hello,

This is a nice news.

By any chance, would you have the time to make a pull request to include it ? I will unfortunately not have the time to do it in 2022. The code example are: https://github.com/BDonnot/lightsim2grid/blob/master/src/NICSLUSolver.h and https://github.com/BDonnot/lightsim2grid/blob/master/src/NICSLUSolver.cpp

This should be relatively quick to do if the new method is similar to NICSLU (which I suspect if CKTSO is the successor of NICSLU)

In any case, thanks for the information.

Benjamin

BDonnot commented 1 year ago

Hello

I did all the "glue" code to make the cktso linear available, see the branch cktso (https://github.com/BDonnot/lightsim2grid/tree/cktso and the file https://github.com/BDonnot/lightsim2grid/blob/cktso/src/CKTSOSolver.cpp) but unfortunately, i did not manage to make it work due to error when solving linear system (error code -2: argument error) when the software tries to solve the linear system even with the small case14 network (which works well for KLU and the default linear solver in Eigen)

You can reproduce it by running the test python3 test_CKTSOSolver.py in lightsim2grid/tests after compilation.

I am not familiar with it maybe you can see what I did wrong ?

mzy2240 commented 1 year ago

@chenxm1986 Hi Dr. Chen, do you have any idea why there is argument error for this thin wrapper?

BDonnot commented 1 year ago

If you want i can provide you with the ai, ap and ax of the matrix and the coefficients of the vector b if that can help you.

chenxm1986 commented 1 year ago

Hello

I did all the "glue" code to make the cktso linear available, see the branch cktso (https://github.com/BDonnot/lightsim2grid/tree/cktso and the file https://github.com/BDonnot/lightsim2grid/blob/cktso/src/CKTSOSolver.cpp) but unfortunately, i did not manage to make it work due to error when solving linear system (error code -2: argument error) when the software tries to solve the linear system even with the small case14 network (which works well for KLU and the default linear solver in Eigen)

You can reproduce it by running the test python3 test_CKTSOSolver.py in lightsim2grid/tests after compilation.

I am not familiar with it maybe you can see what I did wrong ?

-2 typically means that some argument is null. Which function returns -2?

chenxm1986 commented 1 year ago

It seems that before Solve the vector x is not allocated?

BDonnot commented 1 year ago

Hello,

Thank you very much for the quick reply. I will double check thanks for the hint.

The same code works when I use KLU or NICSLU (last time I checked, a few months ago). I would be surprised if the x argument were to be un initialized in case of cktso. But for sure I will double check and let you know asap.

Thanks

chenxm1986 commented 1 year ago

I found another small issue. Please do not delete iparm[] and oparm[]. The just point to internal arrays and cktso will delete them when the handle is destroyed.

BDonnot commented 1 year ago

Ok i'll modify this, thanks

BDonnot commented 1 year ago

Hello,

You were correct on every aspect:

  1. a "copy paste error" caused the x to be uninitialized (causing the -2 return error in CKTSO)
  2. i removed the deletion of the iparam and oparam which solves a "segfault" probably caused by this

Thanks a lot, it all seems to work and i'll include it in the next release (i need to do a bit of documentation)