Expand description
powerio-matrix: sparse matrices and graph outputs 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 representation. 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 terminal admittance 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
the matrix guide.
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::ZeroImpedanceRule;pub use matrix::ZeroImpedanceSkips;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::skipped_zero_impedance;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 pipeline::matrix_stats_for_kind;pub use pipeline::zero_impedance_rule_for_kind;pub use pipeline::zero_impedance_skips_for_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;pub use io::dataset_scenario_ids;pub use io::read_dataset_dir;
Modules§
- error
- format
- Readers and writers for supported case formats, all meeting at
Network. - gen_
cost - 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). - GenCost
Patch - One explicit generator cost patch from a user supplied table.
- GenCost
Policy Report - Counts produced by applying user cost patches and a missing-cost policy.
- 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. The network is borrowed for the common case, but owned when it had to be star-lowered (a 3-winding transformer expanded into a star bus plus three branches viaNetwork::expand_transformers_3w); the core is owned (IndexedNetwork::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 readers that do not need to reduce any source fields).
- 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
- Write
Options - Optional write-time policies layered on top of the neutral
Network.
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. - Missing
GenCost Policy - Policy for generators whose source format has no active-power cost row.
- 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_
file_ with_ options - Convert a case file with write-time cost policies.
- convert_
str - Convert in-memory case
textof the namedformat(seetarget_format_from_name) toto. - convert_
str_ with_ options - Convert in-memory case text with write-time cost policies.
- 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/pypsa,pwb,pslf, andepc) 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/epc), case insensitively (issue #97:.RAWis as common as.rawin the wild). A.jsonfile is classified by top level shape markers: pandapower ("_class": "pandapowerNet"), egret (elementsandsystem), GO Challenge 3 (networkplustime_series_input/reliability), Surge JSON (format: "surge-json"), powerio-json (busesplus network keys), and PowerModels JSON (baseMVA,branch,gen, orgencost). JSON matching distribution markers, ambiguous markers, or no known markers returnsError::UnknownFormat. Passfromto force a transmission format. PowerWorld.pwbis a binary read only format with no retained source; PSLF.epcis text and has a writer. ReturnsParsed: the network plus the reader’s fidelity warnings. - parse_
gen_ cost_ csv - Parse a simple generator cost CSV with required columns
gen_index,bus,c2,c1,c0and optionalstartup,shutdown. - 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_
pslf - Parse a PSLF
.epccase into aNetwork. - parse_
psse - Parse a PSS/E
.raw(revisions 33-35) into aNetwork. Reads bus/load/ fixed-shunt/generator/branch/2- and 3-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,powerio-json/powerio/json(the canonical snapshot; plainjsonmeans this one, the foreign JSON dialects are namespaced),pslf/epc,goc3-json/goc3, andsurge-json/surge. 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, GridFM datasets, and PowerWorld.pwbare directory or read only inputs with no text target; they are routed bycrate::format::routing. - 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_
as_ with_ options - Convert a
Networkwith write-time cost policies. The oldwrite_asbehavior is preserved whenoptionsis default. - 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 - Serialize
netto PSS/E.rawat the default revision (33). - write_
pypsa_ csv_ folder