Expand description
C ABI for powerio: ABI v4.
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.
The surface follows a fixed grammar, written out in the header preamble
(include/powerio.h, generated by cbindgen, never hand-edit):
- Verb-led names are operations and the verb fixes the return family:
parse/read/normalizereturn a new handle,writehas a filesystem effect,converttranscodes without keeping a handle,freedestroys. to_marks a representation change of the same network; the target is a format string (pio_to_format) unless the output type differs (pio_to_arrowfills Arrow C Data Interface structs).- Format names never appear in symbols: formats are strings, so a new
format never changes this ABI. The canonical snapshot is the
powerio-jsonformat name. - Array extractors share the cap/count convention: write up to
capvalues, return the total available,NULLout is a pure count query. - Vocabulary: a bus is a named connection point (this surface is bus granular); a node is one conductor’s point at a bus, reserved for the multiconductor surface; a branch is any two-terminal series element, lines and transformers alike.
Structs§
- PioDist
Network - Opaque parsed distribution network handle (the multiconductor wire-coordinate
model). Distinct from
PioNetwork(the positive-sequence transmission model); none of thepio_n_*/extractor functions accept it. Only built with thedistcargo feature. - PioNetwork
- Opaque parsed network handle. Carries the parsed
Network, theIndexCorederived from it once at parse time (so every indexed query reuses the same bus-id map and per-bus aggregates instead of rebuilding them), and the reader’s fidelity warnings (pio_warnings). - PioPackage
- Opaque
.pio.jsoncompiler package handle. A package owns onepowerio_pkg::NetworkPackage, which wraps either a balancedPioNetworkpayload or a multiconductorPioDistNetworkpayload.
Constants§
- PIO_
ABI_ VERSION - ABI version of this C interface. Bump on any breaking change to an existing
pio_*signature or to thepowerio-jsonsnapshot 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_to_arrow; the C header mirrors these asPIO_ARROW_TABLE_*. - PIO_
ARROW_ TABLE_ GEN - PIO_
ARROW_ TABLE_ LOAD - PIO_
ARROW_ TABLE_ SHUNT - PIO_
ARROW_ TABLE_ SOLVER_ ARC - PIO_
ARROW_ TABLE_ SOLVER_ BRANCH - PIO_
ARROW_ TABLE_ SOLVER_ BUS - PIO_
ARROW_ TABLE_ SOLVER_ GEN - PIO_
ARROW_ TABLE_ SOLVER_ HVDC - PIO_
ARROW_ TABLE_ SOLVER_ LOAD - PIO_
ARROW_ TABLE_ SOLVER_ SHUNT - PIO_
ARROW_ TABLE_ SOLVER_ STORAGE - PIO_
ARROW_ TABLE_ SOLVER_ SWITCH - PIO_
ARROW_ TABLE_ SWITCH - PIO_
DIST_ ABI_ VERSION - ABI version of the optional
pio_dist_*C surface. This is separate fromPIO_ABI_VERSIONso distribution C entry points can evolve without forcing a core ABI bump. Version 1 is the supported dist surface with conversion order(input, from, to, ...). - 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_
branch_ ⚠charging - Write the branch terminal charging table as parallel arrays, each up to
capentries, and return the total branch count. Columns are p.u. - pio_
branches ⚠ - Write the branch table as parallel arrays, each up to
capentries, and return the total branch count. A branch is any two-terminal series element lines and transformers alike (a transformer hastap != 0).from/toare 1-based bus IDS (thepio_bus_idsid space, not dense indices); map them to dense matrix rows with thepio_bus_idsordering. Any output pointer may be NULL to skip that column; all NULL is the count query. - pio_
bus_ ⚠demand - Write the per-bus demand aggregates (active
pd, reactiveqd, summed over each bus’s loads, densepio_bus_idsorder), each up tocapentries, and return the total bus count. Either pointer may be NULL. - pio_
bus_ ⚠ids - Write the 1-based external bus ids, in dense order, into
out, up tocapentries, and return the total bus count. This ordering DEFINES the dense index space every other per-bus array shares. Call once with(NULL, 0)to size, allocate, then call again to fill. Ids are int64 in1..2^63-1(a v4 invariant); a source id that is a string or exceeds that range is mapped to dense int64 at read, never passed through raw. - pio_
bus_ ⚠shunt - Write the per-bus shunt aggregates (conductance
gs, susceptancebs, densepio_bus_idsorder), each up tocapentries, and return the total bus count. Either pointer may be NULL. - pio_
convert_ ⚠file - Convert the case file at
pathfrom formatfrom(NULL to infer from the path, aspio_parse_file) to formatto, without keeping a handle. Returns the converted text as an owned C string (free withpio_string_free),NULLon error. Fidelity warnings, read side first, are written\n-joined intowarnbuf. - pio_
convert_ ⚠str - Convert in-memory case
textfrom formatfrom(required; there is no path to infer from) to formatto, without keeping a handle: the in-memory sibling ofpio_convert_file. Returns the converted text as an owned C string (free withpio_string_free),NULLon error. Fidelity warnings, read side first, are written\n-joined intowarnbuf. - pio_
dist_ abi_ version - The ABI version of the optional
pio_dist_*surface. Only linked when thedistfeature is compiled in; probe that first withpio_has_feature("dist")if loading dynamically. - pio_
dist_ ⚠convert_ file - Convert distribution case
pathfrom optional source formatfromto formatto; seepio_dist_parse_filefor the inference rules. Returns the converted text as an owned C string (free withpio_string_free),NULLon error. The warnings written\n-joined intowarnbufcarry both the parse warnings and the writer’s fidelity losses (there is no handle to query them). - pio_
dist_ ⚠convert_ str - Convert in-memory distribution case
textof formatfromto formatto(both required;dss,pmd, orbmopf). The parameter order is input, source, target, matchingpio_dist_convert_file. Returns the converted text as an owned C string (free withpio_string_free),NULLon error. The warnings written\n-joined intowarnbufcarry both the parse warnings and the writer’s fidelity losses (there is no handle to query them). - pio_
dist_ ⚠network_ free - Free a distribution network handle from
pio_dist_parse_fileorpio_dist_parse_str. NULL is a no-op; free exactly once. - pio_
dist_ ⚠parse_ file - Parse a distribution case file into a
PioDistNetworkhandle. The format comes fromfromif non-NULL (dss,pmd, orbmopf), else from the file itself:.dssis OpenDSS, and.jsonholding the ENGINEERINGdata_modelkey is PMD JSON, otherwise BMOPF JSON. ReturnsNULLon error and writes the message intoerrbuf. Free the handle withpio_dist_network_free. - pio_
dist_ ⚠parse_ str - Parse in-memory distribution case
textof the namedformat(dss,pmd, orbmopf; required, since there is no path to infer from). An OpenDSSRedirect/Compileintextresolves against the current working directory. ReturnsNULLon error and writes the message intoerrbuf. Free the handle withpio_dist_network_free. - pio_
dist_ ⚠to_ format - Serialize
netto distribution formatto(dss,pmd, orbmopf). Writing back to the format the handle was parsed from echoes the source text byte for byte; a cross-format write reports every fidelity loss inwarnbuf(\n-joined). Returns the text as an owned C string (free withpio_string_free),NULLon error. - pio_
dist_ ⚠warnings - Parse warnings retained on the handle (everything the reader could not
represent or had to assume),
\n-joined and written into the callerwarnbuf(truncated to fit, always NUL-terminated). Returns the total byte length of the joined message; call withNULL/0 to size first, then fill — the same idiom aspio_warnings. Returns 0 for a NULL handle. - pio_
gens ⚠ - Write the generator table as parallel arrays, each up to
capentries, and return the total generator count.busis the 1-based bus id (thepio_bus_idsid space). Any output pointer may be NULL to skip. - pio_
has_ ⚠feature - Whether an optional build feature is compiled in: pass
"arrow","gridfm","dist", or"pkg". Returns 1 if present, 0 otherwise (and 0 for a NULL or unknown name). The optional surfaces (pio_to_arrow, thepio_read_dir/ gridfm path, thepio_dist_*block, and thepio_package_*block) are only linked when their feature is built, so a consumer that loaded the library at runtime probes for them here instead of resolving symbols blind. Feature names are strings like format names, so a new feature never changes this signature. Infallible. - pio_
is_ ⚠radial 1if the in-service topology is radial (every island a tree), else0.- pio_
n_ ⚠branches - pio_
n_ ⚠buses - pio_
n_ ⚠gens - pio_
n_ ⚠islands - Number of islands: connected components of the in-service topology.
- pio_
n_ ⚠switches - pio_
network_ ⚠free - Free a network handle from
pio_parse_file,pio_parse_str,pio_read_dir, orpio_normalize. - pio_
normalize ⚠ - Normalize
netinto a NEW network handle: per unit, radians, out-of-service filtered, source bus ids preserved, bus types canonicalized (seeNetwork::to_normalized). A value transform, not a serialization, hence the verb, while theto_*family re-encodes unchanged data. The result is independent ofnet; free both withpio_network_free. Every extractor and serializer works 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_
package_ ⚠diagnostics_ json - Return the package structured diagnostics array as JSON. The returned string
is owned by the library; free it with
pio_string_free. - pio_
package_ ⚠free - Free a package handle returned by
pio_package_*. NULL is a no-op; free exactly once. - pio_
package_ ⚠from_ balanced_ network - Wrap a balanced
PioNetworkhandle in a.pio.jsonpackage. The C handle name is historical; the payload ispowerio::BalancedNetwork.include_solver_metadata != 0attaches compact normalized solver table metadata. - pio_
package_ ⚠from_ multiconductor_ network - Wrap a multiconductor
PioDistNetworkhandle in a.pio.jsonpackage. The C handle name is historical; the payload ispowerio_dist::MulticonductorNetwork. - pio_
package_ ⚠lower_ multiconductor_ to_ balanced - Lower a multiconductor package to a new balanced package. Call
pio_package_multiconductor_to_balanced_preflight_jsonfirst when the caller needs structured blockers for unsupported inputs.base_mvais the three phase system power base used for the balanced per-unit projection. - pio_
package_ ⚠materialize_ operating_ point - Materialize one operating point into a new static package.
- pio_
package_ ⚠multiconductor_ to_ balanced_ preflight_ json - Return the multiconductor-to-balanced lowering preflight report as JSON.
base_mvais the three phase system power base used for the balanced per-unit projection. ReturnsNULLif the package is not multiconductor. - pio_
package_ ⚠operating_ points_ json - Return the package operating point series as JSON, or
nullwhen absent. The returned string is owned by the library; free it withpio_string_free. - pio_
package_ ⚠parse_ file - Parse a
.pio.jsonpackage file into an opaque package handle. This reads only the package envelope; case format names still enter throughpio_parse_file/pio_dist_parse_fileand package constructors. ReturnsNULLon error and writes the message intoerrbuf. Free the handle withpio_package_free. - pio_
package_ ⚠parse_ str - Parse in-memory
.pio.jsontext into an opaque package handle. ReturnsNULLon error and writes the message intoerrbuf. Free the handle withpio_package_free. - pio_
package_ ⚠to_ json - Serialize a package handle to compact
.pio.json. Returns an owned C string (free withpio_string_free) orNULLon error. - pio_
package_ ⚠validate - Run the package semantic validation profile in place. Returns
0on success,-1on error. - pio_
package_ ⚠validation_ json - Return the package validation summary as JSON. The returned string is owned
by the library; free it with
pio_string_free. - pio_
parse_ ⚠file - Parse
path(format from extension, orfromif non-NULL) into a network handle.fromaccepts thepio_parse_strformat names pluspypsa-csv/pypsa,goc3-json/goc3,surge-json/surge, andpwb; that includespslf/epc, and.epcis inferred by extension. 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_warnings). ReturnsNULLon error and writes the message intoerrbuf. Free the handle withpio_network_free. - 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,pslf/epc,goc3-json/goc3,surge-json/surge, orpowerio-json/json(the canonical snapshotpio_to_formatwrites, validated on read). PyPSA CSV folders are directories, not text; parse them withpio_parse_fileandfrom = "pypsa-csv". Read fidelity warnings attach to the handle (pio_warnings). ReturnsNULLon error and writes the message intoerrbuf. Free the handle withpio_network_free. - pio_
read_ ⚠dir - Read one scenario of a dataset directory in the named
fromformat into a network handle: the directory sibling ofpio_parse_file.gridfm(the gridfm-datakit Parquet layout;dirresolves leniently: theraw/leaf, a<case>/directory with araw/child, or a parent holding exactly one such case) is the one dataset format today.scenarioselects within a multi-scenario dataset (pio_scenario_idsenumerates them); formats without scenarios take0. Read fidelity warnings attach to the handle (pio_warnings). ReturnsNULLon error and writes the message intoerrbuf. Free the handle withpio_network_free. Built--features gridfm. - pio_
ref_ ⚠bus_ index - Dense
[0, n)index of the single reference (slack) bus, or-1if not exactly one. An INDEX into thepio_bus_idsordering, not a bus id;pio_branchesfrom/to carry ids, so the unit is in the name. A network may carry several references (one per island, or a normalized case that kept the file’s multipleREFbuses);pio_ref_bus_indicesreads them all, and its count (NULLout) tells zero from many. - pio_
ref_ ⚠bus_ indices - Write the dense
[0, n)indices of the reference (slack) buses, ascending, intoout, up tocapentries, and return the total count: the cap/count convention ofpio_bus_ids.0means none;> 1means one reference per island or several fixed references in one island (a normalized case always reports>= 1). - pio_
scenario_ ⚠ids - Write the distinct scenario ids (ascending) of the dataset directory
dirin the namedfromformat intoout, up tocapentries, and return the total count: the cap/count convention ofpio_bus_ids.gridfmis the one dataset format today. Returns-1on error and writes the message intoerrbuf(unlike the handle extractors, this reads the filesystem and can fail). Built--features gridfm. - pio_
string_ ⚠free - Free a string returned by
pio_to_format,pio_convert_file, orpio_convert_str. - pio_
switches ⚠ - Write the switch table as parallel arrays, each up to
capentries, and return the total switch count.from/toare external bus ids. - pio_
to_ ⚠arrow - Export one network table over the Arrow C Data Interface: the
to_conversion whose output type is Arrow structs rather than a string, and the bulk plane this ABI evolves on. Tables 0..5 are raw network tables; tables 6 and up are normalized solver tables with per unit/radian values and dense zero based row ids. New or richer columns arrive in the Arrow schema, leaving the C signatures fixed. - pio_
to_ ⚠format - Serialize
netto the named formatto: the one text serializer; every format is named by a string. Accepts thepio_parse_strnames:matpoweris a byte-exact echo when the handle was parsed from MATPOWER, andpowerio-jsonis the canonical snapshot (validated bypio_parse_stron the way back; the retained source text is the one field it omits). The snapshot is lossless except for a non-finitef64(Inf/NaN), which JSON cannot represent: it is written asnull, named in a fidelity warning, and then fails to read back; passwarnbufto detect it. - pio_
version - The crate version string (a semver string),
'staticand NUL-terminated. Do NOT free it. Informational; pair it withpio_abi_versionfor the actual compatibility check. - pio_
warnings ⚠ - The fidelity warnings attached to the handle at construction (by whichever
of
pio_parse_file,pio_parse_str,pio_read_dir, orpio_normalizebuilt it),\n-joined intowarnbuf(truncated to fit on a UTF-8 boundary; NULL/0 to skip). Returns the byte length of the full joined text, excluding the NUL; call once with(NULL, 0)to size, then pass achar[len + 1].0means no warnings (or a NULL handle); readers that are total attach none. - pio_
write_ ⚠dir - Write
netinto the directoryout_diras the named directory-shaped formatto: the directory sibling ofpio_to_format. PyPSA CSV (pypsa-csv/pypsa) is the one such format today; a text format name is an error pointing back atpio_to_format. Returns0on success and-1on error (message intoerrbuf). Fidelity warnings, if any, are written\n-joined intowarnbuf.