Skip to content

Add sparse AC-OPF tutorial - #448

Open
blegat wants to merge 4 commits into
mainfrom
bl/opf
Open

blegat wants to merge 4 commits into
mainfrom
bl/opf

Conversation

@blegat

@blegat blegat commented Jul 20, 2026 •

Copy link
Copy Markdown
Member

We could also just give SumOfSquares.Optimizer to the formulation produced by PowerModels.

Preview https://jump-dev.github.io/SumOfSquares.jl/previews/PR448

Needs

cc @langestefan

@codecov

codecov Bot commented Jul 20, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 89.21%. Comparing base (75b80ea) to head (b1bcfab).

Additional details and impacted files
@@           Coverage Diff           @@
##             main     #448   +/-   ##
=======================================
  Coverage   89.21%   89.21%           
=======================================
  Files          46       46           
  Lines        3172     3172           
=======================================
  Hits         2830     2830           
  Misses        342      342           

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

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

# Quadratically Constrained Quadratic Program).
#
# TSSOS handles an equality constraint `h = 0` with a *free* polynomial
# multiplier. This is equivalent to enforcing `h ≥ 0` and `-h ≥ 0` with

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This confirms that we need #163, @tweisser opened that issue working on AC-OPF too unsurprisingly ^^

@langestefan

Copy link
Copy Markdown

Hello Benoit, great work! This will be a useful tool when working on AC-OPF.

It seems that the full CS-TSSOS method, meaning term sparsity + correlative sparsity, isn't implemented yet?

It would also be nice to see some results from Pglib.jl, to compare against TSSOS. Similar to tables 7/8 from https://dl.acm.org/doi/pdf/10.1145/3569709

@blegat

blegat commented Oct 14, 2026

Copy link
Copy Markdown
Member Author

It is, correlative sparsity is here: https://github.com/jump-dev/SumOfSquares.jl/blob/main/src/Certificate/Sparsity/variable.jl and term sparsity is here: https://github.com/jump-dev/SumOfSquares.jl/blob/main/src/Certificate/Sparsity/monomial.jl
I'm not merging because I'd like to close #163 first. I could make a workaround in this example but I'd rather go for the clean solution.
I'm finishing JuliaAlgebra/MultivariatePolynomials.jl#367 first then #163 is next, then I'll finish this PR.

@langestefan

langestefan commented Oct 14, 2026 •

Copy link
Copy Markdown

It is, correlative sparsity is here: https://github.com/jump-dev/SumOfSquares.jl/blob/main/src/Certificate/Sparsity/variable.jl and term sparsity is here: https://github.com/jump-dev/SumOfSquares.jl/blob/main/src/Certificate/Sparsity/monomial.jl

Sorry I meant to say that, in this tutorial you do term sparsity and correlative sparsity independently:

https://github.com/jump-dev/SumOfSquares.jl/pull/448/changes#diff-1563061abe66d45653849f3def9a9656ed337f59c3d89719efd99cb999dca280R323

https://github.com/jump-dev/SumOfSquares.jl/pull/448/changes#diff-1563061abe66d45653849f3def9a9656ed337f59c3d89719efd99cb999dca280R306

Basically:

  • Sparsity.Variable(): step 1 only (just CSSOS)
  • Sparsity.Monomial(ChordalCompletion()): this is TS on the whole problem

But not the combination of term + correlative sparsity that CS-TSSOS offers. This is not supported by SoS.jl yet it seems

@blegat
blegat changed the base branch from main to bl/sparsity_equalities November 24, 2026 12:06
@blegat
blegat added this pull request to stack #461 November 24, 2026 19:54
@blegat
blegat force-pushed the bl/opf branch 2 times, most recently from d64bc36 to ba7a9c4 Compare November 25, 2026 14:56
@blegat
blegat removed this pull request from stack #461 November 25, 2026 14:58
@blegat
blegat changed the base branch from bl/sparsity_equalities to bl/cs_tssos November 25, 2026 14:58
@blegat
blegat added this pull request to stack #483 November 25, 2026 14:58
@blegat

