Skip to content

add monitored components to exceptions automatically#309

Merged
jd-lara merged 18 commits into
mainfrom
jd/handle_exceptions_modf
May 29, 2026
Merged

add monitored components to exceptions automatically#309
jd-lara merged 18 commits into
mainfrom
jd/handle_exceptions_modf

Conversation

@jd-lara
Copy link
Copy Markdown
Member

@jd-lara jd-lara commented May 27, 2026

This PR makes sure that if reductions are applied then the outages monitored components buses are automatically added to the exceptions list to prevent incorrect ABA calculations

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

This PR ensures VirtualMODF remains reduction-consistent by automatically protecting (i.e., retaining through network reductions) the buses needed to keep all outaged and outage-declared monitored transmission components expressible as arcs, preventing incorrect ABA/Woodbury behavior and confusing query failures.

Changes:

  • Add logic to collect “protected buses” from outaged components and their monitored_components, and inject them into requested network reductions.
  • Improve failure/diagnostics by warning when a transmission outage is dropped by reductions and by providing a clearer error when querying a reduced-away monitored arc tuple.
  • Add a comprehensive regression test suite covering protection behavior across Radial/DegreeTwo/Ward reductions, monitored components, and error/warn paths.

Reviewed changes

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

File Description
src/modf_reduction_consistency.jl New helpers to compute protected buses and augment reductions accordingly.
src/virtual_modf_calculations.jl Wire protection into VirtualMODF construction; add warning for dropped transmission outages; add clearer reduced-arc tuple error.
src/PowerNetworkMatrices.jl Include the new consistency helper file in module load order.
test/test_modf_reduction_consistency.jl New end-to-end and helper-level tests for reduction/outage/monitoring consistency.

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

