# Newton method in PowerModels.jl

**URL:** <https://discourse.julialang.org/t/newton-method-in-powermodels-jl/61568>\
**Category:** Optimization (Mathematical)\
**Created:** [May 21, 2021, 9:34am UTC](https://discourse.julialang.org/t/newton-method-in-powermodels-jl/61568 "2021-05-21T09:34:43Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Mariana](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mariana/32/15064_2.png) [@Mariana](https://discourse.julialang.org/u/Mariana)\
**Post date:** [May 21, 2021, 9:34am UTC](https://discourse.julialang.org/t/newton-method-in-powermodels-jl/61568/1 "2021-05-21T09:34:43Z")

</div>

Hello!

I am trying to run a power flow in PowerModels.jl by using Newton method. I am running compute\_ac\_pf, but the result of this function is a dictionary containing generation and voltages at the buses, and it does not have a key “solution”. However, I am also interested in obtaining the flows in the lines of the system. Is there any way I can get these results? I am using version 0.17 of PowerModels.jl.

---

<div class="post-metadata">

**Author:** ![odow](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/odow/32/28685_2.png) [@odow](https://discourse.julialang.org/u/odow)\
**Post date:** [May 23, 2021, 2:36am UTC](https://discourse.julialang.org/t/newton-method-in-powermodels-jl/61568/2 "2021-05-23T02:36:38Z")

</div>

It’s easier to provide help if you show a minimal working example. This post has some helpful tips: [Please read: make it easier to help you](https://discourse.julialang.org/t/psa-make-it-easier-to-help-you/14757)

The `solution` key got added in v0.18 of PowerModels.jl, [PowerModels v0.18.0 by ccoffrin · Pull Request #768 · lanl-ansi/PowerModels.jl · GitHub](https://github.com/lanl-ansi/PowerModels.jl/pull/768/files), so I suggest you update your code.

---

<div class="post-metadata">

**Author:** ![ccoffrin](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ccoffrin/32/400_2.png) [@ccoffrin](https://discourse.julialang.org/u/ccoffrin)\
**Post date:** [May 23, 2021, 2:59pm UTC](https://discourse.julialang.org/t/newton-method-in-powermodels-jl/61568/3 "2021-05-23T14:59:08Z")

</div>

Hi Mariana, have a look at this docs page, [Power Flow · PowerModels](https://lanl-ansi.github.io/PowerModels.jl/stable/power-flow/) it should help you get started in the right direction.

---

<div class="post-metadata">

**Author:** ![Mariana](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mariana/32/15064_2.png) [@Mariana](https://discourse.julialang.org/u/Mariana)\
**Post date:** [June 7, 2021, 5:21pm UTC](https://discourse.julialang.org/t/newton-method-in-powermodels-jl/61568/4 "2021-06-07T17:21:41Z")

</div>

Thank you, @odow and @ccoffrin !! I updated my code to v0.18 of PowerModels.jl and it worked. However, I noticed that when I run the generic power flow, by using the `run_pf` function with the `ACRPowerModel` formulation, the ` calc_branch_flow_ac` function doesn’t return updated values for the branch flows. When I use the `run_pf` function with the `ACPPowerModel` formulation, or directly the `run_ac_pf` function, I am able to obtain the correct values for the branch flows. Here is my code:

```julia
using PowerModels
using Ipopt

network_data = parse_file("/Users/marianarodrigues/Desktop/Sistema Inicial/teste_novo.raw")
print_summary(network_data)

# ========================= JuMP solution =========================

#result = run_ac_pf(network_data, Ipopt.Optimizer)
result = run_pf(network_data, ACRPowerModel, Ipopt.Optimizer)

# Check that the solver converged:
update_data!(network_data, result["solution"])

flows = calc_branch_flow_ac(network_data)
update_data!(network_data, flows)
print_summary(network_data)

```
