Expand description
powerio-matrix: sparse matrices and graph views for power system case files,
built on powerio (re-exported, so one use powerio_matrix::... pulls in
both layers).
Signed incidence A, weighted Laplacian L = A diag(b) Aᵀ and its
reference-grounded form, B’/B’’/Y_bus, PTDF/LODF, adjacency, the LACPF block,
and the DC OPF instance bundle, plus a petgraph view. The builders take the
dense-indexed IndexedNetwork view of a Network.
use powerio_matrix::{parse_file, IndexedNetwork, build_bprime, BuildOptions};
let net = parse_file(case, None)?.network; // re-exported from powerio
let g = IndexedNetwork::new(&net); // dense [0, n) analysis view
let bprime = build_bprime(&g, &BuildOptions::default())?;
assert_eq!(bprime.rows(), g.n()); // B' is n×n§Conventions
B’ and the Laplacians use the positive (M-matrix) form: off-diagonal < 0,
diagonal > 0, diag = Σ|off-diag|. Bus ids are 1-based on the
model; IndexedNetwork maps them to a dense [0, n). tap == 0 means
tap = 1; B’ ignores taps and shifts, B’’ keeps taps and zeros shifts,
Y_bus keeps both. Branch charging susceptance is stored per unit. DC OPF is
bus indexed
(p_g ∈ ℝⁿ), default susceptance b = 1/x, with DcConvention::Matpower
the 1/(x·τ) plus phase-shift variant. The full reference across every
matrix is in
docs/matrices.md.
Re-exports§
pub use matrix::BuildOptions;pub use matrix::BusCosts;pub use matrix::DcConvention;pub use matrix::GenCosts;pub use matrix::GroundedIndexMap;pub use matrix::IncidenceParts;pub use matrix::MatrixStats;pub use matrix::OpfInstance;pub use matrix::Scheme;pub use matrix::Units;pub use matrix::build_adjacency;pub use matrix::build_bdoubleprime;pub use matrix::build_bprime;pub use matrix::build_flow_map;pub use matrix::build_incidence;pub use matrix::build_lacpf;pub use matrix::build_lodf;pub use matrix::build_opf_instance;pub use matrix::build_ptdf;pub use matrix::build_ptdf_lodf;pub use matrix::build_weighted_laplacian;pub use matrix::build_ybus;pub use matrix::ground_at;pub use matrix::ground_at_each;pub use matrix::reference_indicator;pub use matrix::sddm_check;pub use matrix::susceptance_diag;pub use matrix::unit_vector;pub use opf_pipeline::DcOpfOptions;pub use opf_pipeline::DcOpfOutputs;pub use opf_pipeline::write_dcopf_bundle;pub use pipeline::MatrixKind;pub use pipeline::Pipeline;pub use pipeline::PipelineOutputs;pub use pipeline::RhsKind;pub use pipeline::build_kind;pub use io::gridfm::GridfmOptions;pub use io::gridfm::GridfmOutputs;pub use io::gridfm::GridfmRead;pub use io::gridfm::GridfmSnapshot;pub use io::gridfm::GridfmTables;pub use io::gridfm::gridfm_base_case;pub use io::gridfm::gridfm_record_batches;pub use io::gridfm::gridfm_record_batches_batch;pub use io::gridfm::gridfm_scenario_ids;pub use io::gridfm::numbered_snapshots;pub use io::gridfm::read_gridfm_dataset;pub use io::gridfm::read_gridfm_network;pub use io::gridfm::read_gridfm_scenarios;pub use io::gridfm::write_gridfm_batch;pub use io::gridfm::write_gridfm_dataset;
Modules§
- error
- format
- The format hub: readers and writers for every supported file format, all
meeting at the shared
Network. - indexed
IndexedNetwork: the dense-indexed analysis view over aNetwork.- io
- File I/O: Matrix Market (
.mtx) and JSON metadata, plus the gridfm-datakit Parquet export (--features gridfm). - matrix
- Sparse matrix builders for MATPOWER cases.
- network
- Format-neutral network model — the hub every converter meets at.
- opf_
pipeline - Writes the static DC OPF bundle for a case: one directory of named Matrix Market files plus a JSON manifest.
- pipeline
- Orchestrates a single case → output directory.
- synth
- Synthetic MATPOWER style cases. Stress tests the matrix builders beyond the vendored matpower test set.
Structs§
- Branch
- Bus
- BusId
- A bus identifier as it appears in the source file: the external, stable id
(1-based in MATPOWER, and possibly sparse — pegase has gaps in its ids).
Distinct from the dense
[0, n)analysis index, which onlyIndexedNetworkproduces, viabus_index. The two are both integers and trivially confused; making the id its own type stops one being used where the other is meant (using a 1-based id to index a matrix is off-by-one on a contiguous case and pure garbage on a sparse one). - Connectivity
Report - Topological invariants the TUI Inspect screen and downstream solvers care about.
- Conversion
- Output of a conversion: the serialized text plus any fidelity warnings:
data the target can’t represent, defaults synthesized, or blocks mapped best
effort. An empty
warningsmeans a faithful conversion. Forconvert_fileandconvert_str,warningscarries the read side (Parsedwarnings) too, ahead of the write side. - Element
Counts - The element counts that define a scenario batch’s shared base shape. Named
(rather than a bare
(usize, usize, usize)) so the three same-typed fields can’t be transposed silently in an error message or a comparison. - GenCost
- A generator cost curve (
mpc.gencostrow). - Generator
- Hvdc
- A two-terminal HVDC line (MATPOWER
dcline). - Index
Core - The owned, network-independent derivation behind
IndexedNetwork: the dense bus-id map plus the per-bus demand/shunt aggregates. Build it once withIndexCore::buildand reuse it across manyIndexedNetwork::with_coreviews of the sameNetwork. - Indexed
Network - A
Networkpaired with its derivedIndexCore. Borrows the network; the core is either owned (the one-shotIndexedNetwork::new) or borrowed from a cachedIndexCore(IndexedNetwork::with_core). - Load
- Network
- A format-neutral power network.
- Parsed
- Output of a parse: the network plus the reader’s fidelity warnings — tables and columns the model cannot carry, reported instead of dropped silently. Empty for readers that don’t report read warnings (currently every format except pandapower JSON and PyPSA CSV; the PSS/E and PowerWorld reductions are documented in docs/format-fidelity.md, not reported here yet).
- PwdDisplay
- Decoded PowerWorld display file content.
- PwdSubstation
- One substation symbol from a display file: the identity row joined with
its drawing record, in identity table (display) order.
xandyare diagram coordinates as stored, y north positive (see the module docs). - Pypsa
CsvOutputs - Shunt
- Storage
Enums§
- BusType
- Bus type per MATPOWER convention: 1=PQ, 2=PV, 3=ref/slack, 4=isolated.
- Display
Data - Output of a display parse. v0.2.2 supports PowerWorld
.pwd; future display formats can add variants without changing the parse entry point. - Display
Format - A display artifact format. These files are not power network cases and do
not parse to
Network. - Error
- Error
Category - Coarse classification of an
Error, for callers that map onto their own taxonomy (the Python layer’s exception subclasses, C ABI status codes, a CLI exit code). Distinguishing “the input file is bad” from “the operation can’t run on this otherwise-valid case” is the split callers actually branch on, and it’s a property of the error, not of the binding that surfaces it. - Scenario
Mismatch - Why a gridfm scenario snapshot doesn’t line up with the first snapshot’s base element set (the row-stack keeps every table schema-consistent by requiring the same element counts and bus-id ordering across snapshots).
- Source
Format - Which format a
Networkwas read from. Drives the same-format byte-exact echo on write. - Target
Format - A target interchange format. See
write_as.
Functions§
- convert_
file - Convert a case file to
to, optionally forcing the source format withfrom. - convert_
str - Convert in-memory case
textof the namedformat(seetarget_format_from_name) toto. - display_
format_ from_ name - Map a display format name to a
DisplayFormat, orNoneif unrecognized. Acceptspwd,powerworld-pwd, andpowerworld-display. - parse_
display_ bytes - Parse display bytes in the named display
format. - parse_
display_ file - Parse the display file at
path, choosing the reader fromfromor, whenNone, from the extension. v0.2.2 infers PowerWorld.pwd. - parse_
file - Parse the case file at
path, choosing the reader fromfrom(thetarget_format_from_namenames pluspypsa-csv/pypsaandpwb) or, whenNone, from the path: a directory containingnetwork.csvparses as a PyPSA CSV folder (any other directory fails:Error::UnknownFormatwhen its name maps to no extension, the I/O error otherwise), and a file maps by extension (m/json/raw/aux/pwb), case-insensitively (issue #97:.RAWis as common as.rawin the wild). A.jsonfile is sniffed three ways: pandapower ("_class": "pandapowerNet"), egret (top levelelementsandsystem), else PowerModels. Passfromto force one..pwbbinaries are read only and carry no retained source. ReturnsParsed: the network plus the reader’s fidelity warnings. - parse_
matpower - Parse the MATPOWER case in
contentinto aNetwork. - parse_
matpower_ file - Parse the MATPOWER case at
path, using the file stem as the network name. - parse_
pandapower_ json - Parse pandapower
pandapowerNetJSONcontent. ReturnsParsed: the network plus the reader’s fidelity warnings. - parse_
powermodels_ json - Parse PowerModels.jl network data JSON into a
Network. Loads and shunts are read as first-class elements and the raw text is retained, so writing back to PowerModels JSON is a byte-exact echo.per_unit = trueinput (powerio’s own output, and PowerModels’ own export) is converted to the neutral MW/degree convention (powers ×baseMVA, angles to degrees, cost coefficients un-scaled), following PowerModels’ own exceptions (storageps/qsstay raw, dclinept/qf/qtflip sign);per_unit = falseis read as-is. - parse_
powerworld - Parse a PowerWorld
.auxinto aNetwork, reading the Bus/Load/Shunt/ Gen/BranchDATAblocks by their declared field lists. - parse_
psse - Parse a PSS/E v33
.rawinto aNetwork. Reads bus/load/fixed-shunt/ generator/branch/2-winding-transformer; skips the advanced sections. - parse_
str - Parse in-memory case
textof the namedformat(seetarget_format_from_name). ReturnsParsed: the network plus the reader’s fidelity warnings. - read_
pypsa_ csv_ folder - Read a PyPSA CSV folder at
path. ReturnsParsed: the network plus the reader’s fidelity warnings. - target_
format_ from_ name - Map a format name (with the common aliases) to a
TargetFormat, orNoneif unrecognized. Acceptsmatpower/m,powermodels-json/powermodels/pm,egret-json/egret,pandapower-json/pandapower/pp,psse/raw,powerworld/aux. Case-insensitive. The one place the bindings (Python, C ABI) share, so a new text format means one new arm here, not three. PyPSA CSV folders are directory inputs with no text target; their aliases are matched by the privateis_pypsa_csv_namenext to this. - write_
as - Convert a
Networktoformat. Writing back to the source format returns the retained source text; otherwise the network is serialized into the target. - write_
egret_ json - write_
matpower - Serialize
netto MATPOWER.mtext. Echoes the retained source verbatim whennetcame from MATPOWER; otherwise emits canonical.m. - write_
pandapower_ json - write_
powermodels_ json - write_
powerworld - write_
psse - write_
pypsa_ csv_ folder