Skip to content

Units migration: adopt unitful PowerSystems getter API#308

Open
luke-kiernan wants to merge 6 commits into
psy6from
lk/units-table-driven-v2
Open

Units migration: adopt unitful PowerSystems getter API#308
luke-kiernan wants to merge 6 commits into
psy6from
lk/units-table-driven-v2

Conversation

@luke-kiernan
Copy link
Copy Markdown
Collaborator

@luke-kiernan luke-kiernan commented May 27, 2026

Thanks for opening a PR to PowerNetworkMatrices.jl, please take note of the following when making a PR:

Check the contributor guidelines

Summary

Updates PowerNetworkMatrices for the units-aware InfrastructureSystems / PowerSystems API (part of the ongoing units migration). PSY field getters now require an explicit unit system instead of relying on a mutable global unit setting.

Changes

  • Matrix construction (Ybus, BA/ABA, branch reductions): impedance/admittance/shunt getters (get_r, get_x, get_b, get_g, get_primary_shunt, the 3W winding variants, get_impedance_active/reactive_power) now pass SU (system base) — the basis the matrices are built in.
  • Equivalent ratings (BranchesParallel/BranchesSeries/ThreeWindingTransformerWinding): use DU (device base). These are metadata aggregations that must work on branches not yet attached to a system, and match the raw stored ratings.
  • get_series_susceptance: threaded units::IS.AbstractUnitSystem through the PNM wrappers (PSY's accessor now takes it), terminating at SU where the system-base matrices are assembled.
  • [sources]: pinned IS/PSY (and test deps PSB/PFP) to their units-aware branches so CI can resolve the as-yet-unreleased upstream changes.
  • Merge sync: merged main into this branch and resolved conflicts in src/BranchesParallel.jl and src/Ybus.jl, preserving the units-aware getter changes while incorporating upstream updates.

Testing

Attempted julia --project=. test/runtests.jl after merge conflict resolution, but dependency resolution is currently blocked by a missing upstream revision (lk/units-fold-psu) in PowerSystems.jl in this environment.

Dependencies

Depends on the units branches of InfrastructureSystems, PowerSystems, PowerSystemCaseBuilder, and a PowerFlowFileParser fix (separate PR). CI will be red until those merge/release; the [sources] pins let it resolve against the branches meanwhile.

🤖 Generated with Claude Code

luke-kiernan and others added 2 commits March 30, 2026 15:50
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Replace the placeholder `Float64` getter target with explicit unit systems:
`SU` (system base) for impedances, admittances, and shunts used in matrix
construction, and `DU` (device base) for equivalent ratings, which must work
on detached branches. Thread `units::IS.AbstractUnitSystem` through the
`get_series_susceptance` accessors (PSY now requires it).

Pin InfrastructureSystems/PowerSystems (and test deps PowerSystemCaseBuilder/
PowerFlowFileParser) to their units-aware branches via `[sources]` so CI can
resolve the as-yet-unreleased upstream changes.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@jd-lara
Copy link
Copy Markdown
Member

jd-lara commented May 27, 2026

Don't we need PSY6 for this work to make sense?

@luke-kiernan
Copy link
Copy Markdown
Collaborator Author

Don't we need PSY6 for this work to make sense?

Yes. I didn't see a PSY6 branch on this repo so I opened the PR into main. Is there a different branch I should be merging into?

@jd-lara
Copy link
Copy Markdown
Member

jd-lara commented May 29, 2026

@copilot merge main onto this branch and correct the conflicts

Copy link
Copy Markdown
Contributor

Copilot AI commented May 29, 2026

@copilot merge main onto this branch and correct the conflicts

Merged main into this branch and resolved conflicts in src/BranchesParallel.jl and src/Ybus.jl in commit 09e5636.

Copilot AI requested a review from jd-lara May 29, 2026 15:28
@luke-kiernan luke-kiernan changed the base branch from main to psy6 May 29, 2026 16:05
Re-point [sources] from the units feature branches to the next-release
branches now that they are merged upstream:
  - InfrastructureSystems: lk/units-domain-agnostic-is4 -> IS4
  - PowerSystems:          lk/units-fold-psu            -> psy6
  - PowerSystemCaseBuilder lk/units-table-driven        -> psy6
  - PowerFlowFileParser:   fork lk/units-fixes          -> NREL-Sienna main
    (the fix is merged to main but predates the only release, v0.1.0)

Fix two breakages surfaced by the bump to psy6:
  - virtual_lodf_calculations.jl: pass PSY.SU to get_series_susceptance
    in _extract_branch_susceptances_by_arc (missed call sites; the
    accessor now requires an explicit unit system).
  - test_arc_types_and_reductions.jl: attach the MixedBranchesParallel
    test's Line/TapTransformer to a System so the system-base getters in
    ybus_branch_entries resolve (psy6 now throws on detached components).
  - test_connectivity.jl: relax the VirtualPTDF/VirtualLODF cross-method
    equality checks from == to isapprox; the on-demand paths now differ
    by ULPs on the IS4/psy6 stack.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented May 29, 2026

Performance Results

Precompile Time

Main This Branch Delta
2.137 s 2.194 s +2.7%

Execution Time

Test Main This Branch Delta
matpower_ACTIVSg2000_sys-Build PTDF FAILED N/A N/A
matpower_ACTIVSg2000_sys-Build Ybus FAILED N/A N/A
matpower_ACTIVSg2000_sys-Build LODF FAILED N/A N/A
matpower_ACTIVSg2000_sys-Build VirtualMODF FAILED N/A N/A
matpower_ACTIVSg2000_sys-Radial network reduction FAILED N/A N/A
matpower_ACTIVSg2000_sys-Degree two network reduction FAILED N/A N/A
Base_Eastern_Interconnect_515GW-Build Ybus FAILED N/A N/A
Base_Eastern_Interconnect_515GW-Radial network reduction FAILED N/A N/A
Base_Eastern_Interconnect_515GW-Degree two network reduction FAILED N/A N/A
matpower_ACTIVSg2000_sys-Build PTDF First N/A 1.785 s N/A
matpower_ACTIVSg2000_sys-Build PTDF Second N/A 84.0 ms N/A
matpower_ACTIVSg2000_sys-Build Ybus First N/A 6.0 ms N/A
matpower_ACTIVSg2000_sys-Build Ybus Second N/A 5.4 ms N/A
matpower_ACTIVSg2000_sys-Build LODF First N/A 507.4 ms N/A
matpower_ACTIVSg2000_sys-Build LODF Second N/A 125.2 ms N/A
matpower_ACTIVSg2000_sys-Build VirtualMODF First N/A 3.518 s N/A
matpower_ACTIVSg2000_sys-Build VirtualMODF Second N/A 1.207 s N/A
matpower_ACTIVSg2000_sys-VirtualMODF Query 10 rows N/A 506.2 ms N/A
matpower_ACTIVSg2000_sys-Radial network reduction First N/A 541.7 ms N/A
matpower_ACTIVSg2000_sys-Radial network reduction Second N/A 0.7 ms N/A
matpower_ACTIVSg2000_sys-Degree two network reduction First N/A 1.84 s N/A
matpower_ACTIVSg2000_sys-Degree two network reduction Second N/A 1.0 ms N/A
Base_Eastern_Interconnect_515GW-Build Ybus First N/A 482.1 ms N/A
Base_Eastern_Interconnect_515GW-Build Ybus Second N/A 291.7 ms N/A
Base_Eastern_Interconnect_515GW-Radial network reduction First N/A 46.2 ms N/A
Base_Eastern_Interconnect_515GW-Radial network reduction Second N/A 42.1 ms N/A
Base_Eastern_Interconnect_515GW-Degree two network reduction First N/A 370.5 ms N/A
Base_Eastern_Interconnect_515GW-Degree two network reduction Second N/A 43.2 ms N/A

luke-kiernan and others added 2 commits May 29, 2026 14:30
Finish threading the unit-aware PSY getter API through the subsystems the
original migration missed, surfaced by the bump to the psy6/IS4 release
branches:

- connectivity_checks.jl: reimplement find_connected_components with PNM's
  own union-find instead of PowerModels.calc_connected_components, which
  PowerSystems no longer re-exports (PowerModels dependency dropped).
- common.jl, network_modification.jl: pass PSY.SU to get_series_susceptance
  and get_impedance_active/reactive_power in the contingency/MODF delta
  computations (all operate on system-base, system-attached components).
- Ybus.jl, BranchesSeries.jl: the synthetic ward-equivalent
  GenericArcImpedance is detached by design and stores system-base impedance;
  read it back with device base (DU, identity) since system base would need a
  system base power a detached component cannot resolve.
- BranchesParallel.jl: document why get_impedance_averaged_rating uses system
  base (consistent weighting across the group; requires attached branches).

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
- test_connectivity.jl: compare the dense PTDF/LODF cross-method checks with
  isapprox + an absolute tolerance; the dense and on-demand paths drift by a
  few ULPs run-to-run on the IS4/psy6 stack and many entries are physically
  zero (relative tolerance is meaningless there).
- test_equivalent_getters.jl: attach the parallel branches to the system
  (skip_validation) so the system-base susceptance weighting can resolve.
- test_modf_lodf_reductions.jl: clone transformers via deepcopy + fresh
  identity instead of re-reading each field, and pass PSY.SU to
  get_series_susceptance on attached branches.
- test_ward_reduction.jl: read the detached ward-equivalent's susceptance with
  device base (DU).
- test_ybus_reductions.jl: setters now require unitful values (val * PSY.SU).

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
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.

3 participants