Skip to content

remove parameterization of branches parallel#295

Open
m-bossart wants to merge 1 commit intomainfrom
mb/branches-parallel
Open

remove parameterization of branches parallel#295
m-bossart wants to merge 1 commit intomainfrom
mb/branches-parallel

Conversation

@m-bossart
Copy link
Copy Markdown
Contributor

No description provided.

@m-bossart m-bossart requested a review from Copilot April 24, 2026 16:24
@m-bossart
Copy link
Copy Markdown
Contributor Author

Fixes #294

Copy link
Copy Markdown
Contributor

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

Note

Copilot was unable to run its full agentic suite in this review.

This PR removes the type-parameterization from BranchesParallel, updating constructors, helper methods, mapping utilities, and a test to work with a non-generic BranchesParallel container.

Changes:

  • Refactors BranchesParallel{T} into a non-parameterized BranchesParallel holding Vector{PSY.ACTransmission}.
  • Updates Ybus parallel-branch insertion logic to operate on the non-parameterized structure.
  • Adjusts network reduction typed-map utilities and tests to expect BranchesParallel rather than BranchesParallel{T}.

Reviewed changes

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

File Description
test/test_arc_types_and_reductions.jl Updates reduction-type assertion to use BranchesParallel without a type parameter.
src/Ybus.jl Refactors _push_parallel_branch! to accept PSY.ACTransmission and handle mixed-type parallels without re-wrapping.
src/NetworkReductionData.jl Updates typed parallel-branch map return types and segment helpers for non-parameterized BranchesParallel.
src/BranchesParallel.jl Implements non-parameterized BranchesParallel and updates constructors, map-filtering logic, and helpers accordingly.

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

Comment thread src/Ybus.jl
br::PSY.ACTransmission,
)
bp = parallel_branch_map[arc_tuple]
if any(typeof(b) != typeof(br) for b in bp.branches)
Copy link

Copilot AI Apr 24, 2026

Choose a reason for hiding this comment

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

This warning will trigger on every subsequent insertion once a circuit becomes mixed-type (and may also warn repeatedly even when adding a branch of an already-present type). To reduce log noise, warn only when the newly added branch introduces a new concrete type (e.g., compare typeof(br) against the existing set of types), or record that a given arc_tuple has already emitted the mismatch warning.

Suggested change
if any(typeof(b) != typeof(br) for b in bp.branches)
existing_branch_types = Set(typeof(b) for b in bp.branches)
if !isempty(existing_branch_types) && !(typeof(br) in existing_branch_types)

Copilot uses AI. Check for mistakes.
Comment thread src/BranchesParallel.jl
Comment on lines +1 to +2
mutable struct BranchesParallel <: PSY.ACTransmission
branches::Vector{PSY.ACTransmission}
Copy link

Copilot AI Apr 24, 2026

Choose a reason for hiding this comment

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

Storing branches as Vector{PSY.ACTransmission} (an abstract element type) can significantly increase dynamic dispatch and reduce inference in performance-sensitive loops (e.g., building Ybus / iterating branch properties). If this code is on a hot path, consider preserving concreteness by keeping a typed representation internally (e.g., continuing to store homogeneous parallels in a concrete vector and only type-erasing for truly mixed-type collections), or adding a fast-path for the common homogeneous case to avoid repeatedly operating on abstractly-typed elements.

Copilot uses AI. Check for mistakes.
Comment thread src/BranchesParallel.jl
Comment on lines +6 to +7
function BranchesParallel(branches::Vector{<:PSY.ACTransmission})
BranchesParallel(Vector{PSY.ACTransmission}(branches), nothing)
Copy link

Copilot AI Apr 24, 2026

Choose a reason for hiding this comment

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

Storing branches as Vector{PSY.ACTransmission} (an abstract element type) can significantly increase dynamic dispatch and reduce inference in performance-sensitive loops (e.g., building Ybus / iterating branch properties). If this code is on a hot path, consider preserving concreteness by keeping a typed representation internally (e.g., continuing to store homogeneous parallels in a concrete vector and only type-erasing for truly mixed-type collections), or adding a fast-path for the common homogeneous case to avoid repeatedly operating on abstractly-typed elements.

Copilot uses AI. Check for mistakes.
Comment thread src/BranchesParallel.jl
filters::Dict,
) where {T <: PSY.ACTransmission}
function add_to_map(double_circuit::BranchesParallel, filters::Dict)
isempty(filters) && return true
Copy link

