Extracting the Power Flow equations from PowerModels

Hello,

I’m relatively new to both Julia and PowerModels.jl, and I wish to compare different algorithms for solving power flow equations. My objective is to obtain the power flow equations from PowerModels.jl, allowing me to integrate them into various algorithms and compare results with those obtained using JuMP.

In the PowerModels documentation, I haven’t come across a specific function that returns the equations. Does such a function exist, or is do you know an alternative approach to achieve this?

Thanks in advance!

Jim

Hi @Jim16, welcome to the forum. (Sorry I didn’t see your question yesterday, I’ve now moved it to the “Optimization (Mathematical)” section.)

What format do you want/expect the equations to be in?

The math formulation is described in Mathematical Model · PowerModels.

You can also see the underlying JuMP model with pm.model:
https://lanl-ansi.github.io/PowerModels.jl/stable/quickguide/#Building-PowerModels-from-Network-Data-Dictionaries

Hi @Jim16, thank for taking a look at PowerModels. To add to the suggestions of @odow, some times folks are looking for raw JuMP models for the OPF problems that PowerModels builds in a more flexible way. Here is a good reference for those,

Another question we get a fair bit it to view the mathematical JuMP model that PowerModels builds for a given function call. In this case you can do a trick like this (I did not test this code),

using PowerModels, JuMP, Ipopt
m = Model()
result = solve_ac_opf(data, Ipopt.Optimizer, jump_model=m)
println(m)
1 Like

Thanks for your answers !

@odow : the best format would be to have them as a function on all the voltage magnitudes and angles, so that solving the pf equations would be the same as finding the roots of the function.

@ccoffrin : I’ll have a look at PowerModelsAnnex, thank you. About the bit of code you shared, I had already used this trick, but I didn’t manage to build an actual function containing the equations of the model. I could only display them.

I don’t know if there’s an easy way to get the equations as a Julia function that you can call.

This repo has a number of Julia function implementations though: