|
| 1 | +# Power Flow Task |
| 2 | + |
| 3 | +The Power Flow task solves the fundamental problem of determining the steady-state operating conditions of a power system. Given load demands and generator setpoints, it computes voltage magnitudes, voltage angles, and power flows throughout the network. |
| 4 | + |
| 5 | +## Overview |
| 6 | + |
| 7 | +Power Flow (also known as Load Flow) analysis is essential for power system planning and operation. It determines: |
| 8 | + |
| 9 | +- **Voltage profiles**: Magnitude and angle at each bus |
| 10 | +- **Power flows**: Active and reactive power on transmission lines |
| 11 | +- **Power injections**: Net power generation/consumption at buses |
| 12 | +- **System losses**: Total active and reactive power losses |
| 13 | + |
| 14 | +The `PowerFlowTask` extends the `ReconstructionTask` to include physics-based power balance evaluation and comprehensive metrics for different bus types. |
| 15 | + |
| 16 | +## Key Features |
| 17 | + |
| 18 | +- **Physics-based validation**: Computes power balance errors (PBE) to verify physical consistency |
| 19 | +- **Bus type differentiation**: Separate metrics for PQ, PV, and REF buses |
| 20 | +- **Distributed training support**: Handles multi-GPU training with proper metric aggregation |
| 21 | +- **Detailed predictions**: Provides per-bus predictions with residuals for analysis |
| 22 | +- **Comprehensive reporting**: Generates CSV reports and correlation plots |
| 23 | + |
| 24 | +## PowerFlowTask |
| 25 | + |
| 26 | +::: gridfm_graphkit.tasks.pf_task.PowerFlowTask |
| 27 | + |
| 28 | +## Metrics |
| 29 | + |
| 30 | +The Power Flow task computes the following metrics during testing: |
| 31 | + |
| 32 | +### Power Balance Metrics |
| 33 | +- **Active Power Loss (MW)**: Mean absolute active power residual across all buses |
| 34 | +- **Reactive Power Loss (MVar)**: Mean absolute reactive power residual across all buses |
| 35 | +- **PBE Mean**: Mean Power Balance Error magnitude across all buses (√(P² + Q²)) |
| 36 | +- **PBE Max**: Maximum Power Balance Error across all buses |
| 37 | + |
| 38 | +### Prediction Accuracy (RMSE) |
| 39 | +Computed separately for each bus type (PQ, PV, REF): |
| 40 | +- **Voltage Magnitude (Vm)**: p.u. |
| 41 | +- **Voltage Angle (Va)**: radians |
| 42 | +- **Active Power Generation (Pg)**: MW |
| 43 | +- **Reactive Power Generation (Qg)**: MVar |
| 44 | + |
| 45 | +### Residual Statistics (when verbose=True) |
| 46 | +For each bus type (PQ, PV, REF) and power type (P, Q): |
| 47 | +- Mean residual per graph |
| 48 | +- Maximum residual per graph |
| 49 | + |
| 50 | +## Bus Types |
| 51 | + |
| 52 | +The task evaluates performance separately for three bus types: |
| 53 | + |
| 54 | +- **PQ Buses**: Load buses with specified active and reactive power demand |
| 55 | +- **PV Buses**: Generator buses with specified active power and voltage magnitude |
| 56 | +- **REF Buses**: Reference/slack buses that balance the system |
| 57 | + |
| 58 | +## Power Balance Error (PBE) |
| 59 | + |
| 60 | +The Power Balance Error is a critical metric that measures how well predictions satisfy Kirchhoff's laws: |
| 61 | + |
| 62 | +$$ |
| 63 | +\text{PBE} = \sqrt{(\Delta P)^2 + (\Delta Q)^2} |
| 64 | +$$ |
| 65 | + |
| 66 | +where: |
| 67 | +- $\Delta P$ = Active power residual (generation - demand - losses) |
| 68 | +- $\Delta Q$ = Reactive power residual (generation - demand - losses) |
| 69 | + |
| 70 | +Lower PBE values indicate better physical consistency of the predictions. |
| 71 | + |
| 72 | +## Outputs |
| 73 | + |
| 74 | +### CSV Reports |
| 75 | +Two CSV files are generated per test dataset: |
| 76 | + |
| 77 | +1. **`{dataset}_RMSE.csv`**: RMSE metrics by bus type |
| 78 | + - Columns: Metric, Pg (MW), Qg (MVar), Vm (p.u.), Va (radians) |
| 79 | + - Rows: RMSE-PQ, RMSE-PV, RMSE-REF |
| 80 | + |
| 81 | +2. **`{dataset}_metrics.csv`**: Power balance metrics |
| 82 | + - Avg. active res. (MW) |
| 83 | + - Avg. reactive res. (MVar) |
| 84 | + - PBE Mean |
| 85 | + - PBE Max |
| 86 | + |
| 87 | +### Visualizations (when verbose=True) |
| 88 | + |
| 89 | +1. **Residual Histograms**: Distribution of power balance residuals by bus type (PQ, PV, REF) |
| 90 | +2. **Feature Correlation Plots**: Predictions vs. targets for Vm, Va, Pg, Qg by bus type |
| 91 | + |
| 92 | +### Prediction Output |
| 93 | + |
| 94 | +The `predict_step` method returns detailed per-bus information: |
| 95 | + |
| 96 | +```python |
| 97 | +{ |
| 98 | + 'scenario': scenario IDs, |
| 99 | + 'bus': bus indices, |
| 100 | + 'pd_mw': active power demand, |
| 101 | + 'qd_mvar': reactive power demand, |
| 102 | + 'vm_pu_target': target voltage magnitude, |
| 103 | + 'va_target': target voltage angle, |
| 104 | + 'pg_mw_target': target active power generation, |
| 105 | + 'qg_mvar_target': target reactive power generation, |
| 106 | + 'is_pq': PQ bus indicator, |
| 107 | + 'is_pv': PV bus indicator, |
| 108 | + 'is_ref': REF bus indicator, |
| 109 | + 'vm_pu': predicted voltage magnitude, |
| 110 | + 'va': predicted voltage angle, |
| 111 | + 'pg_mw': predicted active power generation, |
| 112 | + 'qg_mvar': predicted reactive power generation, |
| 113 | + 'active res. (MW)': active power residual, |
| 114 | + 'reactive res. (MVar)': reactive power residual, |
| 115 | + 'PBE': power balance error magnitude |
| 116 | +} |
| 117 | +``` |
| 118 | + |
| 119 | +## Configuration Example |
| 120 | + |
| 121 | +```yaml |
| 122 | +task: |
| 123 | + name: PowerFlow |
| 124 | + verbose: true |
| 125 | + |
| 126 | +training: |
| 127 | + batch_size: 32 |
| 128 | + epochs: 100 |
| 129 | + losses: ["MaskedMSE", "PBE"] |
| 130 | + loss_weights: [0.01, 0.99] |
| 131 | + |
| 132 | +optimizer: |
| 133 | + name: Adam |
| 134 | + lr: 0.001 |
| 135 | +``` |
| 136 | +
|
| 137 | +## Physics-Based Constraints |
| 138 | +
|
| 139 | +The task uses specialized layers to compute physical quantities: |
| 140 | +
|
| 141 | +- **`ComputeBranchFlow`**: Calculates active (Pft) and reactive (Qft) power flows on branches using the power flow equations |
| 142 | +- **`ComputeNodeInjection`**: Aggregates branch flows to compute net power injections at each bus |
| 143 | +- **`ComputeNodeResiduals`**: Computes power balance violations by comparing injections with generation and demand |
| 144 | + |
| 145 | +These layers ensure that predictions are evaluated not only on accuracy but also on their adherence to fundamental power system physics. |
| 146 | + |
| 147 | +## Distributed Training |
| 148 | + |
| 149 | +The PowerFlowTask includes special handling for distributed training: |
| 150 | + |
| 151 | +- **Metric aggregation**: Uses `sync_dist=True` to properly aggregate metrics across GPUs |
| 152 | +- **Verbose output gathering**: Collects test outputs from all ranks to rank 0 for complete visualization |
| 153 | +- **Max reduction for PBE Max**: Uses `reduce_fx="max"` to find the global maximum PBE across all processes |
| 154 | + |
| 155 | +## Usage |
| 156 | + |
| 157 | +The Power Flow task is automatically selected when you specify `task.name: PowerFlow` in your YAML configuration file. The task: |
| 158 | + |
| 159 | +1. Performs forward pass through the model |
| 160 | +2. Inverse normalizes predictions and targets |
| 161 | +3. Computes branch flows using power flow equations |
| 162 | +4. Calculates power balance residuals and PBE |
| 163 | +5. Evaluates metrics separately for each bus type |
| 164 | +6. Generates comprehensive reports and visualizations |
| 165 | +7. Provides detailed per-bus predictions for analysis |
| 166 | + |
| 167 | +## Related |
| 168 | + |
| 169 | +- [Optimal Power Flow Task](optimal_power_flow.md): For optimization-based power flow with economic objectives |
| 170 | +- [State Estimation Task](state_estimation.md): For state estimation from noisy measurements |
| 171 | +- [Feature Reconstruction](feature_reconstruction.md): Base reconstruction task |
0 commit comments