Expand description
C ABI for powerio.
Parse any supported power system case format into an opaque handle, query it,
convert it to another format, and pull out the numeric tables a
downstream solver needs to assemble matrices. Every entry point is extern "C", catches panics at the boundary, and returns error text into a
caller-provided buffer. Strings handed back are owned by the library; free
them with pio_string_free. Array extractors fill caller-allocated
buffers (length = the matching pio_n_* count); pass NULL to skip one.
Naming: every symbol is prefixed pio_. The header is include/powerio.h.
Structs§
- PioNetwork
- Opaque parsed network handle. Carries the parsed [
Network], the [IndexCore] derived from it once at parse time (so every indexed query reuses the same bus-id map and nodal aggregates instead of rebuilding them), and the reader’s fidelity warnings (pio_parse_warnings).
Constants§
- PIO_
ABI_ VERSION - ABI version of this C interface. Bump on any breaking change to an existing
pio_*signature or to the JSON transport schema (new additive symbols don’t require a bump). A consumer comparespio_abi_versionagainst the value it was built against (thePIO_ABI_VERSIONmacro inpowerio.h) and refuses a mismatched library instead of calling in blind. - PIO_
ARROW_ TABLE_ BRANCH - PIO_
ARROW_ TABLE_ BUS - Table selectors for
pio_export_arrow; the C header mirrors these asPIO_ARROW_TABLE_*. - PIO_
ARROW_ TABLE_ GEN - PIO_
ARROW_ TABLE_ LOAD - PIO_
ARROW_ TABLE_ SHUNT - PIO_
ERRBUF_ MIN - A comfortable error-buffer size: pass a
char[PIO_ERRBUF_MIN]to anyerrbuf/warnbufparameter and a message always fits without truncation.
Functions§
- pio_
abi_ version - The ABI version the library was built with (see
PIO_ABI_VERSION). Lets a consumer detect a stale or incompatible library at load time. Infallible. - pio_
base_ ⚠mva - pio_
branches ⚠ - Fill the branch tables (each length
pio_n_branches).from/toare the 1-based bus ids (the same id space aspio_bus_ids, not dense indices); map them to dense matrix rows with thepio_bus_idsordering. Any pointer may beNULLto skip. - pio_
bus_ ⚠ids - Fill
out(lengthpio_n_buses) with the 1-based bus ids in dense order. - pio_
convert_ ⚠file - Convert
pathto formatto(optionally forcing the source viafrom). Returns the converted text as an owned C string (free withpio_string_free),NULLon error. Fidelity warnings, if any, are written\n-joined intowarnbuf. - pio_
export_ ⚠arrow - Export one raw network table over the Arrow C Data Interface.
- pio_
from_ ⚠json - Rebuild a network handle from JSON produced by
pio_to_json. Returns a new handle (free withpio_network_free), orNULLon error (message intoerrbuf). The handle has no retained source, sopio_to_matpowerreformats it rather than echoing a byte-exact original. - pio_
gens ⚠ - Fill the generator tables (each length
pio_n_gens;busis the 1-based bus id, the same id space aspio_bus_ids). Any pointer may beNULLto skip. - pio_
gridfm_ ⚠scenario_ ids - Write a gridfm dataset’s distinct scenario ids (ascending) into
out, up tocapentries, and return the total count. Call once withcap == 0(oroutNULL) to size, allocate, then call again to fill — the standard count/buffer pattern ofpio_bus_ids. Returns-1on error and writes the message intoerrbuf. Built--features gridfm. - pio_
is_ ⚠radial 1if the in-service topology is a forest, else0.- pio_
n_ ⚠branches - pio_
n_ ⚠buses - pio_
n_ ⚠components - pio_
n_ ⚠gens - pio_
n_ ⚠reference_ buses - Number of reference (slack) buses.
0means none;> 1means one reference per island or several fixed reference buses in one island. A normalized case always reports>= 1. - pio_
network_ ⚠free - Free a network handle from
pio_parse_file,pio_parse_str,pio_to_normalized, orpio_from_json. - pio_
nodal_ ⚠demand - Fill nodal aggregates (each length
pio_n_buses, dense order): active and reactive demand summed per bus. Any pointer may beNULL. - pio_
nodal_ ⚠shunt - Fill nodal shunt aggregates (each length
pio_n_buses, dense order). - pio_
parse_ ⚠file - Parse
path(format from extension, orfromif non-NULL) into a case handle.fromaccepts thepio_parse_strformat names pluspypsa-csv/pypsa; a PyPSA CSV folder is a directory, so it can only enter through this function, withfrom = "pypsa-csv"(or NULL when the directory holds anetwork.csv). Read fidelity warnings attach to the handle (pio_parse_warnings). ReturnsNULLon error and writes the message intoerrbuf. - pio_
parse_ ⚠str - Parse in-memory case
textof the namedformatinto a network handle. Unlikepio_parse_filethere is no path to infer from, soformatis required: one ofmatpower/m,powermodels/pm,egret,pandapower-json/pandapower/pp,psse/raw,powerworld/aux(seeTargetFormat::from_str). PyPSA CSV folders are directories, not text; parse them withpio_parse_fileandfrom = "pypsa-csv". Read fidelity warnings attach to the handle (pio_parse_warnings). ReturnsNULLon error and writes the message intoerrbuf. Free the handle withpio_network_free. - pio_
parse_ ⚠warnings - Read fidelity warnings attached at parse time,
\n-joined intowarnbuf(truncated to fit; NULL/0 to skip). Returns the warning count; 0 for a NULL handle. Empty for formats whose readers are total. - pio_
read_ ⚠gridfm - Read one scenario of a gridfm-datakit Parquet dataset into a network handle —
the inverse of the gridfm writer.
dirresolves leniently: theraw/leaf holding the parquet files, a<case>/directory with araw/child, or a parent holding exactly one such case. ReturnsNULLon error and writes the message intoerrbuf; the lossy read’s fidelity warnings (what the gridfm schema couldn’t round-trip) are written\n-joined intowarnbuf. Free the handle withpio_network_free. Built--features gridfm. - pio_
reference_ ⚠bus - Dense
[0, n)index of the single reference bus, or-1if not exactly one (also-1if the index is too large forisize). A network may carry several references (one per island, or a normalized case that kept the file’s multipleREFbuses); usepio_n_reference_busesto tell zero from many, andpio_reference_busesto read them all. - pio_
reference_ ⚠buses - Fill
out(lengthpio_n_reference_buses) with the dense[0, n)indices of the reference buses, ascending. - pio_
string_ ⚠free - Free a string returned by
pio_to_matpower,pio_to_format,pio_convert_file, orpio_to_json. - pio_
to_ ⚠format - Serialize
netto formatto. - pio_
to_ ⚠json - Serialize the case to JSON: the structured-table transport every Julia
bridge consumes. Carries the whole [
Network] (buses, loads, shunts, branches, generators, storage, HVDC, extras) but not the retained source text, so it is structured data, not the byte-exact echo. Returns an owned C string (free withpio_string_free),NULLon error (message intoerrbuf). - pio_
to_ ⚠matpower - Serialize
netto MATPOWER.mtext (byte-exact echo when parsed from MATPOWER). Returns an owned C string; free withpio_string_free. ReturnsNULLon error and writes the message intoerrbuf. - pio_
to_ ⚠normalized - Normalize
netinto a NEW per-unit network handle: per unit, radians, out-of-service filtered, source bus ids preserved, bus types canonicalized (seeNetwork::to_normalized). The result is independent ofnet; free both withpio_network_free. Every extractor andpio_to_jsonworks on it unchanged (the handle is per unit, not MW). ReturnsNULLon error (no reference bus can be chosen, or a non-positive base MVA) and writes the message intoerrbuf. - pio_
version - The crate version string (e.g.
"0.0.1"),'staticand NUL-terminated. Do NOT free it. Informational; pair it withpio_abi_versionfor the actual compatibility check. - pio_
write_ ⚠pypsa_ csv_ folder - Write
netas a PyPSA CSV folder atout_dir. Returns0on success and-1on error (the message is written intoerrbuf), the same convention as the other fallibleintreturns in this ABI. Fidelity warnings, if any, are written\n-joined intowarnbuf.