Skip to content

Read cases through PowerIO (replaces #60) - #68

Closed
samtalki wants to merge 4 commits into
madsuite-org:mainfrom
samtalki:powerio-0.11-cases
Closed

samtalki wants to merge 4 commits into
madsuite-org:mainfrom
samtalki:powerio-0.11-cases

Conversation

@samtalki

@samtalki samtalki commented Oct 26, 2026 •

Copy link
Copy Markdown
Contributor

Cases are now read through PowerIO.jl instead of ExaPowerIO. Any single-phase network PowerIO reads becomes an OPF case: MATPOWER, PSS/E RAW/RAWX, PowerModels JSON, pandapower, PowerWorld, CGMES, XIIDM, and more. ExaPowerIO is no longer a dependency. This replaces #60, which targeted PowerIO 0.9; almost none of the API it used exists in 0.11. Issue #52 is fixed here.

How a case is read

  • Lookup: a path, or a bare PGLib-OPF name (pglib_opf_*.m, also api/… and sad/…). Names resolve in the same lazy PGLib-OPF v23.07 artifact ExaPowerIO used, now declared in this package's Artifacts.toml. It has the same tree hash, so existing depots reuse the download. A missing path that isn't a PGLib name is an ArgumentError and no longer triggers the download.

  • Pre-parsed networks: anywhere a file name was accepted, a network already parsed with PowerIO works too: PowerIO.parse(BalancedNetwork, path; format), or its module PowerIO.parse(PioModule{BalancedNetwork}, path), possibly edited with PowerIO.apply_updates!.

  • Parsing: parse_ac_power_data calls PowerIO.to_powerdata(net, T), then keeps what is in service, in file order:

    • isolated buses and out-of-service generators, branches and storage are dropped;
    • the rest are renumbered densely;
    • rateA = 0 (or a non-finite rating) becomes the limit implied by the voltage and angle bounds, as ExaPowerIO 0.3.2 does.

    The rows are named isbits NamedTuple types with ExaPowerIO's field names and order, so no model body changed. Empty tables stay concrete for GPU convert_array.

  • Parity: against ExaPowerIO 0.3.4, every field of every table matches to 1e-12 on all 66 top-level PGLib-OPF v23.07 cases and the 5 fixtures in data/. The exceptions are va, now in radians, and the reference-bus choice described below.

Ahead-of-time compilation

compile_all runs the case reader inside a juliac --trim=safe library. PowerIO 0.11.6 fails trim verification (90 errors: a value type picked at run time, untyped handle locks, a keyword element type). eigenergy/PowerIO.jl#184 adds:

  • a typed parse(BalancedNetwork, path), which returns the network as parse(T, str) does in Base;
  • a positional to_powerdata(net, T);
  • a trimmed-app CI check.

With it, the :acp library verifies and links, and its obj/cons match the in-Julia model exactly on case14 (by path) and on case30 and api/case14 (by PGLib name). This PR adds an aot CI slice so a regression shows up. A compiled library can't download the PGLib artifact; that was already true with ExaPowerIO, and test_aot now resolves the name in Julia first.

PowerIO 0.11.7 and later are registered, so the branch pin is gone; compat is PowerIO = "0.11.7, 0.12". With PowerIO 0.12.1, the aot slice passes on Julia 1.13.2 (31/31); on Julia 1.12.7 trim verification fails (also with PowerIO 0.11.12), mostly on Pkg REPLExt code reached through LazyArtifacts.

Behavior changes (0.5.0)

  • More inputs accepted: any balanced PowerIO format, and pre-parsed networks.
  • Storage: out-of-service storage is dropped. storage_bus is the model position of the bus; it was the raw MATPOWER bus number, which indexed the wrong bus whenever numbering wasn't 1..n. Storage p_loss/q_loss are per unit, as in ExaPowerIO 0.3.4.
  • Inconsistent shunt admittance scaling in multiperiod OPF methods #52: a load curve scales pd/qd only; bus shunts (gs, bs) keep their value. The Pd/Qd matrix path already did this. Nothing in the test fixtures has a shunt, so the hard-coded objectives are unchanged.
  • New errors:
    • an in-service generator, branch or storage unit at an isolated bus raises ArgumentError; before, it silently got bus index 0;
    • a piecewise-linear generator cost (MATPOWER model 1) raises ArgumentError; before, its breakpoints were read as polynomial coefficients.
  • Multi-period shapes: a curve shorter than N, Pd/Qd with the wrong number of rows, mismatched Pd/Qd, or too few periods raise DimensionMismatch instead of a BoundsError or an @assert.
  • Reference bus: when a case's reference bus has no in-service generator, the new reference is the bus of the generator with the largest Pmax. ExaPowerIO compared column 10, which is PMIN. This changes the reference bus of 5 PGLib cases (case1951_rte and case6468/6470/6495/6515_rte) and nothing else.
  • va0 is in radians. It was degrees, so a warm start start = (va = d -> d.va0,) was off by 180/π. The default starts don't use it.
  • MATPOWER writer: it refuses a solution whose row counts don't match the case file (DimensionMismatch), and a non-MATPOWER case file (ArgumentError). Before, it could write values into the wrong rows.
  • Native library: PowerIO's library is a lazy artifact fetched on the first parse. The precompile workload fetches it, or skips itself offline instead of failing.

Tests

  • New test/parser_tests.jl (the nothing slice):
    • concrete inference of opf_args (path and pre-parsed), mpopf_args_default and positional mpopf_args; isbits rows, empty tables included;
    • an edited case14: an isolated bus, out-of-service generator and branch, bus numbers offset by 1000 with the rows reversed, and storage in and out of service at a non-contiguous bus, with every index checked and a solve;
    • each refusal;
    • rateA = 0 against PowerModels' calc_thermal_limits!;
    • pre-parsed and updated networks;
    • round trips: PowerModels JSON (same tables and objective) and PSS/E RAW (same network, solves);
    • case lookup;
    • Inconsistent shunt admittance scaling in multiperiod OPF methods #52, and the multi-period shape errors.
  • Reference solves: PGLib case5, case14, case30 and case57, by name, against PowerModels/Ipopt (rtol = 1e-6). DC OPF case3/5/14 against PowerModels' DCPPowerModel, through the previously unused test_dcopf_case.
  • Writer: row-count and non-MATPOWER refusals.
  • aot CI slice: test_aot (the EMP_TEST_AOT opt-in still works), plus a case loaded by path in the rectangular form.

Verification (local, Julia 1.13.1, macOS)

  • EMP_TEST_SELECTION=nothing: 808 passed. cpu: 450 passed. aot: 19 passed, with all six models compiled under --trim=safe.
  • The cuda slice needs the self-hosted runners.
  • The goc3 slice is untouched here. The GOC3 path moves to PowerIO in a separate PR.

Rebased onto main (0.4.8)

  • Conflicts resolved in Project.toml, src/opf.jl, src/ExaModelsPower.jl, test/runtests.jl; the parser tests run next to the violations, case-start and zero-compile tests.
  • case_start (from Start from the case's operating point: start = :case, case_start, compiled start writer #72) converted va0 from degrees; with va0 now in radians it is used as is.
  • Local results with PowerIO 0.12.1: nothing 868/868 (Julia 1.12.7); cpu 458/459, the one failure being the POCL zero-compile check for opf_violations that also fails on main; aot 31/31 (Julia 1.13.2). cuda, goc3 and docs were not run locally.

🤖 Generated with Claude Code

samtalki and others added 4 commits November 16, 2026 16:54
Every case is parsed by PowerIO instead of ExaPowerIO, so any single-phase
network PowerIO reads (MATPOWER, PSS/E, PowerModels JSON, pandapower,
CGMES, ...) becomes an OPF case, and a network already parsed with PowerIO
can be passed wherever a file name was. ExaPowerIO is no longer a
dependency; the PGLib-OPF artifact it provided is declared here, with the
same tree hash.

`parse_ac_power_data` reads `PowerIO.to_powerdata(net, T)` and keeps what
is in service, in file order, as named isbits row types with ExaPowerIO's
field names, so no model body changes. It matches ExaPowerIO 0.3.4 field
for field on every PGLib-OPF case, except that `va` is in radians, storage
is remapped to model bus positions, and a lost reference bus moves to the
largest-Pmax generator (ExaPowerIO compared PMIN).

A load curve no longer scales bus shunts (madsuite-org#52). The MATPOWER writer
refuses a solution whose row counts do not match the case file.

The compiled library parses with `parse(BalancedNetwork, path)` and the
positional `to_powerdata(net, T)`, which pass `juliac --trim=safe` from
eigenergy/PowerIO.jl#184; PowerIO is pinned to that branch until 0.11.7.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
parser_tests.jl covers inference of the arguments a compiled library
builds, in-service selection and renumbering on an edited case14, each
refusal, the implied thermal limit against PowerModels, pre-parsed and
updated networks, PowerModels JSON and PSS/E round trips, case lookup,
and the multi-period load contract. PGLib cases by name are solved against
PowerModels, and DC OPF against DCPPowerModel through the unused
`test_dcopf_case`.

An `aot` slice runs `test_aot`, now compiling into a temporary directory,
with a case loaded by path, so a regression in the trimmed case reader
fails CI.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
PowerIO.jl #184 now returns the value from parse(BalancedNetwork, path), as
parse(T, str) does in Base, and the module from parse(PioModule{V}, path). The
case reader drops its `.value`; the tests that emit or apply updates ask for
the module.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…s VA in radians

The parse now gives va0 in radians, so case_start must not convert it again.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@sshin23
sshin23 marked this pull request as ready for review November 17, 2026 00:26
@sshin23 sshin23 added the claude:pr Request an unattended Claude review of this PR label Nov 17, 2026
@sshin23

sshin23 commented Nov 17, 2026

Copy link
Copy Markdown
Member

Continued in #76, from a branch in this repository so the Claude review workflow can run. It carries these commits rebased onto main, plus the follow-ups described there.

@sshin23 sshin23 closed this Nov 17, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

claude:pr Request an unattended Claude review of this PR

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants