Repository navigation
Parse by value type and keep the ExaModelsPower bridge trim-safe - #184
Conversation
ExaModelsPower compiles its case reader into a library with
`juliac --trim=safe`, which refuses any call it cannot resolve statically.
PowerIO 0.9 had a typed path for that; the 0.11 rewrite dropped it, and a
trimmed build of `parse` plus `to_powerdata` failed verification with 90
errors.
- `parse(V, source)` (path, IO, bytes) checks the value's structural type
name and wraps it as a concrete `PioModule{V}`, refusing a source that
holds another kind of value with an `ArgumentError` that names it.
- `to_powerdata(net, T)` and `to_ac_power_data(net, T)` take the element
type positionally; the keyword forms forward to them.
- Handle locking reads `lib` and `operation_lock` through typed accessors
and collects handles by dispatch rather than `isa` tests and `unique!`
over the abstract `Handle` type.
- The bridge reads element tables through `_table(net, Val(name))`, whose
row type is static, instead of the large `getproperty`.
`test/trim` builds and runs a trimmed app that parses case14 and calls the
bridge; CI runs it on the `1` leg.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…rap path
- parse(V, source) returns a V, as parse(T, str) does in Base;
parse(PioModule{V}, source) returns the module and parse(PioModule, source)
is the untyped form. deserialize takes the same forms.
- A family V (TimeSeries, CalculationInstance, a Union) is resolved at run time
and checked; a parameter that names no PowerIO value type is refused; a
mismatch names the source and releases the module at once.
- Calculation instances and solutions borrow through static entry points, so
parse(AcScucInstance, path) compiles under --trim=safe. One typed
_wrap_value serves parse, deserialize, the to_*_instance constructions
(now PioModule{I}), and time series and scenario set entries.
- to_powerdata and to_ac_power_data take T positionally for modules and paths;
LoadSeries{T}(net, ...) is the inferable constructor. The path helpers use
the typed parse.
- Locking a single handle no longer allocates; base_mva and the value type
name are each read in one place.
- The trimmed app also parses a GO Challenge 3 instance; test/trim pins
JuliaC 0.3 and Julia 1.12.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
frederikgeth
left a comment
There was a problem hiding this comment.
Approved reviewed head b3eeb09a472461b532fce6eac70a8eab940d279a against current PowerIO.jl main 1a941f0893277a7e6f7d64803e06e1fd24e152a5. No blocking findings after reviewing typed parse/deserialize dispatch, static value and calculation wrapping, owner-rooted handle lifetimes, deduplication/lock ordering, keyword forwarding, typed table access and the positional ExaModelsPower bridge. Existing untyped forms and ABI 7 remain compatible; the typed overloads are additive.
Local full Pkg.test() against the published 0.11.6 macOS aarch64 C library passed on Julia 1.13.3 (2,296 passes, one existing platform skip) and Julia 1.10.12 (1,976 passes, one existing skip), with POWERIO_REQUIRE_LIBRARY=1 and four Julia threads. Eighteen supplemental assertions passed for inferred typed IO/byte-view parsing, typed IR IO/bytes, values surviving explicit module/collection handle release and GC, typed time-series/scenario entries and solution families, mismatch errors, mixed-root deterministic handle deduplication, and concrete empty generator/branch/arc/storage bridge tables.
Exact-head CI and Benchmarks passed. Hosted CI actually built the native main library, checked raw-layer regeneration, ran both Julia version legs and the documentation build, and executed the trimmed-app compile/run gate on the current Julia leg. Its output was trimmed app: 14 5 20 40 0 100.0 2. Trim coverage is verified from those hosted logs; a fresh local trim build is not claimed because JuliaC 0.3 is absent from the offline package cache.
This is an approved paired-0.11.7 candidate for the ExaModelsPower dependency. Final cross-repository integration, release preparation and maintainer approval remain separate gates. No code was changed or pushed and nothing was merged, registered, tagged or released.
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>
ExaModelsPower compiles its case reader into a shared library with
juliac --trim=safe(compile_all), and the compiled library parses cases at run time. 0.9 had a trim-safe typed path for this (309e05e). The 0.11 rewrite dropped it: a trimmed ExaModelsPower build over 0.11.6 fails verification with 90 errors.The first-level failures were:
parsechoosing the value type at run time;to_powerdata's keywordTarriving as aDataType;@with_handlesreadingoperation_lockthrough the abstractHandle;unique!over aVector{Handle};Symbollooked up in aDict.Typed parse
As
parse(T, str)does in Base, naming the value type returns that value:IO, or bytes.V, both typed forms are inferred and compile under--trim=safe. The value keeps its module's data alive, asparse(path).valuealready did.Vmay be a family such asTimeSeries,CalculationInstance, or aUnion. The value type is then resolved at run time and checked againstV.PioModule{V}takes a concreteV, since a module type names one value type.ArgumentErrors:TimeSeries{Int}, is refused plainly.deserializetakes the same forms for PowerIO IR.Typed results elsewhere
_wrap_value(V, …)serves parse, deserialize, theto_*_instanceconstructions, and time series and scenario set entries.to_*_instanceconstructions now return a concretePioModule{I}.to_powerdata(x, T)andto_ac_power_data(x, T)take the element type positionally for a network, a module, or a path, and infer a concrete result, empty tables included. The keyword forms forward to them.LoadSeries{T}(net, …)is the inferable form of eachLoadSeriesconstructor.ybus.jlandexa.jluseparse(BalancedNetwork, path; format)instead of repeating an untyped parse and anisacheck.Handles and tables
libandoperation_lockare read through typed accessors.objectidsort instead of withunique!. Locking a single handle allocates nothing;net.base_mvawent from 80 bytes to 0._table(net, Val(name)), whichgetpropertyalso uses, instead of relying on constant propagation.base_mvaand the value type name are each read in one place.Trim check
test/trimbuilds and runs a trimmed app that uses:parse(BalancedNetwork, …)with the positional bridge, on case14;parse(PioModule{AcScucInstance}, …)on a GO Challenge 3 instance.CI runs it on the
1leg. The project pins JuliaC 0.3 and Julia 1.12, since its Manifest isn't committed.Verification
Pkg.test(): on Julia 1.13.1, 2,296 passed and 1 broken; on 1.10, 1,976 passed and 1 broken. The broken one is the existing@test_skipin the C ABI coverage test.julia --project=test/trim test/trim/build.jl(Julia 1.13.1, macOS): trim verification passes and the app prints14 5 20 40 0 100.0 2.parse(BalancedNetwork, …)andto_powerdata(net, T). With them,compile_all(ExaModelsPower)verifies and links all six models, and each compiled model'sobjandconsmatch the in-Julia model exactly.This rides the next paired release (0.11.7). ExaModelsPower #68 depends on it.
🤖 Generated with Claude Code