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
46 stars 9 forks source link

Feature Request : Multi-Slack (Non Distributed) #50

Closed elharchaoui closed 9 months ago

elharchaoui commented 1 year ago

Hello Mr Bonnot,

We are using PandaPower to perform our power flow calculations, we have discovered LightSim2grid via PandaPower, we are interested in using it because of it's good shown performance.

We have several sub-stations which means several slacks non distributed, a use case example is mv_oberrhein in PandaPower Network, we have remarked that LightSim2grid is not activated for this use case. We would like to use it in our works in order to help us to improve the speed performance.

Is there any way to use LighSim2Grid on a multi-slack (Non Distributed) network ?, if yes, is it easy to handle ?, are you planning to add this feature in the future ?

Thank you so much in advance.

Regards

BDonnot commented 1 year ago

Hello,

Thanks for your interest in this package.

Currently only single or distributed slack i'are supported. I will have a lookin how to add multi slacks. And depending on how complicated it is I might add the feature in the future.

Note however that this will take some time (best case scenario I can look end of September) as I cannot work on lightsim2grid at the moment.

Benjamin

elharchaoui commented 1 year ago

Hello Bonnot,

Hope you are doing well, did you have some time to check the feasibility of introducing Multi-Slack on Lightsim2grid ? can you share with us your update and plans? thank you in advance.

Regards

BDonnot commented 1 year ago

Hello,

I am on parental leave until beginning of December. And then I have a 2 weeks holiday for Christmas.

I cannot work on this issue before early 2023 at best. Any pull request will drastically reduce the time it takes for me to do it.

I think it should be possible to implement it rather easily as I'm pretty sure it does not require heavy development.

If I may ask, out of curiosity, why would you like multiple slack in a non distributed way? This model does not really make sense for me but I'm not a power system expert (but I'm really curious ๐Ÿ˜‰)

Best

Benjamin

elharchaoui commented 1 year ago

Hello,

Congratulation for the new baby ๐ŸŽ‰, and thanks for your interest. In fact, it's for the power flow calculation of several sub-stations with each one having its own Slack, it will be very quick to compute PF for all sub-stations at once instead of each one separately, Pandapower actually handles this parallel computation of PF (power flow) over multiple sub-stations, this is much faster compared to the sequential computation of PF for those multiple sub-stations.

you can imagine the task as parallelization of newton-raphson computation over multiple grids.

Thanks

BDonnot commented 1 year ago

Thanks ๐Ÿ˜Š

Oh OK I see. In this case it makes perfect sense indeed. I'll see what I can do asap (but again probably not in 2022 :-/)

Best

Benjamin

BDonnot commented 1 year ago

Hello, I think i just need to change one single function in the c++ side so it should be easy. By any chance, do you have any file you are using (for the grid) and script (for the code) so that i can make experiments with it asap ?

If not i will actually spend more time to find a suitable grid and then create a code with pandapower to do what you want to do rather than to code the actual feature in lightsim2grid.

Thanks

elharchaoui commented 1 year ago

Hello Benjamin, Thank you for getting back to us. Since we are not allowed to upload our networks, the easiest would be for you to use the MV network already available in pandapower :

import pandapower.networks import pandapower as pp net = pandapower.networks.mv_oberrhein() pp.runpp(net, lightsim2grid=False) # works pp.runpp(net, lightsim2grid=True) # NotImplementedError: option 'lightsim2grid' is True and multiple ext_grids are found, but distributed_slack=False.

The runtime with this network wonโ€™t be representative since the network is really small but it might still be useful for you to experiment with. Donโ€™t hesitate to tell us if it is not

BDonnot commented 1 year ago

Hello,

As a first step this sounds great. I'll get back to you once i've done it (in a separate branch, probably next week) with the binary you can install and you can let me know if that works for you. If it does i'll merge it to the right repo.

Does that sound ok for you ?

elharchaoui commented 1 year ago

Hello,

That's great! thank you! yes, it's ok for us.

BDonnot commented 1 year ago

Hello,

I have not forget this feature. I was swamped by work and there were lots of different bugs in grid2op and lightsim2grid...

I'll work on it as soon as I can

BDonnot commented 1 year ago

A quick update on the matter: things are a bit more complicated, especially if i need to initialize the grid with DC.

I will try to see if I get the same results as pandapower for mv_oberrhein() grid when I let pandapower compute the initial vector.

elharchaoui commented 1 year ago

Hello,

Thanks for keeping me updated and for your involvement in the matter.

elharchaoui commented 1 year ago

Hello,

Do you have any updates to share, is there something I can do to help? can you give some details about the complexity and what needs to be modified?

Thank you in advance

Regards

BDonnot commented 1 year ago

Hello,

I tried to run it with the "simple ideas" that I got, but unfortunately it did not work. I think I need to double check in the case of multiple (non distributed) slack how pandapower does it. Because clearly, removing some buses that would be neither pv nor pq (so the slack) is not enough. There is probably another trick that I don't really "master" right now :-/

BDonnot commented 9 months ago

Hello,

Just so you know, I implemented this feature at the moment (tests might not pass yet) but it appears to work at least in AC (i tried 5 minutes and DC and it does not work).

The problem I faced was related to the grid you provided mv_oberrhein seems to be a distribution grid and I had to change a few things (closing switches, removing trafo shift_degree for example.

But with that done, I now get the same results as pandapower for this grid (if tests pass) see https://github.com/BDonnot/lightsim2grid/blob/bd-dev/lightsim2grid/tests/test_multi_slack.py for an example.

NB if you want to use this feature, make sure to use the right solver in lightsim2grid. By default if multiple slacks are detected the "distributed slack" is chosen. You need to set something like:

from lightsim2grid.solver import SolverType

gridmodel = ....  # whatever grid in lightsim2grid format
gridmodel.change_solver(SolverType.KLUSingleSlack)

Let me know if it needs further coding.