powsybl / pypowsybl

A PowSyBl and Python integration based on GraalVM native image
Mozilla Public License 2.0
53 stars 10 forks source link

[WIP] European Merging Function tutorial in pypowsybl #418

Open obrix opened 2 years ago

obrix commented 2 years ago

European Merging Function tutorial in pypowsybl

A feature : To expose what is necessary to be able to run the EMF tutorial from powsybl-tutotial in pypowsybl.

All necessary API are not exposed in pypowsybl, the following elements are missing :

All necessary API should be exposed to be able to execute the same process as in powsybl-tutorial with a more user friendly approach.

Design

BalanceComputationParameters

The implementation can rely on loadflow.Parameters and add the neccesary members :

class BalanceComputationParameters: def __init__(self, loadflowparameters: LoadFlow.Parameters, threshold: float, maxNumberIterations: int)

BalanceComputation

In a similar way than LoadFlow class, we can have a BalanceComputation object with a run method that will take a list of BalanceComputionAreas, a merged network, and a BalanceComputationParameters and return a BalanceComputionResult object

class BalanceComputation: def run(self, network: Network, computationAreas: List[BalanceComputationAreas], parameters: BalanceComputationParameters) -> BalanceComputationResult

BalanceComputationArea

Add a method to BalanceComputation object that will create the list of computation areas in a similar way than what is done in igmPreprocessing and prepareFictitiousArea methods in the tutorial Need as a parameter : MergedNetwork, List of CGMESControlAreas, Dict of NetPositions (controlAreaId -> floats). This should return a list of objects wrapping a java handle (BalanceComputationArea).

class BalanceComputation: def build_computation_areas(self, network : Network, cgmesControlAreas : list[CGMESControlAreas], netPositions :dict[String, float]) -> list[BalanceComputationArea]

In the java tutorial CGMESControlAreas are retrieved from each individual networks unmerged. To do something similar here we can add a function to the the Network class the wrap the following Java code :

CgmesControlArea controlArea = network.getExtension(CgmesControlAreas.class).getCgmesControlAreas().iterator().next();

The CgmesControlArea can be retrieved and stored on python side as a java handle directly, or in a simple object wrapping the handle.

Net positions

In the tutorial net positions seem to be retrieved from a DataExchanges object that is built from an xml files. I am not sure we need to provide a way to retrieve the net positions from a similar file here. We can simply let the user load its net positions himself ?

BalanceComputationResult

Add a simple object to store the status, iteration count, and maybe the map of areas to scaling factors as a dict ?

Merged network serialization to xml cgmes

Just add a new member function to the network class to do this ?

Process overview in pypowsybl

obrix commented 2 years ago

Hello @geofjamg @annetill , this is a first draft for the support of EMF in pypowsybl. Feel free to comment, I will begin to work on it as some design choices have already been discussed with @geofjamg .

annetill commented 2 years ago

Thanks for this first draft! It looks good but I have about how to build a BalanceComputationArea. I don't know if we want to expose the object CGMESControlAreas that is build from an extension of the network (that contains indeed two lists: the terminals and the boundaries that delimit the area). The only very interesting think is the energy identification code that is needed to retrieve the target net position from PEVF file. For me, the most interesting things are:

obrix commented 2 years ago

@annetill Yes, as I began to work on a prototype I asked myself the same thing about CGMESControlAreas and I am not sure what is best. In the tutorial CGMESControlAreas are built from each network pre merge. The issue here is that as discussed with @geofjamg we plan to use Network.merge in the python API which is a destructive merge, I think I thus have to create and store those areas in some way before actually doing the merge operation. I have to make some tests to check what is best from an API point of view.

Concerning the PEVF file, do we need to provide something for the user to load it ? (ie something similar to the DataExchanges object in the tutorial ?) Or can we simply let him handle it on its own ? I don't know the PEVF format.

Concerning NetworkArea and Scalable do you mean it would be a good idea to expose them in python ? My idea was simply to create them on the fly on java side in the call to _build_computationareas because they are necessary for BalanceComputationArea building, but the python user would simply retrieve handles to java BalanceComputationArea objects and not NetworkArea/Scalable.

Haigutus commented 1 year ago

Any updates on this?

On PEVF/CGMA files, I would recommend not to handle that part, rather take input of dict {"area_id/HVDC_id": value}

Example implementation to convert IEC schedules to json -> https://github.com/Baltic-RCC/EMF/blob/286fb31bd68289d7dc4a622b95b891d36825d54d/emf/common/converters/iec_schedule_to_ndjson.py#L27