Jd/pnm pf update#1619
Conversation
There was a problem hiding this comment.
Pull request overview
This PR updates PowerNetworkMatrices/PowerFlows compatibility and adapts network reduction construction to the PNM 0.22 API, where irreducible buses are supplied to matrix constructors rather than reduction specs.
Changes:
- Updates dependency bounds for
PowerFlowsandPowerNetworkMatrices. - Refactors PTDF/MODF construction and reconciliation into helper functions.
- Threads
irreducible_busesthroughYbus,VirtualPTDF, andVirtualMODFconstructors.
Reviewed changes
Copilot reviewed 1 out of 2 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
Project.toml |
Bumps PowerFlows and PowerNetworkMatrices compatibility versions. |
src/core/network_model.jl |
Updates matrix reduction construction and PTDF/MODF consistency handling for PNM 0.22. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
|
Performance Results
|
…n model construction DecisionModel deepcopied the caller's template, which bit-copied the raw libklu factorization Ptr held by a user-provided VirtualPTDF/VirtualMODF. The copy aliased the original's handle while the cleanup finalizer stayed attached only to the original; when GC reclaimed the original template during build!, the finalizer freed the handle out from under the copy. The next klu_solve then read freed memory (Numeric.n == 0) -> KLU_INVALID -> SIGSEGV. Linux crashed deterministically; macOS survived on heap-layout luck. Exposed by PNM 0.22, whose Virtual matrices carry the KLU factorization through a finalizer-guarded Ptr. Add _copy_template_for_build: a deepcopy that shares PTDF_matrix/MODF_matrix by reference (by seeding the deepcopy memo) so the factorization handle is never copied, while still deep-copying the device/branch/service models and network reduction so the model can mutate them independently. Use it in DecisionModel (replacing the unsafe deepcopy) and EmulationModel (which previously mutated the caller's template in place — the same contract violation). https://claude.ai/code/session_01KNFhS4Z85haH3HZFT8VJC4
A failure on one platform (currently macOS, which runs Julia x64 under Rosetta on the arm64 runner) was cancelling the Linux and Windows jobs before they could report. Disabling fail-fast gives a clean per-platform verdict so the Linux/KLU result is visible while the macOS failure is investigated separately. https://claude.ai/code/session_01KNFhS4Z85haH3HZFT8VJC4
…Simulations.jl into jd/pnm_pf_update
| # Both matrices must share one reduction so the nodal-balance rows and the | ||
| # post-contingency MODF columns line up; reconcile (and fail fast) before | ||
| # outage consolidation populates the branch maps. | ||
| _ensure_ptdf_modf_consistent!(model, sys) | ||
| _consolidate_device_model_outages_with_modf!(branch_models, get_MODF_matrix(model)) |
There was a problem hiding this comment.
This is correct. I will push a different fix for this.
| for (device_type, devices) in contributing_devices_map | ||
| device_model = get(devices_template, Symbol(device_type), nothing) | ||
| device_model = get(devices_template, nameof(device_type), nothing) | ||
| isnothing(device_model) && continue |
| "An interface is specified with only part of a double-circuit that has been reduced. | ||
| Branches: $(branch_names[in_interface]) are in the interface and branches: $(branch_names[.!in_interface]) are not. | ||
| Modify the data to include all of or none of the parallel segements.", | ||
| ), |
| name: Julia ${{ matrix.julia-version }} - ${{ matrix.os }} | ||
| runs-on: ${{ matrix.os }} | ||
| strategy: | ||
| fail-fast: false |
There was a problem hiding this comment.
Just confirming, is this meant to be committed or just for debugging?
There was a problem hiding this comment.
Yeah, I want to keep it because if it fails in one OS throws all the CI out
| # Both matrices must share one reduction so the nodal-balance rows and the | ||
| # post-contingency MODF columns line up; reconcile (and fail fast) before | ||
| # outage consolidation populates the branch maps. | ||
| _ensure_ptdf_modf_consistent!(model, sys) | ||
| _consolidate_device_model_outages_with_modf!(branch_models, get_MODF_matrix(model)) |
There was a problem hiding this comment.
This is correct. I will push a different fix for this.
| function _set_subnetworks_from_ptdf!( | ||
| model::NetworkModel{<:AbstractPTDFModel}, | ||
| sys::PSY.System, | ||
| ) | ||
| model.subnetworks = _make_subnetworks_from_subnetwork_axes(model.PTDF_matrix) | ||
| if length(model.subnetworks) > 1 | ||
| @debug "System Contains Multiple Subnetworks. Assigning buses to subnetworks." | ||
| _assign_subnetworks_to_buses(model, sys) | ||
| end |
There was a problem hiding this comment.
I think this is right, we should only overwrite the subnetworks if the user input is empty.
There was a problem hiding this comment.
users should never provide subnetworks here. It always needs to be derived from the data
This PR updates the logic and the versions for PNM and PFs