Skip to content

Change compute_ac_pf iteration to use more standard (smaller) Jacobian - #1011

Draft
LKuhrmann wants to merge 7 commits into
lanl-ansi:masterfrom
LKuhrmann:smaller_Jacobian
Draft

Change compute_ac_pf iteration to use more standard (smaller) Jacobian#1011
LKuhrmann wants to merge 7 commits into
lanl-ansi:masterfrom
LKuhrmann:smaller_Jacobian

Conversation

@LKuhrmann

Copy link
Copy Markdown
Contributor

Change

Fixes #1009.

Reduces what is iterated in the Newton Raphson iteration from [P, Q] for all buses to [P, Q] for PQ buses and [P] for PV buses. This reduces the Jacobian size by the number of PV busses +2.

I believe the implementation I am suggesting is more standard. The first two random results I get when I google for "newton raphson power flow" support this: random university pdf 1, page 111ff and random university pdf 2, page 9

Impact

Should make compute_ac_pf slightly faster and more memory efficient with more standard convergence when compared to other power flow tools.

As this PR simplifies the Newton-Raphson iteration by no longer converging toward Q injections (for PV and slack buses) and P injection (for the slack bus) I would expect this to converge whenever the current implementation converges.
But I can't prove that, so there is a risk that this might break convergence in some (probably a bit weird) cases.

Todo

I assume this change will need some tests. One test that could be added is the one presented in #1009 that does not currently converge.

I am uncertain if the way I implemented this is inline with the broader PowerModels codebase, so I am keen for code changes/opinions!

What else would need to happen so this can be merged?
If there are reasons for the current power flow implementation I am keen to hear them!

@codecov

codecov Bot commented Jul 27, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 97.08029% with 4 lines in your changes missing coverage. Please review.
✅ Project coverage is 93.94%. Comparing base (dd45675) to head (798e373).

Files with missing lines Patch % Lines
src/core/admittance_matrix.jl 93.75% 2 Missing ⚠️
src/prob/pf.jl 98.09% 2 Missing ⚠️
Additional details and impacted files

Impacted file tree graph

@@           Coverage Diff           @@
##           master    #1011   +/-   ##
=======================================
  Coverage   93.94%   93.94%           
=======================================
  Files          43       43           
  Lines        9676     9731   +55     
=======================================
+ Hits         9090     9142   +52     
- Misses        586      589    +3     
Files with missing lines Coverage Δ
src/core/admittance_matrix.jl 92.62% <93.75%> (+0.11%) ⬆️
src/prob/pf.jl 95.65% <98.09%> (+0.02%) ⬆️

Continue to review full report in Codecov by Harness.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update dd45675...798e373. Read the comment docs.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@LKuhrmann

Copy link
Copy Markdown
Contributor Author

Seems like the remaining failing tests would be fixed by #1010

@langestefan

langestefan commented Aug 11, 2026

Copy link
Copy Markdown

I think this will be cleaner to implement on top of #1013. That PR also converges on your test case.

This PR adds duplicate code to admittance_matrix.jl. It also adds new fields to AdmittanceMatrix, which is also used by packages such as PowerModelsACDC: https://github.com/Electa-Git/PowerModelsACDC.jl/blob/8b8752720d454bba26237eb3a8012f6467bf48bd/src/prob/sacdcpf.jl#L760

We can instead put the map in PowerFlowData, which I think will be cleaner.

@LKuhrmann

Copy link
Copy Markdown
Contributor Author

Interesting that #1013 converges on my test case, as it also seems to use the larger (nonstandard) Jacobian.

I don't really have an opinion on what would be cleaner or how newton-rahpson should be implemented, my primary concern is convergence parity with other newton-raphson solvers.

@langestefan

langestefan commented Aug 18, 2026

Copy link
Copy Markdown

I am still investigating, but it seems we found a bug that you resolved in this PR here:

https://github.com/lanl-ansi/PowerModels.jl/pull/1011/changes#diff-2b965b9925b2c961928bd613df19e77854d7f5f85c49b24fbea67f20914245bbR587-R590

On the main branch it's taking the state vectors from the last call to f!. But that means that OnceDifferentiable gets the Jacobian before it computes the residual, meaning at every iterate the Jacobian we use is the one from the previous step. This is actually the thing that causes the divergences on some test cases you observed, not the Jacobian formulation.

This is why my Newton implementation without the reduced Jacobian from #1012 also converges. Because it also does not make this mistake. We should make a new issue for this.

@LKuhrmann

Copy link
Copy Markdown
Contributor Author

Very interesting!

I will see if I can find other cases where the convergence difference is the result of the smaller jacobian rather than a result of the jacobian using the newest voltages.

If updating the voltage twice (as I implemented in the lines you link) fixes the convergence issues, then it could be a very simple bugfix from a convergence perspective.

@langestefan

Copy link
Copy Markdown

I have opened #1016 to discuss.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Newton-Raphson power flow convergence differs from other power flow tools

2 participants