powsybl / pypowsybl-grid2opbackend

Mozilla Public License 2.0
11 stars 0 forks source link

Possible "workflow" for the integration #1

Closed BDonnot closed 1 year ago

BDonnot commented 1 year ago

What to do

The technical interface to implement is detailed there: https://grid2op.readthedocs.io/en/latest/backend.html

A first possible way to do it

A possible "workflow" is detailed here:

https://github.com/rte-france/Grid2Op/tree/dev_1.8.2/examples/backend_integration

Some steps (should be in order of difficulty):

  1. loading the grid, an example is given here https://github.com/rte-france/Grid2Op/blob/dev_1.8.2/examples/backend_integration/Step1_loading.py NB this might include converting the grid from pandapower json format to a compatible format if we want to use the backend developed here with existing grid2op environments. This conversion would be easy: load pandapower to convert json -> matpower. Then read the matpower file with pypowsybl.
  2. handling the manipulation of loads (change load_p and load_q) , starting a powerflow and then reading back the restult. An example is here https://github.com/rte-france/Grid2Op/blob/dev_1.8.2/examples/backend_integration/Step2_modify_load.py
  3. handling manipulation of generators (change gen_p and gen_v) and then read back the result https://github.com/rte-france/Grid2Op/blob/dev_1.8.2/examples/backend_integration/Step3_modify_gen.py
  4. connect or disconnect powerline, and read the data (flows) on the powerlines: https://github.com/rte-france/Grid2Op/blob/dev_1.8.2/examples/backend_integration/Step4_modify_line_status.py
  5. change the "busbar" to which an object is connect, an example is given here: https://github.com/rte-france/Grid2Op/blob/dev_1.8.2/examples/backend_integration/Step5_modify_topology.py

Issue regarding the topology

The main issue (as identified at this stage) is the "modification of the topology" and the "busbar" to which an object (load, generator, side of powerline or transformer etc.) is connected.

It would not be possible to reuse some smart method of open loadflow for this kind of modifications as the "short list of all possible actions that will be done" is not known when the backend is loaded.

Not knowing this list will likely have some large impact on the performance of the developed backend. At time of writing, we will not focus on the performance and will see if we can optimize it later on.

Possible solution 1: changing the grid

This solution consists in:

  1. Load a grid in whatever format in pypowsybl
  2. Isolate the elements: load, shunt, generators, side of powerlines and transformers etc. as well as the substation they are connected to
  3. Create another grid in pypowsybl with these exact elements and add the appropriate busbars (2 per substations) and the switches (1 per busbar and per elements)
  4. save this file in iidm and load it back.
  5. Manipulate only this "new" grid file

In this case the manipulation of the grid by the "apply_action" method is rather simple: if an element is on busbar 1 you close the switch that connects it to this busbar and open the other one, and if it's on busbar bar 2 you do the opposite.

caveat some topologies might be infeasible in practice yet with this method they can still be applied on the grid.

caveat if in the future grid2op supports different number of "busbar" (today it's 2 per substations) for substation then this might not work as smoothly.

Possible solution 2: compute the detailed topology "on the fly"

In this solution, you do not modify the grid model. You create a function that computes the state of the switches in the detailed topology to match the "target nodal topology" that you receive as input.

If you cannot find a solution for the switches, then you throw the appropriate error which will be handled grid2op side.

The approach needs to implement a function that given a nodal topology outputs a detailed topology.

  1. It needs to be implemented
  2. then we run it each "grid2op step" (which might take a while)
  3. we can (once 2. above works and is tested) stores inputs / outputs of this function and only run it for each "never seen before nodal topology" which can save some computation time.

@geofjamg @annetill : does it translates accurately what we said in the meeting earlier ? If not do not hesitate to add comment, i'll integrate them here :-)

tschuppr commented 1 year ago

We chose the first architecture, all the process is explained in our README in this section and this function has been particularly useful.