Get power flow equations from PowerModels?

Is it possible to obtain the power flow equations in the form of f(x) = 0 from PowerModels.jl?

Follow-up question, is it possible to get the system of nonlinear equations h(x) = 0 that make up a power flow problem, i.e. h(x) = 0, where h(x) = [ f(x)^\top\!, \, g(x)]^\top, where f(x) are the said power flow equations, and h(x) are the bus specifications?

Perhaps @ccoffrin can help me out? Thanks!

Hi @timueh! Thanks for your question.

As of PowerModels v0.14, PowerModels focuses on building JuMP models (with DC Power Flow being the only dedicated routine that does not require JuMP). So it is not easy to extract the system of equations into Julia functions, such as f(x). If you would like to quickly inspect the JuMP model you can do this,

using PowerModels; using JuMP; using Ipopt
m = Model()
result = run_ac_opf("case.m", with_optimizer(Ipopt.Optimizer), jump_model=m)

This issue may be of interest,, which seeks to develop a dedicated AC Power Flow solver in PowerModels that would not require JuMP, which could be used to extract the functions you are interested in.

You might find the calc_power_balance and calc_branch_flow_ac functions useful, which simply evaluate the power flow equations on the data model.