-
Notifications
You must be signed in to change notification settings - Fork 0
IOM-side port of PSI#1579 (SCUC branch formulation using MODF) #102
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
acostarelli
wants to merge
6
commits into
main
Choose a base branch
from
ac/scuc
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 2 commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
83e0de2
IOM-side port of PSI#1579 (SCUC branch formulation using MODF)
877325a
Round 2: pull PNM-only helpers from PSI#1579 into IOM
8239dda
Merge remote-tracking branch 'origin/main' into ac/scuc
a323ef8
Address PR #102 review feedback and complete PSI#1579 port
0173cc6
Potential fix for pull request finding
acostarelli b0457e0
address copilot comment
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -28,8 +28,11 @@ Establishes the NetworkModel for a given AC network formulation type. | |
| Adds slack buses to the network modeling. | ||
| - `PTDF_matrix::Union{PNM.PowerNetworkMatrix, Nothing}` = nothing | ||
| PTDF/VirtualPTDF matrix produced by PowerNetworkMatrices (optional). | ||
| - `LODF_matrix::Union{PNM.PowerNetworkMatrix, Nothing}` = nothing | ||
| LODF/VirtualLODF matrix produced by PowerNetworkMatrices (optional). | ||
| - `MODF_matrix::Union{PNM.VirtualMODF, Nothing}` = nothing | ||
| VirtualMODF matrix for security-constrained models (N-k contingencies). | ||
| If `nothing` and the template includes a security-constrained branch | ||
| formulation, the matrix is constructed from the system during | ||
| `instantiate_network_model!` (same pattern as PTDF). | ||
| - `reduce_radial_branches::Bool` = false | ||
| Enable radial branch reduction when building network matrices. | ||
| - `reduce_degree_two_branches::Bool` = false | ||
|
|
@@ -45,7 +48,7 @@ Establishes the NetworkModel for a given AC network formulation type. | |
| # Notes | ||
| - `modeled_branch_types` and `reduced_branch_tracker` are internal fields managed by the model. | ||
| - `subsystem` can be set after construction via `set_subsystem!(model, id)`. | ||
| - PTDF/LODF inputs are validated against the requested reduction flags and may raise | ||
| - PTDF inputs are validated against the requested reduction flags and may raise | ||
| a ConflictingInputsError if they are inconsistent with `reduce_radial_branches` | ||
| or `reduce_degree_two_branches`. | ||
|
acostarelli marked this conversation as resolved.
Outdated
|
||
|
|
||
|
|
@@ -59,7 +62,7 @@ Establishes the NetworkModel for a given AC network formulation type. | |
| mutable struct NetworkModel{T <: AbstractPowerModel} | ||
| use_slacks::Bool | ||
| PTDF_matrix::Union{Nothing, PNM.PowerNetworkMatrix} | ||
| LODF_matrix::Union{Nothing, PNM.PowerNetworkMatrix} | ||
| MODF_matrix::Union{Nothing, PNM.VirtualMODF} | ||
|
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ignoring for now. |
||
| subnetworks::Dict{Int, Set{Int}} | ||
| bus_area_map::Dict{IS.InfrastructureSystemsComponent, Int} | ||
| duals::Vector{DataType} | ||
|
|
@@ -76,7 +79,7 @@ mutable struct NetworkModel{T <: AbstractPowerModel} | |
| ::Type{T}; | ||
| use_slacks = false, | ||
| PTDF_matrix = nothing, | ||
| LODF_matrix = nothing, | ||
| MODF_matrix = nothing, | ||
| reduce_radial_branches = false, | ||
| reduce_degree_two_branches = false, | ||
| subnetworks = Dict{Int, Set{Int}}(), | ||
|
|
@@ -91,7 +94,7 @@ mutable struct NetworkModel{T <: AbstractPowerModel} | |
| new{T}( | ||
| use_slacks, | ||
| PTDF_matrix, | ||
| LODF_matrix, | ||
| MODF_matrix, | ||
| subnetworks, | ||
| Dict{IS.InfrastructureSystemsComponent, Int}(), | ||
| duals, | ||
|
|
@@ -109,7 +112,7 @@ end | |
|
|
||
| get_use_slacks(m::NetworkModel) = m.use_slacks | ||
| get_PTDF_matrix(m::NetworkModel) = m.PTDF_matrix | ||
| get_LODF_matrix(m::NetworkModel) = m.LODF_matrix | ||
| get_MODF_matrix(m::NetworkModel) = m.MODF_matrix | ||
|
Comment on lines
63
to
+110
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Not important |
||
| get_reduce_radial_branches(m::NetworkModel) = m.reduce_radial_branches | ||
| get_network_reduction(m::NetworkModel) = m.network_reduction | ||
| get_duals(m::NetworkModel) = m.duals | ||
|
|
@@ -135,6 +138,85 @@ function add_dual!(model::NetworkModel, dual) | |
| return | ||
| end | ||
|
|
||
| function _build_network_reductions( | ||
| model::NetworkModel, | ||
| irreducible_buses::Vector{Int64}, | ||
| ) | ||
| reductions = PNM.NetworkReduction[] | ||
| if model.reduce_radial_branches | ||
| push!(reductions, PNM.RadialReduction(; irreducible_buses = irreducible_buses)) | ||
| end | ||
| if model.reduce_degree_two_branches | ||
| push!( | ||
| reductions, | ||
| PNM.DegreeTwoReduction(; irreducible_buses = irreducible_buses), | ||
| ) | ||
| end | ||
| return reductions | ||
| end | ||
|
|
||
| # Verify a user-provided MODF Matrix was built with the same network reduction | ||
| # as the active reduction (derived from the PTDF Matrix). Equality of the bus | ||
| # reduction map is the decisive check: it fixes the reduced bus/arc numbering | ||
| # the post-contingency builder uses to index `modf_matrix[arc, outage_spec]`. | ||
| function _validate_provided_modf_reduction!( | ||
| modf::PNM.VirtualMODF, | ||
| network_reduction::PNM.NetworkReductionData, | ||
| ) | ||
| if PNM.get_bus_reduction_map(modf.network_reduction_data) != | ||
| PNM.get_bus_reduction_map(network_reduction) | ||
| throw( | ||
| IS.ConflictingInputsError( | ||
| "The provided MODF Matrix was built with a different network \ | ||
| reduction than the active reduction derived from the PTDF \ | ||
| Matrix. Rebuild the MODF with a consistent network reduction, \ | ||
| or omit it so it is recalculated automatically.", | ||
| ), | ||
| ) | ||
| end | ||
| return | ||
| end | ||
|
|
||
| """ | ||
| True if any branch DeviceModel in `branch_models` uses a formulation that | ||
| consumes `DeviceModel.outages` (per `_formulation_supports_outages`). POM's | ||
| `AbstractSecurityConstrainedStaticBranch` specialization makes that trait | ||
| return `true`; non-SC formulations default to `false`. | ||
| """ | ||
| function _template_has_outage_aware_branch(branch_models::BranchModelContainer) | ||
|
acostarelli marked this conversation as resolved.
|
||
| for v in values(branch_models) | ||
| if _formulation_supports_outages(get_formulation(v)) | ||
| return true | ||
| end | ||
| end | ||
| return false | ||
| end | ||
|
|
||
| """ | ||
| Drop outages from each outage-aware-branch `DeviceModel` whose UUID isn't | ||
| registered on `modf_matrix`; without this they'd `KeyError` downstream in | ||
| post-contingency expression construction. PNM's `_register_outages!` silently | ||
| skips outages it can't convert to a `NetworkModification`, so the IOM-side | ||
| view of `m.outages` can be a strict superset of what's actually usable. | ||
| """ | ||
| function _consolidate_device_model_outages_with_modf!( | ||
| branch_models::BranchModelContainer, | ||
| modf_matrix::PNM.VirtualMODF, | ||
| ) | ||
| registered = PNM.get_registered_contingencies(modf_matrix) | ||
| for m in values(branch_models) | ||
| _formulation_supports_outages(get_formulation(m)) || continue | ||
| for uuid in setdiff(keys(m.outages), keys(registered)) | ||
| @warn "Outage $(uuid) (DeviceModel{$(get_component_type(m)), \ | ||
| $(get_formulation(m))}) is not registered on the MODF \ | ||
| matrix and will not contribute any post-contingency \ | ||
| constraints." _group = LOG_GROUP_MODELS_VALIDATION | ||
| delete!(m.outages, uuid) | ||
| end | ||
| end | ||
| return | ||
| end | ||
|
|
||
| # Default implementations for network model compatibility checks | ||
| # These can be extended in PowerOperationsModels for specific network formulations | ||
| requires_all_branch_models(::Type{<:AbstractPowerModel}) = true | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.