Fix PV→PQ bus type conversion when bus rows are not in ID order#49
Fix PV→PQ bus type conversion when bus rows are not in ID order#49yemine0x01 wants to merge 3 commits into
Conversation
2ac86c6 to
b8ec1b4
Compare
…n_count with bus IDs Signed-off-by: eminyouskn <youssouf.emine@artelys.com>
b8ec1b4 to
5cc90e9
Compare
albanpuech
left a comment
There was a problem hiding this comment.
Looks good.
However, here are many parts of the code in datakit and in graphkit that expect the buses to be sorted. Just to give one example: https://github.com/gridfm/gridfm-graphkit/blob/a5e6449f5fd5f77211ba22483ef8e7f3f14c6120/gridfm_graphkit/datasets/powergrid_hetero_dataset.py#L162
|
Thanks for the review, @albanpuech. Just to clarify, do we strictly need the buses to be ordered by ID? For context, these changes don't remove the existing bus ordering; they simply ensure the logic still functions correctly even if the buses happen to be unordered. |
There are many places in the code that assume that, yes. or https://github.com/gridfm/gridfm-graphkit/blob/a5e6449f5fd5f77211ba22483ef8e7f3f14c6120/gridfm_graphkit/datasets/powergrid_hetero_dataset.py#L162 We would need to check everything and list where code needs to be changed |
gen_countis produced bynp.bincountovergens_on[:, GEN_BUS](0-based bus ID), so it is indexed by bus ID. The mask(self.buses[:, BUS_TYPE] == PV) & (gen_count == 0)was comparing element-wise againstgen_countin row order. When pypowsybl exports buses in non-sorted order (MATPOWER, PSS/E, XIIDM formats), bus row ≠ bus ID, so the wrong buses were promoted from PV to PQ.gen_countwithbus_ids = self.buses[:, BUS_I].astype(int)so the comparison aligns with the bus row being evaluated.