Difficulty with utilizing PowerModels.update data! function

Hello to everyone. I apologize if my inquiry is too simple. Julia is a programming language that I am learning. For optimal power flow and power flow problems, I use the PowerModels toolkit. PowerModels.update data! is a function that allows the user to update the prior result for future calculation.

For example, if I compute DC-OPF using DCPPowerModel and then run AC power flow to see if the DC-OPF is AC practicable, the code frequently returns an error. When I utilized ACPPowerModel and SOCWRPowerModel, this was not the case. Here is my code.

using PowerModels

using Ipopt

using SCS

using MAT

using Gurobi

network_data = PowerModels.parse_file(“case9.m”)

result=solve_opf(network_data, DCPPowerModel, Gurobi.Optimizer)

PowerModels.print_summary(result[“solution”])

PowerModels.update_data!(network_data, result[“solution”])

result2=PowerModels.compute_ac_pf(network_data)

PowerModels.print_summary(result2[“solution”])

result3=PowerModels.calc_branch_flow_ac(network_data)

PowerModels.print_summary(result3)

The issue here is that result=solve_opf(network_data, DCPPowerModel, Gurobi.Optimizer) returns NaN values for the reactive power parts of the solution. Then the call to PowerModels.update_data!(network_data, result[“solution”]) overwrites the reactive parts of the network data with these NaN values which makes it not a well formed AC dataset for compute_ac_pf.

The recommend fix would be to replace PowerModels.update_data!(network_data, result[“solution”]) with a variant you write by hand that only updates the active power values you are interested in (usually the pg values on the generators and sometimes the va values on the buses).

3 Likes

Thank you very much for responding. So I only have to hunt for an other technique of updating my data when I want to evaluate whether the DC-OPF set point is AC power flow possible. Does PowerModels.update data! work as expected for ACPPowerModel and SOCWRPowerModel?

Sure thing.

In all cases, update_data! works as expected, in that it overwrites one dictionary with another. That is the limits of its functionality.

The issue you are having here is related to the output semantics of solve_opf with a network model that does not define reactive power aspects of the problem, i.e. DCPPowerModel. The convention in PowerModels is to use NaN’s when a particular required value is not available, so that the data output structure is standardized for all models. If you use a model that defines all of these values (e.g. ACPPowerModel) update_data! will do what you are expecting without special work. In cases where not all data is well defined, i.e. DCPPowerModel, you need to write some custom code for the specific use case that you have in mind.

1 Like

Thank you very much for your rapid answer. Please do you have any example code that might be of assistance?

I think what you are looking for is something like this code below. I would caution, setting up an AC PowerFlow study from a DC dispatch solution has a number of subtle points (e.g. line losses) that should be treated with care.

using PowerModels, Ipopt

case_file = joinpath(dirname(pathof(PowerModels)), "..", "test", "data", "matpower", "case9.m")

network_data = parse_file(case_file)

result = solve_opf(network_data, DCPPowerModel, Ipopt.Optimizer)
print_summary(result["solution"])

for (i,gen) in result["solution"]["gen"]
    network_data["gen"][i]["pg"] = gen["pg"]
end

result2 =solve_pf(network_data, ACPPowerModel, Ipopt.Optimizer)
print_summary(result2["solution"])
1 Like