reference_case (str, optional) – Name of a built-in network. Supports both pandapower case names
(e.g. "case118") and pypowsybl IEEE names (e.g.
"ieee14", "ieee118"). Ignored if reference_net or
reference_file is given.
reference_net (pandapowerNet or pypowsybl.network.Network, optional) – A pre-loaded network object (pandapower or pypowsybl). Takes
precedence over reference_case and reference_file.
reference_file (str, optional) – Path to a grid file in any pypowsybl-supported format (CGMES,
XIIDM, MATPOWER, IEEE-CDF, PSS/E, UCTE, etc.). Takes
precedence over reference_case.
level_specs (list of dict, optional) – Voltage-level specifications for Mode II. Each dict must have
keys "n" (int), "avg_k" (float), "diam" (int), and
"dist_type" ("dgln" | "dpl" | "poisson").
Optionally "max_k" (int).
connection_specs (dict, optional) – Transformer connection specs for Mode II. Maps
(level_i,level_j) tuples to dicts with "type"
("k-stars" | "simple") and parameters "c", "gamma".
seed (int, optional) – Random seed for reproducibility.
keep_lcc (bool) – If True (default), keep only the largest connected component
after topology generation.
entropy_model (int) – Bus-type entropy model — 0 (standard) or 1 (weighted).
bus_type_ratio (list of float, optional) – Target [Gen%,Load%,Conn%] ratios. If None, default
ratios based on network size are used.
ref_sys_id (int) – Reference system for statistical tables (0–3).
refine_topology (bool) – If True, the transmission allocator may add/remove edges to
improve DCPF convergence.
base_kv_map (dict, optional) – Custom {level_index:kV} mapping. If None and
mode="reference", the mapping is extracted from the reference
grid.
output_dir (str) – Directory for exported files (created if needed).
output_name (str) – Base filename (without extension) for exported files.
export_formats (sequence of str) – One or more format names to export. Supported:
"json", "excel", "sqlite", "pickle",
"xiidm", "cgmes", "matpower", "psse".
Returns:
The fully parameterised synthetic grid (a
PowerGridGraph).
Return type:
nx.Graph
Raises:
ValueError – If mode is not "reference" or "synthetic", or if
required arguments for the chosen mode are missing.
Generate detailed input sequences for PowerGridGenerator from
high-level parameters.
This is “operation mode II”, where the user specifies only the number of
nodes, average degree, diameter, and distribution type for each voltage
level, rather than providing explicit degree sequences. The configurator
uses DegreeDistributionOptimizer to fit distribution parameters
and then samples degree sequences.
See Section 6 of Aksoy et al. (2018) for the synthetic input
generation guidelines.
Parameters:
seed (int or None, optional) – Random seed for reproducibility. Default is None.
'max_k' (int, optional): maximum degree (default:
min(n-1,50)). For 'dpl' the paper suggests
\(d_{\max} \approx 1.517\,n^{1/4}\); for 'dgln'\(\bar{d} \approx 2.425 \pm 0.185\) is consistent across
subgraphs (Section 6.1 of Aksoy et al., 2018).
inter_connections (dict) –
Mapping (i,j)->config for transformer connections.
Config is either:
Generative model for an entire power grid graph on k voltage levels.
Implements Algorithm 4 (CLCStars) from Aksoy et al. (2018).
Phase 1 generates each same-voltage subgraph via the CLC model,
and Phase 2 inserts transformer edges via the random-star model.
Parameters:
seed (int or None, optional) – Random seed for reproducibility. Default is None.
Generate a multi-level power grid graph (CLCStars, Algorithm 4).
Runs Phase 1 (CLC for each voltage level) and Phase 2 (random-star
transformer edges for each pair of levels), then combines results.
Parameters:
degrees_by_level (list of list of int) – Desired degree sequences \(\mathbf{d}^{X_1},\dots,\mathbf{d}^{X_k}\),
one per voltage level.
diameters_by_level (list of int) – Desired diameters \(\delta^{X_1},\dots,\delta^{X_k}\),
one per voltage level.
transformer_degrees (dict) – Mapping (i,j)->(t_i_j,t_j_i) where t_i_j is the
transformer degree list for level-i nodes toward level j,
and t_j_i is the reverse.
keep_lcc (bool, optional) – If True, return only the largest connected component with
contiguous node IDs. Default is False.
Returns:
The generated grid graph with voltage_level node attributes
and type ('line' or 'transformer') edge attributes.
Assigns bus types (Generator, Load, Connection) to a raw power grid
topology using an Artificial Immune System (AIS) optimization algorithm.
The method, from Elyas and Wang (2016), exploits the observed non-trivial
correlations between bus types and topology metrics (node degree, clustering
coefficient) in realistic grids. A bus type entropy measure quantifies
these correlations, and a target entropy \(W^*\) is derived from a
scaling property fitted to real-world systems. The AIS then searches for
an assignment whose entropy matches \(W^*\).
The pipeline is:
Determine target bus type ratios \((r_G, r_L, r_C)\) from network
size.
Estimate \(W^*\) via Monte Carlo sampling of random assignments
and the scaling relation \(W^* = \mu + \sigma \cdot d(N)\).
Run AIS optimization (clonal selection, hypermutation, receptor editing)
to find an assignment \(\mathbb{T}\) such that
\(|W(\mathbb{T}) - W^*| < \epsilon\).
Two entropy definitions are supported:
Model 0 (\(W_0\)): standard entropy of bus/link type ratios.
\(\mu\) is stable across network sizes.
Model 1 (\(W_1\)): generalized entropy weighted by \(N\)
and \(M\). \(\mu\) grows with network size, giving better
discrimination in large grids.
Parameters:
graph (nx.Graph) – NetworkX graph representing the grid topology (nodes and edges only;
no bus type attributes required yet).
entropy_model (int) – Selects the entropy definition: 0 for \(W_0\), 1 for \(W_1\).
bus_type_ratio (list of float or None) – Optional target ratios [Gen,Load,Conn]. Values are normalized
to sum to 1. If None, default ratios are chosen based on N.
Assigns generation capacities (PgMax) to generator buses in the grid.
Implements the three-stage methodology from Elyas et al. (2017):
Total generation: Compute the aggregate generation capacity from a
scaling law fitted to realistic grids:
logPg_tot(N)=-0.21*log^2(N)+2.06*log(N)+0.66.
Individual capacities: Sample N_g individual capacities from an
exponential distribution (with ~1% super-large outliers to capture the
observed heavy tail).
Correlated assignment: Assign capacities to generator buses using a
14x14 empirical 2D probability table (Tab_2D_Pgmax) that encodes
the joint distribution of normalized capacity and normalized nodal
degree. This preserves the observed Pearson correlation
rho(P_bar, k_bar) in [0.25, 0.5] between capacity and degree.
Reference systems with pre-computed Tab_2D_Pgmax tables are available
for NYISO-2935 (id=1), WECC-16944 (id=2), and a third system (id=3).
A heuristic diagonal-bias table (id=0) is provided as a fallback.
Parameters:
graph (nx.Graph) – NetworkX graph with 'bus_type' node attributes already set
(by BusTypeAllocator).
ref_sys_id (int) – Reference system for statistical tables (0=heuristic, 1=NYISO-2935,
2=WECC-16944, 3=additional reference).
Run the full generation-capacity allocation pipeline.
Executes the three-stage methodology from Elyas et al. (2017):
Compute total generation capacity from the scaling law:
Pg_tot=10^(-0.21*log10(N)^2+2.06*log10(N)+0.66).
Sample individual capacities, normalize them and the generator
nodal degrees by their respective maxima so that both lie in
[0, 1]: P_bar=P/max(P), k_bar=k/max(k).
Assign normalized capacities to generator buses via 2D binning
using Tab_2D_Pgmax.
Denormalize: Pg_max=P_bar*max(P).
Parameters:
tab_2d (np.ndarray or None, optional) – Custom 14x14 probability matrix. If None, the default table
for the selected ref_sys_id is used.
Returns:
Mapping from generator node ID to its assigned capacity
Pg_max (MW).
Assigns active power loads (PL) to load buses in the grid.
Implements the load-setting methodology from Elyas et al. (2017), which
mirrors the generation-capacity approach in CapacityAllocator:
Total load: Compute an aggregate load target, either from a
deterministic scaling formula or as a fraction (light / medium / heavy)
of the total installed generation capacity.
Individual loads: Sample N_l individual loads from an exponential
distribution (with ~1% super-large outliers).
Correlated assignment: Assign loads to load buses using a 14x14
empirical 2D probability table (Tab_2D_load) that encodes the
joint distribution of normalized load demand and normalized nodal
degree.
Reference systems with pre-computed Tab_2D_load tables are available
for NYISO-2935 (id=1), WECC-16944 (id=2), and a third system (id=3).
A heuristic diagonal-bias table (id=0) is provided as a fallback.
Parameters:
graph (nx.Graph) – NetworkX graph with 'bus_type' and (for non-deterministic loading
levels) 'pg_max' node attributes already set.
ref_sys_id (int) – Reference system for statistical tables (0=heuristic, 1=NYISO-2935,
2=WECC-16944, 3=additional reference).
Uncommitted units (10–20 %): \(\alpha = 0\), selected via
targets drawn from Uniform[0, 0.6].
Partially committed units (40–50 %): selected via exponential
distribution on capacity; dispatch factors assigned through a
2-D bin-matching table Tab_2D_Pg (\(14 \times 10\)).
Fully committed units (remainder): \(\alpha = 1\).
Balancing loop: iteratively adjusts dispatch to match total
load within 1 % tolerance.
Parameters:
graph (networkx.Graph) – Power grid graph. Generator nodes must have 'bus_type'=='Gen'
and 'pg_max' (MW) attributes. Load nodes must have 'pl' (MW).
ref_sys_id (int, optional) – Reference system for statistical tables (1 = NYISO-2935,
2 = WECC-16994, 3 = additional reference). Default is 1.
Loading-level flag from the reference system. When 0 all alphas
are Uniform[0, 1]; otherwise 0.5 % receive negative dispatch
(e.g., pumped-storage hydro).
Implements the algorithm of Sadeghian et al. (2018):
Collect generator buses and normalise capacities by
\(P^{\max}_{g_{\max}}\).
Partition generators into uncommitted
(\(\alpha = 0\)), partially committed
(\(0 < \alpha < 1\)), and fully committed
(\(\alpha = 1\)).
Assign dispatch factors to partially committed units via
the 2-D bin-matching table Tab_2D_Pg.
Iteratively balance total generation against total load
(1 % tolerance, up to 50 iterations) by scaling committed
\(\alpha\) values and toggling uncommitted / full-load
units on or off.
Convert normalised dispatch back to MW:
\(P_{g_i} = \alpha_i \cdot \bar{P}_{g_i}^{\max} \cdot P^{\max}_{g_{\max}}\).
Returns:
Mapping of generator bus ID to dispatched active power (MW).
Allocate impedance and capacity limits to transmission lines.
The algorithm follows Sadeghian et al. (2018) and the SynGrid
MATLAB toolbox (sg_line.m, sg_flow_lim.m):
Impedance generation — magnitudes \(Z\) from
LogNormal(\(\mu\), \(\sigma\)), angles \(\varphi\)
from a Lévy stable distribution
\(S(\alpha_s, \beta_s, \gamma_s, \delta_s)\). Then
\(X = Z \sin\varphi\), \(R = Z \cos\varphi\).
DCPF-based swapping — sort impedances ascending and flows
descending, then randomly swap ~20–30 % of assignments to
introduce variance while preserving the negative correlation
between impedance and flow.
(Optional) Topology refinement — iteratively add
low-impedance lines between max angle-difference bus pairs
and remove weak high-\(X\) lines until the angle spread
is below a size-dependent threshold.
Capacity assignment — gauge ratios
\(\beta_l = F_l / F_l^{\max}\) from
Exponential(\(\mu_\beta\)) with overload injection;
assigned via 2-D table Tab_2D_FlBeta.
Capacity limits: \(F_l^{\max} = F_l / \beta_l\).
Parameters:
graph (networkx.Graph) – Power grid graph with nodal generation/load attributes.
Run the full Schweitzer distribution synthesis pipeline.
Parameters:
mode ("reference" or "default") –
Selects the operation mode.
"reference" — fit synthesis parameters from an existing
distribution network (pandapower, pypowsybl, or file), then
generate synthetic feeders with the fitted parameters.
"default" — use default Table III parameters (or a
user-supplied DistributionSynthParams).
reference_case (str, optional) – Short name of a built-in distribution network. Currently
supported: "cigre_lv", "cigre_mv", or any pandapower
factory function name. Ignored when reference_net or
reference_file is given.
reference_net (pandapowerNet or pypowsybl.network.Network, optional) – A pre-loaded network object. Takes precedence over
reference_case and reference_file.
reference_file (str, optional) – Path to a grid file in any pypowsybl-supported format.
params (DistributionSynthParams, optional) – Custom parameters for mode="default". If None, the
built-in defaults from Schweitzer Table III are used.
n_feeders (int) – Number of synthetic feeders to generate (default 1).
n_nodes (int) – Number of nodes per feeder (default 20).
total_load_mw (float) – Total load in MW per feeder (default 0.5).
total_gen_mw (float) – Total generation in MW per feeder (default 0.0).
v_nom_kv (float) – Nominal voltage in kV (default 10.0).
assign_cable_types (bool) – Run Step 4 — cable type assignment (default True).
Graph representation of a radial distribution feeder.
Inherits from PowerGridGraph and adds convenience properties
for radial-tree distribution grids annotated with hop distances,
node types, and cable parameters (Schweitzer et al. 2017 format).
Compares a synthetic power grid against a reference (real-world) graph.
Provides tabular metric comparisons and visual distribution overlaps,
both globally and per voltage level.
Computes Kolmogorov-Smirnov (KS) and Relative Hausdorff (RH) statistics
between the degree distributions of the synthetic and reference graphs,
per voltage level. Prints and returns the results table.
Parameters:
show_pvalue (bool) – If True, include the KS p-value column. Default False.
Returns:
pd.DataFrame with columns Level, KS Statistic, RH Distance
(and KS p-value if show_pvalue is True).
Bubble plot showing generation and load magnitudes.
Generators are blue squares, Loads are red circles.
Size is proportional to capacity/load.
Optionally plots impedance on edges.
Exports the generated synthetic grid to standard file formats via
pandapower and pypowsybl built-in functions.
Parameters:
graph (Graph) – The synthetic power grid as a NetworkX Graph.
base_mva (float) – System base apparent power in MVA.
base_kv_map (dict | None) – Dictionary mapping voltage level indices to kV values
(e.g., {0:380.0,1:110.0,2:20.0}). If None,
a default mapping is used.
Load a power grid from a file in any pypowsybl-supported format.
Supported formats include CGMES, XIIDM, MATPOWER, IEEE-CDF, PSS/E,
UCTE, BIIDM, JIIDM, and POWER-FACTORY. The format is auto-detected
from the file extension when format is None.
Parameters:
filepath (str) – Path to the grid data file.
format (str, optional) – Explicit format string (e.g. 'CGMES', 'MATPOWER'). If
None the format is inferred by pypowsybl from the file.
Returns:
NetworkX graph compatible with the synthesizer pipeline (same
structure as pypowsybl_to_nx()).