Show balance slacks owned by buses and areas (#94) - #7
Open
PabloBotin wants to merge 1 commit into
Open
Conversation
PabloBotin
force-pushed
the
feature/migrate-to-poweranalytics-new-api
branch
2 times, most recently
from
July 29, 2026 22:34
b89dc10 to
39be6fe
Compare
Slack categories were read through `PA.Metrics.calc_system_slack_up` and its down counterpart, which resolve to `PowerAnalytics.read_system_result`. That function hardcodes `make_key(entry, PSY.System)` and asserts the result has a single data column. PowerSimulations attaches balance slacks to four different component types depending on the network formulation: `System` for copper-plate and PTDF, `Area` for the area-balance models, and `ACBus` for the PowerModels formulations (with `"P"`/`"Q"` meta in the AC case). Only the first was ever found, so node- and area-level slacks silently never appeared — and would have tripped the single-column assertion had they been read at all. Discover the slack keys present in the results by entry type instead, regardless of which component owns them, and sum across the per-bus or per-area columns into one series per direction. The `System` case has a single column, so its values are unchanged. Only the active-power `"P"` slack is included for AC formulations; the fuel stack plots active power, so reactive slack does not belong on it. This works around the limitation rather than fixing it: `read_system_result` is still `System`-only for every other PowerAnalytics consumer.
PabloBotin
force-pushed
the
issue-94-bus-slacks
branch
from
July 29, 2026 22:54
5d16dc1 to
00c1cf5
Compare
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Closes Sienna-Platform#94.
Root cause
Slack categories were read via
PA.Metrics.calc_system_slack_up/ its down counterpart, which resolve toPowerAnalytics.read_system_result(input_utils.jl:190). Its first line is:followed by
@assert size(res, 2) == 2— one time column plus exactly one data column.But PowerSimulations attaches balance slacks to four different component types depending on the network formulation (
network_slack_variables.jl:115-182):CopperPlatePowerModel,PTDFPowerModelSystemSystemBalanceSlackUp__SystemAreaBalancePowerModel,AreaPTDFPowerModelArea…__AreaPM.AbstractActivePowerModel(DC, NFA)ACBus…__ACBusPM.AbstractPowerModel(AC)ACBus+"P"/"Q"meta…__ACBus__P/__QOnly the first is ever found. The other three are invisible — and being multi-column, they would have tripped the single-column assertion even if the key had matched. That is exactly the reported symptom: "the slacks at the node level don't appear."
Confirmed by solving:
DCPPowerModelwithuse_slacks = trueproducesSystemBalanceSlackUp__ACBus, andPA.compute(calc_system_slack_up, results)raises on it.The fix
Discover the slack keys actually present in the results by entry type, regardless of owning component, and sum across the per-bus/per-area columns into one series per direction. The
Systemcase has a single column, so summing is a no-op and its values are unchanged.Only the active-power
"P"slack is included for AC formulations — the fuel stack plots active power in MW, so reactive slack does not belong on it.This works around the limitation rather than fixing it.
read_system_resultremainsSystem-only for every other PowerAnalytics consumer; the proper fix is an upstream PA metric that discovers the owner type and aggregates. Worth filing.Verification
Full suite 101/101, zero Error log events; formatter clean.
The regression test fails on the parent commit — stashing only
src/call_plots.jland re-running gives52 passed, 2 failed, 3 errored, the failures being the two missing slack categories and the errors beingonly(...)on absent traces. The two "unchanged behavior" testsets pass on the parent, as intended.Independently exercised against real solves:
DCPPowerModel+ slacks → keys areACBus-ownedPA.calc_system_slack_upon those resultsplot_fuelshows Unserved Energy / Over GenerationCopperPlatetrace ==PA.computeexactlyValues were compared in native MW via
auto_units = false; the auto-scaled form is exactlyref/1000.Known limitations
Areacase is not covered by a test.c_sys5_uchas noAreaorAreaInterchangecomponents, soAreaBalancePowerModelfails to build (ConflictingInputsError). Hand-building that fixture would be fragile, and theACBustest already exercises the identical code path — non-Systemowner, many columns, summed. No distinct branch is left untested.key.metais accessed as a field. Noget_metaaccessor exists in InfrastructureSystems or PowerSimulations (both grepped). The alternative — string-matchingencode_key_as_string— is worse. An upstream accessor would be the clean fix.max_active_power×3 on adeepcopy; with the unmodified system the nodal slacks solve to all-zero and the sum assertion would be vacuous.