Skip to content

Conversation

@m-bossart
Copy link
Collaborator

No description provided.

Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This pull request enables Ward reduction for DC power flow methods with a warning message. Previously, Ward reduction was completely unsupported and would throw a NotImplementedError. The changes allow Ward reduction to be used with DC power flow methods (DCPowerFlow, PTDFDCPowerFlow, and vPTDFDCPowerFlow) but warn users that branch flows for branches in parallel with equivalent branches added by Ward reduction may give unexpected results.

Changes:

  • Modified the network_reduction_message function to allow Ward reduction with DC power flow methods while emitting a warning instead of throwing an error
  • Added a new test suite for Ward reduction with DC power flow methods

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 6 comments.

File Description
src/PowerFlowData.jl Modified network_reduction_message to allow Ward reduction with DC power flow (with warning) instead of throwing NotImplementedError
test/test_reduced_dc_power_flow.jl Added new test suite for Ward reduction with all DC power flow types

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

results = PF.solve_power_flow(
dc_pf,
sys;
network_reductions = NetworkReduction[WardReduction(study_buses)],
Copy link

Copilot AI Jan 30, 2026

Choose a reason for hiding this comment

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

Missing namespace prefix for NetworkReduction and WardReduction. These should be PNM.NetworkReduction and PNM.WardReduction to be consistent with the rest of the file (see lines 6-10).

Suggested change
network_reductions = NetworkReduction[WardReduction(study_buses)],
network_reductions = PNM.NetworkReduction[PNM.WardReduction(study_buses)],

Copilot uses AI. Check for mistakes.
),
)
end
if m isa DCPowerFlow && any(isa.(nrs, (PNM.WardReduction,)))
Copy link

Copilot AI Jan 30, 2026

Choose a reason for hiding this comment

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

The condition checks for DCPowerFlow specifically, but should check for AbstractDCPowerFlow to cover all DC power flow types (DCPowerFlow, PTDFDCPowerFlow, and vPTDFDCPowerFlow). The test in test_reduced_dc_power_flow.jl iterates over all subtypes of AbstractDCPowerFlow, so PTDFDCPowerFlow and vPTDFDCPowerFlow with WardReduction would not trigger this warning.

Suggested change
if m isa DCPowerFlow && any(isa.(nrs, (PNM.WardReduction,)))
if m isa AbstractDCPowerFlow && any(isa.(nrs, (PNM.WardReduction,)))

Copilot uses AI. Check for mistakes.
)
end
if m isa DCPowerFlow && any(isa.(nrs, (PNM.WardReduction,)))
@warn "Use ward reduction with DC power flow with caution. Flows for arcs in parallel with equivalent branches added during Ward will give unexpected results."
Copy link

Copilot AI Jan 30, 2026

Choose a reason for hiding this comment

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

Inconsistent capitalization: "ward" should be "Ward" to match the capitalization used in the error message on line 404 and to be consistent with proper noun capitalization for the Ward reduction method.

Suggested change
@warn "Use ward reduction with DC power flow with caution. Flows for arcs in parallel with equivalent branches added during Ward will give unexpected results."
@warn "Use Ward reduction with DC power flow with caution. Flows for arcs in parallel with equivalent branches added during Ward will give unexpected results."

Copilot uses AI. Check for mistakes.
end
end

# Ward reduction tested separately from Radial/Degree Two reductions because power flow results for retained buses is not expected to match exactly.
Copy link

Copilot AI Jan 30, 2026

Choose a reason for hiding this comment

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

Grammatical error: "results ... is not expected" should be "results ... are not expected" since "results" is plural.

Suggested change
# Ward reduction tested separately from Radial/Degree Two reductions because power flow results for retained buses is not expected to match exactly.
# Ward reduction tested separately from Radial/Degree Two reductions because power flow results for retained buses are not expected to match exactly.

Copilot uses AI. Check for mistakes.
end

# Ward reduction tested separately from Radial/Degree Two reductions because power flow results for retained buses is not expected to match exactly.
@testset "RTS: Ward Reduction and DC Power Flow" begin
Copy link

Copilot AI Jan 30, 2026

Choose a reason for hiding this comment

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

The UNSUPPORTED list in test/test_reduced_ac_power_flow.jl still includes Ward reduction with DC power flow types (DCPowerFlow, PTDFDCPowerFlow, vPTDFDCPowerFlow on lines 5-7 of that file). Since this PR enables Ward reduction with DC power flow, those entries should be removed from the UNSUPPORTED list to maintain consistency across the test suite.

Copilot uses AI. Check for mistakes.
)
end
if m isa DCPowerFlow && any(isa.(nrs, (PNM.WardReduction,)))
@warn "Use ward reduction with DC power flow with caution. Flows for arcs in parallel with equivalent branches added during Ward will give unexpected results."
Copy link

Copilot AI Jan 30, 2026

Choose a reason for hiding this comment

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

The warning message could be clearer. The phrase "Flows for arcs in parallel with equivalent branches added during Ward" is somewhat unclear. Consider rephrasing to something like "Branch flows for branches in parallel with equivalent branches added by Ward reduction may be incorrect" for better clarity.

Suggested change
@warn "Use ward reduction with DC power flow with caution. Flows for arcs in parallel with equivalent branches added during Ward will give unexpected results."
@warn "Use Ward reduction with DC power flow with caution. Branch flows for branches in parallel with equivalent branches added by Ward reduction may be incorrect."

Copilot uses AI. Check for mistakes.
@github-actions
Copy link
Contributor

Performance Results

Version Precompile Time
Main 2.612583244
This Branch 2.450543529
Version Run Time
Main-matpower_ACTIVSg10k_sys-NewtonRaphsonACPowerFlow- first solve 10.595496443
Main-matpower_ACTIVSg10k_sys-NewtonRaphsonACPowerFlow- second solve 0.083758135
Main-matpower_ACTIVSg10k_sys-RobustHomotopyPowerFlow- first solve 11.071419118
Main-matpower_ACTIVSg10k_sys-RobustHomotopyPowerFlow- second solve 7.827137909
This Branch-matpower_ACTIVSg10k_sys-NewtonRaphsonACPowerFlow- first solve 10.294857739
This Branch-matpower_ACTIVSg10k_sys-NewtonRaphsonACPowerFlow- second solve 0.08227202
This Branch-matpower_ACTIVSg10k_sys-RobustHomotopyPowerFlow- first solve 11.771523759
This Branch-matpower_ACTIVSg10k_sys-RobustHomotopyPowerFlow- second solve 7.97172142

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.

2 participants