Comment thread src/virtual_modf_calculations.jl Outdated
Comment on lines +63 to +67
- `network_reduction_data::NetworkReductionData`:
Network reduction mappings for branch resolution.
Network reduction mappings for branch resolution. Its `irreducible_buses`
set is the authoritative record of buses retained from reduction,
including those protected so every outaged and monitored component stays
expressible as an arc (the MODF "exception list").
Comment on lines +371 to +375
isempty(mod.arc_modifications) || return
transmission =
PSY.get_associated_components(sys, outage; component_type = PSY.ACTransmission)
isempty(collect(transmission)) && return
@warn "Outage (label=$(mod.label)) references transmission components but " *
Comment thread src/virtual_modf_calculations.jl Outdated
Comment on lines +288 to +294
if isempty(network_reductions)
applied_reductions = network_reductions
else
protected_buses = _collect_protected_buses(sys)
applied_reductions =
_adjust_reductions_for_protection(network_reductions, protected_buses)
end
PSY.add_supplemental_attribute!(
sys,
outaged,
_fixed_outage(; monitored = [monitored]),
PSY.add_supplemental_attribute!(
sys,
outaged,
_fixed_outage(; monitored = [monitored]),
@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented May 27, 2026

Performance Results

Precompile Time

Main This Branch Delta
2.184 s 2.216 s +1.5%

Execution Time

Test Main This Branch Delta
matpower_ACTIVSg2000_sys-Build PTDF First 2.409 s 2.259 s -6.2%
matpower_ACTIVSg2000_sys-Build PTDF Second 78.0 ms 74.6 ms -4.3%
matpower_ACTIVSg2000_sys-Build Ybus First 15.5 ms 11.7 ms -24.0%
matpower_ACTIVSg2000_sys-Build Ybus Second 13.5 ms 10.8 ms -20.1%
matpower_ACTIVSg2000_sys-Build LODF First 148.5 ms 158.3 ms +6.6%
matpower_ACTIVSg2000_sys-Build LODF Second 205.9 ms 210.7 ms +2.4%
matpower_ACTIVSg2000_sys-Build VirtualMODF First 2.008 s 3.927 s +95.5%
matpower_ACTIVSg2000_sys-Build VirtualMODF Second 69.6 ms 1.049 s +1408.3%
matpower_ACTIVSg2000_sys-VirtualMODF Query 10 rows 497.7 ms 508.4 ms +2.2%
matpower_ACTIVSg2000_sys-Radial network reduction First 469.7 ms 550.0 ms +17.1%
matpower_ACTIVSg2000_sys-Radial network reduction Second 0.7 ms 0.7 ms +1.5%
matpower_ACTIVSg2000_sys-Degree two network reduction First 1.768 s 1.898 s +7.4%
matpower_ACTIVSg2000_sys-Degree two network reduction Second 1.1 ms 1.2 ms +9.8%
Base_Eastern_Interconnect_515GW-Build Ybus First 3.461 s 902.1 ms -73.9%
Base_Eastern_Interconnect_515GW-Build Ybus Second 3.264 s 880.6 ms -73.0%
Base_Eastern_Interconnect_515GW-Radial network reduction First 35.7 ms 43.5 ms +22.0%
Base_Eastern_Interconnect_515GW-Radial network reduction Second 37.3 ms 43.5 ms +16.8%
Base_Eastern_Interconnect_515GW-Degree two network reduction First 367.1 ms 381.6 ms +3.9%
Base_Eastern_Interconnect_515GW-Degree two network reduction Second 51.8 ms 43.1 ms -16.9%

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

Copilot reviewed 8 out of 8 changed files in this pull request and generated 3 comments.

Comment thread src/virtual_modf_calculations.jl Outdated
Comment on lines +67 to +70
- `network_reduction_data::NetworkReductionData`:
Network reduction mappings for branch resolution.
Network reduction mappings for branch resolution. Its `irreducible_buses`
set records the buses retained from reduction, including those protected
so outaged and monitored components stay queryable (the "exception list").
Comment thread src/modf_reduction_consistency.jl Outdated
Comment on lines +95 to +113
# Ward retains `study_buses`; a protected external bus must join the study area
# so its incident branch is not equivalenced away.
function _augment_reduction(reduction::WardReduction, protected::Set{Int})
isempty(protected) && return reduction
return WardReduction(_merge_irreducible(reduction.study_buses, protected))
end

"""
_adjust_reductions_for_protection(reductions, protected) -> Vector{NetworkReduction}

Return a new reduction vector in which each reduction's protected-bus set has
been extended with `protected`.
"""
function _adjust_reductions_for_protection(
reductions::Vector{NetworkReduction},
protected::Set{Int},
)
return NetworkReduction[_augment_reduction(r, protected) for r in reductions]
end
Comment on lines +37 to +38
_fixed_outage(; monitored = Base.UUID[]) =
PSY.FixedForcedOutage(; outage_status = 0.0, monitored_components = monitored)
@jd-lara
Copy link
Copy Markdown
Member Author

jd-lara commented May 27, 2026

@m-bossart this PR surfaced a bug in PFs reporting code fixed here Sienna-Platform/PowerFlows.jl@3d7a71c

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

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

PSY.add_supplemental_attribute!(
sys,
outaged,
_fixed_outage(; monitored = [monitored]),
Comment thread test/test_connectivity.jl Outdated
@jd-lara jd-lara self-assigned this May 27, 2026
Comment thread src/virtual_modf_calculations.jl Outdated
Comment thread src/virtual_modf_calculations.jl Outdated
Comment thread src/virtual_modf_calculations.jl Outdated
Comment thread src/Ybus.jl
Comment thread src/Ybus.jl
k_j = j_start + offset + idx
r = rows[k_j]
v_j = vals[k_j]
# Snapshot column j up front. Structural inserts into column i shift the CSC backing
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I'm not sure I fully understand the tradeoff for these two implementations.

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.

The old version tracked CSC backing-store offsets assuming inserts into column i shift the storage in a fixed direction this is only true when i < j. Once we added the zero-impedance merges where the survivor index i > removed index j, that bookkeeping dropped a mutual term, producing an asymmetric Ybus. This is where the PowerFlow tests started to fail

@jd-lara jd-lara requested a review from Copilot May 28, 2026 18:19
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

Copilot reviewed 21 out of 21 changed files in this pull request and generated 3 comments.

Comment thread src/IncidenceMatrix.jl
# Radial uses only the user set; no system-derived complement.
user_irreducible =
get_user_irreducible_buses(get_reductions(get_network_reduction_data(A)))
irreducible_positions = Set([A.lookup[2][x] for x in user_irreducible])
Comment on lines 276 to 285
@@ -271,16 +280,24 @@ function VirtualMODF(
tol::Float64 = eps(),
max_cache_size::Int = MAX_CACHE_SIZE_MiB,
network_reductions::Vector{NetworkReduction} = NetworkReduction[],
irreducible_buses::Set{Int} = Set{Int}(),
automatically_register_outages::Bool = true,
kwargs...,
Comment thread src/modf_reduction_consistency.jl Outdated
Comment thread src/AdjacencyMatrix.jl Outdated
Comment thread src/AdjacencyMatrix.jl Outdated
Comment thread src/ReductionContainer.jl
Comment thread src/virtual_modf_calculations.jl Outdated
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

Copilot reviewed 23 out of 23 changed files in this pull request and generated 5 comments.

Comment thread src/reduction_helpers.jl Outdated
Comment on lines +6 to +15
function _arc_conecting_two_areas(arc::PSY.Arc)
from_bus = PSY.get_from(arc)
to_bus = PSY.get_to(arc)
area_from = IS.get_uuid(PSY.get_area(from_bus))
area_to = IS.get_uuid(PSY.get_area(to_bus))
return area_from != area_to
end

_arc_conecting_two_areas(br::PSY.ACTransmission) =
_arc_conecting_two_areas(PSY.get_arc(br))
Comment thread src/reduction_helpers.jl Outdated
Comment on lines +17 to +29
function _arc_conecting_two_areas(br::PSY.ThreeWindingTransformer)
# For the 3WT all the 4 buses are kept if any of the 3 arcs connect two areas
arcs = [
PSY.get_primary_star_arc(br),
PSY.get_secondary_star_arc(br),
PSY.get_tertiary_star_arc(br),
]
for arc in arcs
if _arc_conecting_two_areas(arc)
return true
end
end
return false
Comment thread src/reduction_helpers.jl Outdated
Comment on lines +75 to +76
(PSY.get_available(br) && _arc_conecting_two_areas(br)) || continue
_add_arc_buses!(buses, br)
Comment on lines +76 to +81
# The monitored set is carried ON the outage as device UUIDs.
PSY.add_supplemental_attribute!(
sys,
outaged,
_fixed_outage(; monitored = [monitored]),
)
Comment on lines +194 to +198
PSY.add_supplemental_attribute!(
sys,
outaged,
_fixed_outage(; monitored = [monitored]),
)
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.

all of these are false positive

@jd-lara jd-lara merged commit bc90835 into main May 29, 2026
7 of 8 checks passed
@jd-lara jd-lara deleted the jd/handle_exceptions_modf branch May 29, 2026 15:19
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.

4 participants