blegat commented Nov 25, 2026

Copy link
Copy Markdown
Member Author

Good point, this is now done in #482

Base automatically changed from bl/cs_tssos to main November 30, 2026 15:26
Use the degree-two truncated ideal for balance equations, the reference
voltage and the three zero active generator powers. Match the normalization
and generator bounds of pop_opf_real. Retain all selected monomials for
one minimum-fill term-sparsity step.

Reference: TSSOS.jl 591f036e, example/modelopf.jl, PGLib 0.2.2,
PowerModels 0.21.7. Run pop_opf_real on pglib_opf_case14_ieee with
normal=true, AngleCons=true, LineLimit="relax". Run cs_tssos at order 1
with (CS, TS) = (false, false), ("MF", false), (false, "MF").
Use Clarabel in both packages and rescale the TSSOS objective as in runopf.jl.

| Pattern | TSSOS blocks / max | SOS blocks / max | TSSOS bound | SOS bound |
| --- | ---: | ---: | ---: | ---: |
| Dense | 1 / 39 | 1 / 36 | 2178.080019 | 2178.079324 |
| Correlative | 28 / 7 | 28 / 7 | 2178.080355 | 2178.079741 |
| Term | 28 / 6 | 25 / 6 | 2178.080416 | 2178.079061 |

Compared the coefficient maps of the objective, 115 inequalities and 32
equalities. Checked the multiplier bases and the clique labels. Projecting
out the three zero active powers gives identical maximal dense and term
cliques. For correlative sparsity, five fill edges differ in each direction.
Every one of the 123 required nonfixed moment entries occurs in both
patterns and both clique families satisfy running intersection. The
different fill variables therefore give equivalent PSD completions.
Run the real-voltage pglib_opf_case14_ieee model at order one with
normal=true, AngleCons=true and LineLimit="relax". Use cs_tssos with
CS="MF", TS="MF", MomentOne=false on TSSOS.jl 591f036e, scaling its
objective as in example/runopf.jl. Use Clarabel for both solves.

| Implementation | Lower bound | Gram blocks | Largest block | Nonnegative inequality multipliers |
| --- | ---: | ---: | ---: | ---: |
| CS-TSSOS | 2175.655968 | 80 | 5 | 211 |
| SumOfSquares | 2175.655851 | 80 | 5 | 115 |

Compared all 148 input polynomials by support and coefficient. Label the
constant 0 and each linear monomial by its OPF variable index. Sorting
the labels in each block and comparing the resulting multisets gives
exact agreement with data.basis[i][1][b] for b in data.blocks[i][1]
over all variable cliques i.

Both SDPs specify the same 135 moments. The TSSOS equality rows have
rank 35. They lie in the degree-two Macaulay row space, and restricting
that row space to these moment coordinates also gives dimension 35.
The 211 nonnegative scalar multipliers combine by inequality into 115.
Give Ipopt and SumOfSquares.Optimizer the same JuMP model. Compare the
first-order bound with the explicit TSSOS formulation and explain how
eliminating branch flows changes the thermal limits and the Gram basis.

| PGLib case14 | Variables | Largest Gram block | Objective or bound |
| --- | ---: | ---: | ---: |
| PowerModels ACR, Ipopt | 118 | — | 2178.080412 |
| PowerModels ACR, first-order SOS (SCS) | 118 | 119 | 2178.080436 |
| TSSOS formulation, dense SOS (Clarabel) | 38 | 36 | 2178.079324 |

SCS used absolute and relative tolerances of 1e-9. The numerical SOS
bound exceeds the Ipopt objective by about 0.000024. The tutorial checks
agreement of the two dense relaxation values to within 0.01 on case14.

This branch has not been deployed

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

Labels

None yet

Development

Successfully merging this pull request may close these issues.

2 participants