Skip to main content

powerio/
lib.rs

1//! `powerio`: lossless parsing and a typed data model for power system case
2//! files.
3//!
4//! Readers and writers cover MATPOWER `.m`, PowerModels JSON, PSS/E `.raw`,
5//! PowerWorld `.aux`, pandapower JSON, PyPSA CSV, egret JSON, PSLF `.epc`, GO
6//! Challenge 3 JSON, and Surge JSON. PowerWorld `.pwb` case files are read
7//! only, and GO Challenge 3 JSON has no canonical writer beyond same source
8//! echo; `.pwd` display files parse through [`parse_display_file`].
9//! Case formats meet at the typed [`Network`], and
10//! [`Network::to_format`] reports whatever a target format cannot represent.
11//! See the [`crate::format`] module for the two-tier fidelity behavior.
12//!
13//! Writing back to the source format reproduces the file byte for byte:
14//! `parse → write → parse` returns the original text, down to comments and
15//! exact numeric tokens. The crate keeps a small dependency set so other
16//! tools can embed it as a parser without a matrix or solver stack; the
17//! matrices live in the `powerio-matrix` crate.
18//!
19//! ```
20//! use powerio::{parse_str, TargetFormat};
21//!
22//! let src = "\
23//! function mpc = example
24//! mpc.version = '2';
25//! mpc.baseMVA = 100;
26//! mpc.bus = [
27//! \t1\t3\t0\t0\t0\t0\t1\t1\t0\t230\t1\t1.1\t0.9;
28//! \t2\t1\t0\t0\t0\t0\t1\t1\t0\t230\t1\t1.1\t0.9;
29//! ];
30//! mpc.branch = [
31//! \t1\t2\t0.01\t0.1\t0\t0\t0\t0\t0\t0\t1\t-360\t360;
32//! ];
33//! ";
34//! let net = parse_str(src, "matpower")?.network;
35//! assert_eq!(net.buses.len(), 2);
36//! assert_eq!(net.to_format(TargetFormat::Matpower)?.text, src);
37//! # Ok::<(), powerio::Error>(())
38//! ```
39
40pub mod error;
41pub mod format;
42pub mod gen_cost;
43pub mod indexed;
44pub mod network;
45mod normalize;
46mod operations;
47pub mod solver_tables;
48
49pub use error::{ElementCounts, Error, ErrorCategory, Result, ScenarioMismatch};
50pub use format::{
51    Conversion, DisplayData, DisplayFormat, Parsed, PwdDisplay, PwdSubstation, PypsaCsvOutputs,
52    TargetFormat, WriteOptions, convert_file, convert_file_with_options, convert_str,
53    convert_str_with_options, display_format_from_name, parse_display_bytes, parse_display_file,
54    parse_egret_json, parse_file, parse_goc3_json, parse_matpower, parse_matpower_file,
55    parse_pandapower_json, parse_powermodels_json, parse_powerworld, parse_pslf, parse_psse,
56    parse_str, parse_surge_json, read_pypsa_csv_folder, target_format_from_name, write_as,
57    write_as_with_options, write_dir, write_egret_json, write_matpower, write_pandapower_json,
58    write_powermodels_json, write_powerworld, write_pslf, write_psse, write_psse_rev,
59    write_pypsa_csv_folder, write_surge_json,
60};
61pub use gen_cost::{GenCostPatch, GenCostPolicyReport, MissingGenCostPolicy, parse_gen_cost_csv};
62pub use indexed::{ConnectivityReport, IndexCore, IndexedNetwork};
63pub use network::{
64    Area, BalancedNetwork, Branch, BranchCharging, BranchCurrentRatings, BranchRatingSet,
65    BranchSolution, Bus, BusId, BusType, DEFAULT_BASE_FREQUENCY, Diagnostic, Extras, GenCaps,
66    GenCost, Generator, Hvdc, Impedance, Load, LoadVoltageModel, Network, Shunt, ShuntBlock,
67    SolverParams, SourceFormat, Storage, Switch, SwitchedShuntControl, SwitchedShuntMode,
68    Transformer3W, TransformerControl, TransformerControlMode, Winding,
69};
70pub use operations::Selector;
71pub use solver_tables::{
72    NORMALIZED_SOLVER_TABLES_PASS, NormalizedSolverTables, SolverArcRow, SolverArcTerminal,
73    SolverBranchRow, SolverBusRow, SolverCostRow, SolverGeneratorRow, SolverHvdcRow, SolverLoadRow,
74    SolverShuntRow, SolverStorageRow, SolverSwitchRow, SolverTableIndex, SolverTableUnits,
75};