Copilot AI Apr 24, 2026

Choose a reason for hiding this comment

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

only(branch_types) will throw if double_circuit.branches is empty (since branch_types would be empty). If BranchesParallel can ever be constructed/observed with an empty branches vector, add an explicit guard (e.g., return true or throw a clearer error) before calling only.

Suggested change
isempty(filters) && return true
isempty(filters) && return true
isempty(double_circuit.branches) && return true

Copilot uses AI. Check for mistakes.
Comment thread src/BranchesParallel.jl
Comment on lines +151 to 152
T = only(branch_types)
if !haskey(filters, T)
Copy link

Copilot AI Apr 24, 2026

Choose a reason for hiding this comment

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

only(branch_types) will throw if double_circuit.branches is empty (since branch_types would be empty). If BranchesParallel can ever be constructed/observed with an empty branches vector, add an explicit guard (e.g., return true or throw a clearer error) before calling only.

Copilot uses AI. Check for mistakes.
::Type{T},
) where {T <: PSY.ACTransmission}
return b.parallel_branch_map[T]::Dict{Tuple{Int, Int}, BranchesParallel{T}}
return b.parallel_branch_map[T]::Dict{Tuple{Int, Int}, BranchesParallel}
Copy link

Copilot AI Apr 24, 2026

Choose a reason for hiding this comment

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

The function name get_typed_parallel_branch_map suggests the returned map is typed/consistent w.r.t. T, but the value type is now BranchesParallel (which can contain mixed ACTransmission types). Consider either (a) renaming/adjusting the API/docs to avoid implying type-homogeneity, or (b) enforcing (via checks) that entries in parallel_branch_map[T] only contain branches of type T when returned through this accessor.

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

Performance Results

Precompile Time

Main This Branch Delta
2.188 s 2.191 s +0.1%

Execution Time

Test Main This Branch Delta
matpower_ACTIVSg2000_sys-Build PTDF First 2.205 s 2.041 s -7.4%
matpower_ACTIVSg2000_sys-Build PTDF Second 113.2 ms 76.2 ms -32.7%
matpower_ACTIVSg2000_sys-Build Ybus First 13.8 ms 12.6 ms -8.2%
matpower_ACTIVSg2000_sys-Build Ybus Second 12.5 ms 11.3 ms -10.1%
matpower_ACTIVSg2000_sys-Build LODF First 158.5 ms 181.0 ms +14.2%
matpower_ACTIVSg2000_sys-Build LODF Second 222.6 ms 229.2 ms +3.0%
matpower_ACTIVSg2000_sys-Build VirtualMODF First 4.205 s 4.986 s +18.6%
matpower_ACTIVSg2000_sys-Build VirtualMODF Second 210.7 ms 726.4 ms +244.8%
matpower_ACTIVSg2000_sys-VirtualMODF Query 10 rows 511.6 ms 541.5 ms +5.8%
matpower_ACTIVSg2000_sys-Radial network reduction First 468.5 ms 464.1 ms -0.9%
matpower_ACTIVSg2000_sys-Radial network reduction Second 0.7 ms 0.6 ms -1.8%
matpower_ACTIVSg2000_sys-Degree two network reduction First 1.929 s 1.623 s -15.9%
matpower_ACTIVSg2000_sys-Degree two network reduction Second 1.0 ms 1.0 ms -4.9%
Base_Eastern_Interconnect_515GW-Build Ybus First 3.728 s 4.039 s +8.3%
Base_Eastern_Interconnect_515GW-Build Ybus Second 3.554 s 3.508 s -1.3%
Base_Eastern_Interconnect_515GW-Radial network reduction First 34.4 ms 37.7 ms +9.6%
Base_Eastern_Interconnect_515GW-Radial network reduction Second 35.3 ms 36.9 ms +4.5%
Base_Eastern_Interconnect_515GW-Degree two network reduction First 387.1 ms 171.2 ms -55.8%
Base_Eastern_Interconnect_515GW-Degree two network reduction Second 48.4 ms 36.8 ms -23.9%

@m-bossart
Copy link
Copy Markdown
Contributor Author

This is currently failing in the model build for WECC as well.

@m-bossart m-bossart requested a review from jd-lara April 24, 2026 18:54
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