Skip to main content

Module format

Module format 

Source
Expand description

Parsing and emission for supported case formats, all meeting at BalancedNetwork.

Each format module owns its parser and/or serializer: MATPOWER .m, PowerModels JSON, PSS/E .raw, PowerWorld .aux, egret ModelData JSON, pandapower JSON, PyPSA CSV folders, PSLF .epc, PSS/E RAWX 35, PowSybl XIIDM and JIIDM 1.0 through 1.17, CIM CGMES 2.4.15 and 3.0, GO Challenge 3 JSON, Surge JSON, and DeepMind OPFData JSON. PowerWorld .pwb cases, OPFData JSON, and the IEEE Common Data Format are input only. GO Challenge 3 defines a calculation rather than a bare network, so its implementation is private to the powerio facade’s typed parser. PowerWorld .pwd displays read through the top-level powerio::parse as a powerio.GeoLayer. Case input and output formats meet here, so adding a format that supports emission is one module plus one hub registration. parse compiles a retained source into a typed module, detecting the format from the source name and content. emit emits a parsed module through a destination and echoes the retained source for a same format target. Non-finite numeric values, such as MATPOWER Inf/NaN angle limits, are emitted as JSON null.

§Fidelity behavior

Emission has two fidelity tiers:

  • Same format emission of an unchanged parsed module returns the original bytes. The module retains its source, so emit back to the same format returns every field, comment, and numeric token.
  • Cross-format keeps maximal fidelity with itemized loss. Whatever the target format cannot represent is reported by EmitResult::diagnostics, never dropped silently. During parsing, parsers itemize what they ignore on the module’s diagnostics.

Re-exports§

pub use powerworld::PwdDisplay;
pub use powerworld::PwdSubstation;

Modules§

powerworld
Parse and emit PowerWorld auxiliary .aux files.
routing
Shared format alias and JSON shape routing for the powerio crate.

Structs§

EmitOptions
Optional emission policies layered on top of the neutral BalancedNetwork.

Enums§

CgmesVersion
The CGMES release family a file set declares, from its cim namespace.
TargetFormat
A target case format. See emit.

Constants§

SOURCE_FORMAT_NAMES
The source format names this crate recognizes, each with its aliases. A recognized calculation format can still be refused with guidance to the top level facade. The unknown format error prints this list, and a test walks every alias through routing::parse_transmission_format so it cannot drift from the matcher. pypsa-csv names a directory source and pwb a binary one; every other name reads file and memory sources alike.

Functions§

emit
Emit a parsed module to format through a destination: the one output operation over file, memory, and (for the directory formats) folder output. Every text target commits a single artifact — a path destination names the exact file, a memory destination names the artifact — staged and renamed into place so a failed emission never exposes a partial target. The result carries the complete artifact inventory and the serializer’s findings.
emit_with_options
emit() with generator cost policies.
is_pypsa_csv_name
Whether a format name means a PyPSA CSV folder. PyPSA folders are directory inputs, not text targets, so they have no TargetFormat arm; this is the companion alias matcher to parse_target_format and the one place the PyPSA aliases live.
parse
Parse the case file at path, choosing the parser from from (the parse_target_format names plus pypsa-csv/pypsa, pwb, pslf, and epc) or, when None, from the path: a directory containing network.csv parses as a PyPSA CSV folder (any other directory is refused as a directory with Error::UnknownFormat, before extension inference), and a file maps by extension (m/json/raw/aux/pwb/epc), case insensitively (issue #97: .RAW is as common as .raw in the wild); a .txt or .cdf file whose first card is an IEEE CDF title card reads as ieee-cdf. A .json file is classified by top level shape markers: pandapower ("_class": "pandapowerNet"), egret (elements and system), GO Challenge 3 (network plus time_series_input/reliability, refused here with guidance to the typed facade parser), Surge JSON (format: "surge-json"), OPFData (grid, solution, and metadata), and PowerModels JSON (baseMVA, branch, gen, or gencost). JSON matching distribution markers, ambiguous markers, or no known markers returns Error::UnknownFormat. Declare a format on the source to force a parser. PowerWorld .pwb is a binary input only format; PSLF .epc is text and supports emission. Returns the typed module: the network value, the parser’s findings, and the retained source.
parse_format_id
The declared format ID for a caller-supplied token. Tokens are matched case insensitively and accept the historical underscore spelling of a hyphenated alias; the ID itself keeps the stable lower case hyphen grammar.
parse_target_format
Map a format name (with the common aliases) to a TargetFormat, or None if unrecognized. Accepts matpower/m, powermodels-json/powermodels/pm, egret-json/egret, pandapower-json/pandapower/pp, psse/raw, powerworld/aux, pslf/epc, goc3-json/goc3, and surge-json/surge, opfdata-json/opfdata/gridopt, xiidm, jiidm, cgmes, and ucte/uct. Case-insensitive. The one place the bindings (Python, C ABI) share, so a new format means one new arm here, not three. CGMES emits a profile directory; PyPSA CSV folders, GridFM datasets, PowerWorld .pwb, and IEEE CDF cases are routed by crate::format::routing.