Progress Utilities Module¶
- class progress.mod_utilities.RAUtilities¶
Bases:
object
Contains utility methods required for performing mixed time sequential Monte Carlo (MCS) simulations and evaluating reliability indices in power systems.
- This class offers functions to:
Compute reliability transition rates for various components (generators, transmission lines, ESS).
Track and update component states (fail/repair) over simulated time.
Aggregate or compute net capacities, state of charge, and wind/solar generation.
Perform optimization-based dispatch (economic dispatch) in either a zonal or copper-sheet model.
Compute final reliability indices (e.g., LOLP, EUE, LOLE) and handle parallel (MPI) processing steps.
- CheckConvergence(s, LOLP_rec, comm, rank, size, mLOLP_rec, COV_rec)¶
Gathers partial results from all MPI processes and updates the running mean and coefficient of variation (COV) for LOLP. Used to track convergence during MCS.
- Parameters:
s (int) – Current sample index.
LOLP_rec (np.ndarray) – Array of LOLP values recorded by the local process for each sample so far.
comm (mpi4py.MPI.Comm) – MPI communicator object.
rank (int) – MPI rank of this process.
size (int) – Total number of MPI processes.
mLOLP_rec (np.ndarray) – Array for storing the running mean of LOLP across samples.
COV_rec (np.ndarray) – Array for storing the coefficient of variation (COV) at each sample.
- Returns:
A 2-element tuple containing:
mLOLP_rec (np.ndarray): Updated array of mean LOLP values across processes.
COV_rec (np.ndarray): Updated array of COV values, checking for convergence.
- Return type:
tuple
- GetReliabilityIndices(indices_rec, sim_hours, samples)¶
Computes final reliability indices (LOLP, EUE, EPNS, LOLE, etc.) by averaging over the recorded arrays.
- Parameters:
indices_rec (dict) – Dictionary with arrays of reliability indices (one entry per sample).
sim_hours (int) – Total number of hours (e.g., 8760) in the simulation horizon.
samples (int) – Number of Monte Carlo samples performed.
- Returns:
A dictionary containing final reliability metrics such as LOLP, LOLH, EUE, EPNS, LOLE, etc.
- Return type:
dict
- NextState(t_min, ng, ness, nl, lambda_tot, mu_tot, current_state, cap_max, cap_min, ess_units)¶
Determines which component (gen/trans/ESS) transitions (fails or repairs) next using exponential random draws, then updates system states and capacities.
- Parameters:
t_min (float) – Time (hours) remaining until the next state transition event occurs.
ng (int) – Number of conventional generators.
ness (int) – Number of energy storage systems.
nl (int) – Number of transmission lines.
lambda_tot (np.ndarray) – Failure rates for all components (ordered: gen, lines, ESS).
mu_tot (np.ndarray) – Repair rates for all components (ordered: gen, lines, ESS).
current_state (np.ndarray) – Current binary states of each component (1 = up, 0 = down). For ESS, each integer denotes how many are up among identical units.
cap_max (np.ndarray) – Maximum capacities for each component type.
cap_min (np.ndarray) – Minimum capacities for each component type.
ess_units (np.ndarray) – Number of identical units for each ESS installation.
- Returns:
A 3-element tuple containing:
current_state (np.ndarray): Updated states after one component fails/repairs.
current_cap (dict): Current maximum and minimum capacity arrays (accounting for the updated state).
t_min (float): Updated time to the next state transition.
- Return type:
tuple
- OptDispatch(ng, nz, nl, ness, fb_ess, fb_soc, BMva, fb_Pg, fb_flow, A_inc, gen_mat, curt_mat, ch_mat, gencost, net_load, SOC_old, ess_pmax, ess_eff, disch_cost, ch_cost)¶
Formulates and solves an economic dispatch (transportation model) optimization for a single hour, including line flow constraints, generation dispatch, storage charging/discharging, and load curtailment.
- Parameters:
ng (int) – Number of conventional generators.
nz (int) – Number of zones.
nl (int) – Number of lines.
ness (int) – Number of energy storage systems.
fb_ess (function) – Function specifying variable bounds for ESS charging power.
fb_soc (function) – Function specifying variable bounds for ESS state of charge.
BMva (float) – System base power (MVA).
fb_Pg (function) – Function specifying variable bounds for generator and ESS discharge power.
fb_flow (function) – Function specifying variable bounds for line flow.
A_inc (np.ndarray) – Incidence matrix for lines.
gen_mat (np.ndarray) – Generation matrix indicating which bus/zone each generator belongs to.
curt_mat (np.ndarray) – Matrix used for load curtailment variables (identity mapping to each zone).
ch_mat (np.ndarray) – Matrix used for storage charging variables (which bus/zone each ESS belongs to).
gencost (np.ndarray) – Per-unit fuel costs for conventional generators.
net_load (np.ndarray) – Net load array (MW) per zone.
SOC_old (np.ndarray) – Previous hour’s state-of-charge for each ESS (MWh).
ess_pmax (np.ndarray) – Maximum power output (MW) for each ESS.
ess_eff (np.ndarray) – Round-trip efficiency (fraction) for each ESS.
disch_cost (np.ndarray) – Discharge cost for each ESS.
ch_cost (np.ndarray) – Charge cost for each ESS.
- Returns:
A 2-element tuple containing:
load_curt (float): Total load curtailment (MW) in this hour.
SOC_old (np.ndarray): Updated state-of-charge for each ESS after dispatch.
- Return type:
tuple
- OptDispatchLite(ng, nz, ness, fb_ess, fb_soc, BMva, fb_Pg, A_inc, gencost, net_load, SOC_old, ess_pmax, ess_eff, disch_cost, ch_cost)¶
Solves an economic dispatch problem ignoring line flow constraints (copper-sheet model). This method is a simplified version of
OptDispatch()
.- Parameters:
ng (int) – Number of conventional generators.
nz (int) – Number of zones.
ness (int) – Number of energy storage systems.
fb_ess (function) – Function specifying variable bounds for ESS charging power.
fb_soc (function) – Function specifying variable bounds for ESS state-of-charge.
BMva (float) – System base power (MVA).
fb_Pg (function) – Function specifying variable bounds for generator and ESS discharge power.
A_inc (np.ndarray) – Incidence matrix (not strictly used, but included for consistency).
gencost (np.ndarray) – Per-unit costs for conventional generators.
net_load (np.ndarray) – Net load (MW) for the entire system (summed over all zones).
SOC_old (np.ndarray) – Previous hour’s state-of-charge for each ESS (MWh).
ess_pmax (np.ndarray) – Maximum power output for each ESS.
ess_eff (np.ndarray) – Round-trip efficiency for each ESS.
disch_cost (np.ndarray) – Discharge cost for each ESS.
ch_cost (np.ndarray) – Charge cost for each ESS.
- Returns:
A 2-element tuple containing:
load_curt (float): Total load curtailment (MW).
SOC_old (np.ndarray): Updated state-of-charge for each ESS.
- Return type:
tuple
- OutageAnalysis(var_s)¶
Identifies the start and end of each outage (load-curtailed period) from the binary LOL array and calculates their durations.
- Parameters:
var_s (dict) – Dictionary of sample-specific tracking variables (e.g., “label_LOLF”).
- Returns:
1D array of outage durations (in hours).
- Return type:
np.ndarray
- OutageHeatMap(LOL_track, size, samples, main_folder)¶
Aggregates hourly loss-of-load data into a monthly/hourly matrix and writes the percentage of load-loss hours by month/hour to a CSV file. Can be used later for creating heatmaps.
- Parameters:
LOL_track (np.ndarray) – 4D array of shape (size, samples, 365, 24) representing the LOL states.
size (int) – Total number of MPI processes.
samples (int) – Number of Monte Carlo samples.
main_folder (str) – Directory path where results (CSV/plots) are saved.
- Returns:
None
- Return type:
None
- ParallelProcessing(indices, LOL_track, comm, rank, size, samples, sim_hours)¶
Gathers reliability indices and the LOL tracker from all MPI processes to compute average indices over all ranks. Optionally saves final results and calls
OutageHeatMap()
if a full-year simulation is run.- Parameters:
indices (dict) – Dictionary of reliability indices for the local rank.
LOL_track (np.ndarray) – 2D array of shape (samples, hours) tracking LOL states for the local rank.
comm (mpi4py.MPI.Comm) – MPI communicator object.
rank (int) – MPI rank of this process.
size (int) – Total number of MPI processes.
samples (int) – Number of Monte Carlo samples performed.
sim_hours (int) – Number of hours in each sample (e.g., 8760).
- Returns:
If rank=0, a dictionary containing aggregated reliability indices (LOLP, EUE, etc.) across all ranks, else returns None.
- Return type:
dict or None
- SolarPower(n, nz, s_zone_no, solar_prob, s_profiles, s_sites, s_max)¶
Determines solar power output for each zone based on a randomly selected cluster/day/hour profile.
- Parameters:
n (int) – Current hour in the overall MCS simulation.
nz (int) – Number of zones.
s_zone_no (np.ndarray) – Zone indices for each solar site.
solar_prob (np.ndarray) – Array of cluster probabilities (rows = clusters, columns = months).
s_profiles (list[np.ndarray]) – List of 3D arrays, each containing daily solar profiles for a cluster (dimensions: [days, 24 hours, sites]).
s_sites (int) – Number of solar sites.
s_max (np.ndarray) – Maximum capacity (MW) of each solar site.
- Returns:
A 2D NumPy array of shape (24, nz), giving solar generation (MW) for each zone over 24 hours. Only the row corresponding to hour n%24 is relevant at time n, but the entire 2D block is returned for convenience.
- Return type:
np.ndarray
- TrackLOLStates(load_curt, BMva, var_s, LOL_track, s, n)¶
Records whether load was curtailed at the current hour, and logs loss-of-load days, frequencies, etc.
- Parameters:
load_curt (float) – The amount of load curtailment (MW).
BMva (float) – System base power (MVA) for consistent unit conversions.
var_s (dict) – Dictionary of temporary simulation variables (e.g., curtailment array, LOL day counts).
LOL_track (np.ndarray) – 2D array (shape: [samples, hours]) tracking which hours had loss of load.
s (int) – Current Monte Carlo sample index.
n (int) – Current hour index.
- Returns:
A 2-element tuple containing:
var_s (dict): Updated dictionary of simulation variables.
LOL_track (np.ndarray): Updated array marking loss-of-load hours.
- Return type:
tuple
- UpdateIndexArrays(indices_rec, var_s, sim_hours, s)¶
Updates reliability index accumulators (LOLP, EUE, EPNS, LOLE, etc.) after each sample is completed.
- Parameters:
indices_rec (dict) – Dictionary that stores reliability indices across samples.
var_s (dict) – Dictionary of sample-specific tracking variables (curtailment array, LOL states, etc.).
sim_hours (int) – Number of hours in the current simulation (e.g., 8760 for a year).
s (int) – Current sample index.
- Returns:
indices_rec (dict): Updated dictionary containing reliability index arrays for all samples.
- Return type:
dict
- WindPower(nz, w_sites, zone_no, w_classes, r_cap, current_w_class, tr_mats, p_class, w_turbines, out_curve2, out_curve3)¶
Computes wind power generation by randomly transitioning wind speed classes, then mapping each class to a turbine power output.
- Parameters:
nz (int) – Number of zones in the system.
w_sites (int) – Number of wind farm sites.
zone_no (np.ndarray) – Zone indices for each wind site.
w_classes (int) – Total number of wind speed classes used.
r_cap (np.ndarray) – Rated capacities (MW) of wind turbines at each site.
current_w_class (np.ndarray) – Current wind speed class for each site (1D array).
tr_mats (np.ndarray) – 3D array of transition rate matrices for each site (dimensions: [site, w_classes, w_classes]).
p_class (np.ndarray) – Array specifying the power curve classification type (e.g., 2 or 3) for each site.
w_turbines (np.ndarray) – Number of turbines at each site.
out_curve2 (np.ndarray) – Power output curve for class 2 turbines (indexed by wind speed class).
out_curve3 (np.ndarray) – Power output curve for class 3 turbines (indexed by wind speed class).
- Returns:
A 2-element tuple containing:
w_zones (np.ndarray): Wind generation in each zone (size = nz).
current_w_class (np.ndarray): Updated wind speed classes for the next hour.
- Return type:
tuple
- capacities(nl, pmax, pmin, ess_pmax, ess_pmin, cap_trans)¶
Constructs arrays of maximum and minimum capacities for generators, lines, and ESS for use in the MCS.
- Parameters:
nl (int) – Number of transmission lines.
pmax (np.ndarray) – Maximum capacities (MW) of each generator.
pmin (np.ndarray) – Minimum capacities (MW) of each generator.
ess_pmax (np.ndarray) – Maximum power outputs (MW) for each ESS.
ess_pmin (np.ndarray) – Minimum power outputs (MW) for each ESS.
cap_trans (np.ndarray) – Transmission capacities (MW) for each line.
- Returns:
A 2-element tuple containing:
cap_max (np.ndarray): Concatenated maximum capacities (generators + lines + ESS).
cap_min (np.ndarray): Concatenated minimum capacities (generators + lines + ESS).
- Return type:
tuple
- reltrates(MTTF_gen, MTTF_trans, MTTR_gen, MTTR_trans, MTTF_ess, MTTR_ess)¶
Computes repair and failure rates for generators, transmission lines, and ESS.
- Parameters:
MTTF_gen (np.ndarray) – Mean time to failure for generators (hours).
MTTF_trans (np.ndarray) – Mean time to failure for transmission lines (hours).
MTTR_gen (np.ndarray) – Mean time to repair for generators (hours).
MTTR_trans (np.ndarray) – Mean time to repair for transmission lines (hours).
MTTF_ess (np.ndarray) – Mean time to failure for energy storage systems (hours).
MTTR_ess (np.ndarray) – Mean time to repair for energy storage systems (hours).
- Returns:
A 2-element tuple containing:
mu_tot (np.ndarray): Repair rates (1/MTTR) for all components (gen, trans, ESS).
lambda_tot (np.ndarray): Failure rates (1/MTTF) for all components.
- Return type:
tuple
- updateSOC(ng, nl, current_cap, ess_pmax, ess_duration, ess_socmax, ess_socmin, SOC_old)¶
Adjusts the state-of-charge (SOC) for storage units to reflect any failures/repairs that reduce or restore capacity.
- Parameters:
ng (int) – Number of generators.
nl (int) – Number of lines.
current_cap (dict) – Dictionary of current max and min capacities (from
NextState()
).ess_pmax (np.ndarray) – Original maximum power outputs for ESS (MW).
ess_duration (np.ndarray) – Duration (hours) of each ESS at rated power.
ess_socmax (np.ndarray) – Maximum SOC fraction for each ESS.
ess_socmin (np.ndarray) – Minimum SOC fraction for each ESS.
SOC_old (np.ndarray) – Previous SOC values (in MWh).
- Returns:
A 3-element tuple containing:
ess_smax (np.ndarray): Maximum allowable SOC (in MWh) after accounting for failures/repairs.
ess_smin (np.ndarray): Minimum allowable SOC (in MWh).
SOC_old (np.ndarray): Updated SOC for each ESS.
- Return type:
tuple