Open
Description
In our team, we discovered a bug because we were not using the PowerGridModelInterface correctly.
In short: we wanted to calculate both high and low load scenario in a network.
So we did
pgm = PowerGridModelInterface(grid=grid)
pgm.create_input_from_grid()
high_load = pgm.calculate_power_flow()
# and then our mistake:
pgm.input_data["sym_load"]["p_specified"] = <new_values>
pgm.input_data["sym_load"]["q_specified"] = <new_values>
# and run again
pgm.calculate_power_flow()
However. This doesn't work. We're only updating the input_data dictionary and we're not updating the internal C-arrays of the PGM instance.
To do it correctly, one should use
sym_load_updates = initialize_array("update", "sym_load", pgm.input_data["sym_load"]["p_specified"].size)
sym_load_updates["p_specified"] = <new_values>
sym_load_updates["q_specified"] = <new_values>
pgm.update_model(update_data={"sym_load": sym_load_updates})
# and run again
pgm.calculate_power_flow()
To prevent other from making this mistake, I propose making the input_data attribute private + add some documentation on this.