Skip to content

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

12 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Python License Status PyTorch PyG

PI-GAT-TCN

Physics-Informed Graph Attention Network with Temporal Convolutional Encoder for Multi-Node Distribution Grid State Forecasting under Solar PV Uncertainty

TL;DR: We hypothesized that physics-informed graph neural networks would outperform simple temporal models for grid state forecasting. We were wrong. This repository documents both the hypothesis and the extensive ablation study that disproved it, ultimately finding that LSTM with simple neighbor averaging beats all complex architectures on this task.


Table of Contents


Summary

This thesis investigates whether physics-informed graph neural networks can improve multi-node distribution grid state forecasting under solar PV uncertainty. The answer, after extensive experimentation, is nuanced but largely negative for the specific conditions studied.

The Hypothesis

We proposed that combining:

  1. Graph Attention Networks (GAT) to capture spatial coupling between grid buses
  2. Temporal Convolutional Networks (TCN) for temporal dynamics
  3. Physics constraints (Kirchhoff's laws) embedded in the loss function

...would outperform purely temporal models like LSTM.

The Reality

Voltage MAE Ranking

The simplest hybrid approach (LSTM + neighbor-averaged features) achieved the best results. Complex attention mechanisms and physics constraints either provided no benefit or actively hurt performance.


The Journey: From Hypothesis to Reality

Phase 1: The Original Vision

We designed PI-GAT-TCN with these architectural innovations:

                    Original PI-GAT-TCN Architecture

    +-------------------------------------------------------------+
    |                  Forecast Output Head                        |
    |              V, P, Q at all 33 nodes (t+1)                  |
    +-----------------------------+-------------------------------+
                                  |
    +-----------------------------v-------------------------------+
    |              Physics-Informed Loss Layer                     |
    |     L = L_forecast + lambda_1*L_KCL + lambda_2*L_PF         |
    +-----------------------------+-------------------------------+
                                  |
    +-----------------------------v-------------------------------+
    |               TCN Temporal Encoder                           |
    |       Dilated causal convolutions [1, 2, 4, 8]              |
    +-----------------------------+-------------------------------+
                                  |
    +-----------------------------v-------------------------------+
    |            Susceptance-Aware GAT Layers                      |
    |        alpha_ij = softmax(MLP([h_i || h_j || B_ij]))        |
    +-----------------------------+-------------------------------+
                                  |
    +-----------------------------v-------------------------------+
    |                  IEEE 33-Bus Graph                           |
    |            33 nodes, 32 branches, radial                     |
    +-------------------------------------------------------------+

Initial Results: PI-GAT-TCN with physics loss performed 4-5x worse than a simple LSTM.

Phase 2: Diagnostic Experiments

When the original model failed, we conducted systematic ablation:

Experiment Hypothesis Result
GAT+TCN (no physics) Physics loss is the problem Still 3x worse than LSTM
Smaller GAT+TCN Model is over-parameterized Still 8x worse than LSTM
LSTM+Graph Hybrid Simple graph features might help Best results achieved
PI-GAT-TCN with V-drop loss Different physics formulation Training collapsed

Key Discovery: The problem wasn't just the physics loss. GAT attention itself hurts performance on small, fixed-topology radial networks.

Phase 3: Physics-Informed LSTM+Graph

Given that LSTM+Graph was our best architecture, we tested three ways to add physics information:

Physics Approaches Comparison

Results:

  • Approach 1 (Physics Features): Slight improvement in P/Q, slight degradation in V
  • Approach 2 (Soft KCL Loss): No improvement over baseline
  • Approach 3 (Hard Projection): Mathematically invalid for radial networks (see The Physics Loss Challenge)

Model Zoo

This repository implements 10 model variants:

Model Type Description Performance
LSTMBaseline Temporal 2-layer LSTM, no graph Good
GCNBaseline Spatial Graph convolutional network Poor
GATBaseline Spatial Graph attention network Poor
GATTCNModel Spatiotemporal GAT + TCN encoder Moderate
PIGATTCNModel Physics-informed GAT + TCN + physics loss Poor
PIGATTCNVdrop Physics-informed GAT + TCN + voltage drop loss Failed
LSTMGraphHybrid Hybrid LSTM + neighbor features Best
LSTMGraphPhysFeatures Physics-informed LSTM+Graph + V_drop, KCL features Good
LSTMGraphKCLLoss Physics-informed LSTM+Graph + soft KCL loss Good
LSTMGraphKCLProj Physics-informed LSTM+Graph + KCL projection N/A*

*KCL projection is mathematically invalid for radial networks and was disabled.


Results

Full Test Set Performance

MAE Comparison

Model MAE V (pu) MAE P (kW) MAE Q (kVAR) Parameters
Persistence Baseline 0.000045 - - -
LSTM+Graph Hybrid 0.000361 0.398 0.250 203,651
LSTM+Graph PhysFeatures 0.000418 0.363 0.236 204,675
LSTM+Graph KCL Loss 0.000428 0.418 0.253 203,651
LSTM Baseline 0.000450 0.657 0.387 201,603
GAT+TCN 0.001631 2.284 1.830 288,707
PI-GAT-TCN 0.002256 3.139 2.130 297,715
GCN Baseline 0.002544 6.438 6.650 8,899
GAT Baseline 0.003320 15.140 10.148 85,123

Performance vs Complexity

Performance vs Complexity

Radar Comparison

Radar Comparison

Stress Test: High PV Ramp Periods (Top 20% Most Volatile Hours)

Model MAE V (pu) MAE P (kW) Change from Full
LSTM+Graph Hybrid 0.000362 0.410 +3.2% P (degrades)
LSTM+Graph PhysFeatures 0.000415 0.374 +3.0% P (degrades)
LSTM Baseline 0.000453 0.677 +3.1% P (degrades)
GAT+TCN 0.001554 2.963 -2.1% P (improves)
PI-GAT-TCN 0.002302 3.073 -2.1% P (improves)

Observation: Graph-based models show better generalization under stress, but their absolute performance is still worse than temporal models.


Key Findings

Finding 1: Simple Neighbor Averaging Beats Complex Attention

Simple Wins

Why? On a small radial network with fixed topology:

  • There's not enough diversity for attention to learn meaningful patterns
  • Uniform averaging is near-optimal when all neighbors matter equally
  • Attention adds noise rather than extracting signal

Finding 2: Physics Constraints Don't Help (In This Setting)

Physics Approach Implementation Outcome
Soft KCL loss L_total = L_forecast + lambda * L_KCL No improvement
Physics features V_drop, KCL residual as inputs Marginal P/Q improvement
Hard projection P_proj = P - A_pinv @ (A @ P) Mathematically invalid

Why soft constraints failed:

  • The base model (LSTM+Graph) already predicts values that approximately satisfy physics
  • Adding physics loss provides redundant gradients
  • LRA balancing (Wang et al. 2021) couldn't find a lambda that helped

Why hard projection failed:

  • For radial networks, the incidence matrix A is full rank (32x32, rank 32)
  • This means A_pinv @ A = I (identity)
  • So P_proj = P - A_pinv @ A @ P = P - P = 0
  • The projection collapses all predictions to zero!

Finding 3: Temporal Context Dominates at Hourly Resolution

At hourly sampling, grid states are highly autocorrelated:

Hour t-23  t-22  t-21  ...  t-2   t-1   t    | t+1 (predict)
+----+----+----+     +----+----+----+    +----+
|0.99|0.99|0.98| ... |1.00|1.00|1.00|--->|1.00|
+----+----+----+     +----+----+----+    +----+

Persistence baseline achieves MAE V = 0.000045 pu
LSTM learns small corrections on top of this pattern.

Finding 4: Graph Models Generalize Better to Volatility

Despite worse absolute performance, graph models don't degrade under PV volatility. This suggests spatial modeling becomes valuable at higher temporal resolution or under more extreme conditions.


The Physics Loss Challenge

Why Physics-Informed Training is Hard for Distribution Grids

We attempted five different physics loss formulations, all of which failed:

Attempt 1: Raw Impedance KCL

# WRONG: Unit mismatch
L_KCL = sum(Y @ V - I)  # Y in Siemens, V in per-unit

Problem: Mixing raw electrical units with normalized ML quantities.

Attempt 2: Per-Unit KCL

# CORRECT units, but gradients too small
Y_pu = Y * Z_base
L_KCL = sum(Y_pu @ V_pu - I_pu)

Problem: KCL mismatch is tiny (~0.001 pu), swamped by forecast loss.

Attempt 3: Line-Loss-Corrected KCL with LRA

# Sophisticated balancing
P_loss = G_pu * (V_i - V_j)**2
lambda = (1 - alpha) * lambda + alpha * (L_forecast / L_physics)

Problem: Lambda either explodes or goes to zero; no stable region.

Attempt 4: Voltage Drop Loss

# Enforce V_drop = (R*P + X*Q) / V
V_drop_expected = linearized_vdrop(R, X, P, Q, V)
L_vdrop = MSE(V_drop_actual, V_drop_expected)

Problem: Training collapsed immediately (gradients too large).

Attempt 5: KCL Projection (Hard Constraint)

# Project onto KCL-feasible manifold
P_proj = P - A_pinv @ A @ P

Problem: Mathematically invalid for radial networks (A is full rank).

The Root Cause

The unit conversion pipeline from OpenDSS through per-unit to z-score normalization creates opportunities for error at every step. Getting meaningful physics gradients requires perfect consistency across:

  • Base values (S_base, V_base, Z_base)
  • Per-unit conversion
  • Z-score normalization
  • Loss computation
  • Gradient scaling

One mistake anywhere = meaningless gradients.


Lessons Learned

For Researchers

  1. Simpler is often better. Before designing complex architectures, establish strong baselines. A well-tuned LSTM might be hard to beat.

  2. Graph attention needs diversity. GAT excels when different neighbors should receive different attention. On fixed radial topologies, uniform averaging suffices.

  3. Physics-informed ML is hard. Getting units, scales, and gradients right for electrical networks requires domain expertise and careful validation.

  4. Negative results are valuable. This thesis documents what doesn't work, saving future researchers from the same pitfalls.

For Practitioners

  1. Start with LSTM + simple features. For hourly distribution grid forecasting, LSTM with neighbor-averaged features is a strong baseline.

  2. Graph models may help under volatility. If operating in high-PV-ramp conditions, consider spatiotemporal models despite higher complexity.

  3. Don't blindly add physics constraints. Physics loss can hurt if the base model already approximates physics or if the constraint formulation is flawed.

What We Would Do Differently

  1. Higher temporal resolution. 15-minute or 5-minute data would increase spatial signal.
  2. Meshed network topology. KCL projection works for meshed networks with redundant paths.
  3. More careful physics validation. Unit-test each component of the physics pipeline independently.
  4. Probabilistic forecasting. Point forecasts may not need physics; uncertainty might.

Dataset

IEEE 33-Bus with Solar PV

IEEE 33-Bus Diagram

Data Pipeline

NASA POWER API --> PV Model --> OpenDSS --> PyTorch Dataset
 (West Java         (P_pv =      (AC power    (V, P, Q per
  hourly GHI)       eta*A*GHI)    flow)        node, 24h windows)
Property Value
Time Range Full year 2023
Resolution 1 hour
Location West Java, Indonesia
Nodes 33 buses
Edges 32 branches (radial)
PV Nodes Nodes 6, 14, 21
Features V, P, Q, is_pv, pv_output
Train/Val/Test 70% / 15% / 15%

Installation and Usage

Setup

# Clone repository
git clone https://github.com/chairulridjaal/pi-gat-tcn.git
cd pi-gat-tcn

# Create virtual environment
python -m venv venv
source venv/bin/activate  # Linux/Mac
venv\Scripts\activate     # Windows

# Install dependencies
pip install -r requirements.txt

Generate Dataset

python data/data_pipeline.py

Train Models

# Best model (recommended)
python src/train.py --config configs/exp3_lstm_graph_hybrid.yaml

# Physics-informed variants
python src/train.py --config configs/lstm_graph_phys_features.yaml
python src/train.py --config configs/lstm_graph_kcl_loss.yaml

# Original ablation ladder
python src/train.py --config configs/lstm.yaml
python src/train.py --config configs/gat_tcn.yaml
python src/train.py --config configs/pi_gat_tcn.yaml

Evaluate

python src/evaluate.py --experiment experiments/<run_name>

Regenerate Charts

python generate_charts.py

Project Structure

pi-gat-tcn/
├── assets/                     # Generated charts for README
├── configs/                    # Training configurations
│   ├── lstm.yaml
│   ├── gat_tcn.yaml
│   ├── pi_gat_tcn.yaml
│   ├── exp3_lstm_graph_hybrid.yaml      # Best config
│   ├── lstm_graph_phys_features.yaml
│   ├── lstm_graph_kcl_loss.yaml
│   └── lstm_graph_kcl_proj.yaml
├── data/
│   ├── raw/                    # IEEE 33-bus DSS file, irradiance
│   ├── processed/              # Processed tensors
│   └── data_pipeline.py        # Data generation script
├── models/
│   ├── lstm_baseline.py
│   ├── gcn_baseline.py
│   ├── gat_baseline.py
│   ├── gat_tcn.py
│   ├── pi_gat_tcn.py
│   ├── lstm_graph_hybrid.py          # Best model
│   ├── lstm_graph_phys_features.py   # Physics features
│   ├── lstm_graph_kcl_loss.py        # Soft KCL loss
│   └── lstm_graph_kcl_proj.py        # KCL projection (disabled)
├── src/
│   ├── train.py
│   ├── evaluate.py
│   ├── dataset.py
│   ├── metrics.py
│   └── run_experiments.py
├── experiments/                # Training logs and checkpoints
├── generate_charts.py          # Chart generation script
├── compute_phys_stats.py       # Physics feature normalization
├── requirements.txt
├── LICENSE
└── README.md

Limitations and Acknowledgments

Implementation Limitations

  1. Hourly resolution limits temporal variability. At 1-hour sampling, consecutive states are nearly identical (persistence MAE V = 0.000045 pu). Higher resolution (15-min, 5-min) would test spatial models more fairly.

  2. Constant load profile. The IEEE 33-bus base case uses static loads, eliminating spatial heterogeneity that exists in real feeders.

  3. Single location, single year. Dataset uses 2023 NASA POWER data for West Java only. Geographic and inter-annual diversity are not captured.

  4. Synthetic data only. While physically grounded via OpenDSS, real-world measurement noise and operational constraints are absent.

Knowledge Limitations (Author's Acknowledgment)

I acknowledge that some negative results may stem from my own limitations:

  1. Physics loss implementation. Five formulations failed; a more experienced researcher might find a working approach.

  2. Hyperparameter tuning. Graph models may perform better with different hyperparameters than those explored.

  3. KCL projection for radial networks. The mathematical proof that projection fails is sound, but there may be alternative hard constraint formulations I didn't consider.

  4. Unit conversion pipeline. Ensuring consistent per-unit conversion from OpenDSS through loss computation is error-prone; subtle bugs may remain.

This thesis prioritizes transparency about what worked and what didn't, including failures that might be resolved by others.


References

Core Methods

  1. Graph Attention Networks (GAT) Velickovic, P., Cucurull, G., Casanova, A., Romero, A., Lio, P., & Bengio, Y. (2018). Graph Attention Networks. ICLR 2018.

  2. Temporal Convolutional Networks (TCN) Bai, S., Kolter, J. Z., & Koltun, V. (2018). An Empirical Evaluation of Generic Convolutional and Recurrent Networks for Sequence Modeling. arXiv:1803.01271.

  3. Physics-Informed Neural Networks (PINNs) Raissi, M., Perdikaris, P., & Karniadakis, G. E. (2019). Physics-informed neural networks: A deep learning framework for solving forward and inverse problems involving nonlinear partial differential equations. Journal of Computational Physics, 378, 686-707.

  4. Learning Rate Annealing for PINNs Wang, S., Teng, Y., & Perdikaris, P. (2021). Understanding and Mitigating Gradient Flow Pathologies in Physics-Informed Neural Networks. SIAM Journal on Scientific Computing, 43(5), A3055-A3081.

Power Systems

  1. IEEE 33-Bus Test Feeder Baran, M. E., & Wu, F. F. (1989). Network reconfiguration in distribution systems for loss reduction and load balancing. IEEE Transactions on Power Delivery, 4(2), 1401-1407.

  2. OpenDSS Dugan, R. C., & Montenegro, D. (2020). The Open Distribution System Simulator (OpenDSS). EPRI.

  3. KCLNet: Physics-Informed GNN for Power Flow Donon, B., Clement, R., Donnot, B., Marot, A., Guyon, I., & Schoenauer, M. (2020). Neural Networks for Power Flow: Graph Neural Solver. Electric Power Systems Research, 189, 106547.

Data Sources

  1. NASA POWER Solar Data NASA Langley Research Center POWER Project. (2023). POWER Data Access Viewer. https://power.larc.nasa.gov/

Deep Learning Frameworks

  1. PyTorch Paszke, A., et al. (2019). PyTorch: An Imperative Style, High-Performance Deep Learning Library. NeurIPS 2019.

  2. PyTorch Geometric Fey, M., & Lenssen, J. E. (2019). Fast Graph Representation Learning with PyTorch Geometric. ICLR Workshop on Representation Learning on Graphs and Manifolds.


Citation

If you use this work in your research, please cite:

@misc{nurvikri2026pigattcn,
  title   = {PI-GAT-TCN: Physics-Informed Graph Attention Networks for
             Distribution Grid State Forecasting -- A Negative Result},
  author  = {Mochamad Chairulridjal Nurvikri},
  year    = {2026},
  url     = {https://github.com/chairulridjaal/pi-gat-tcn},
  note    = {Thesis project documenting extensive ablation study finding that
             simple LSTM+Graph hybrid outperforms complex physics-informed
             graph neural networks for hourly distribution grid forecasting}
}

License

This project is licensed under the MIT License - see the LICENSE file for details.


Built with PyTorch, PyTorch Geometric, and OpenDSS.
Solar irradiance data courtesy of NASA POWER.
This thesis documents both successes and failures in the spirit of reproducible science.

About

Physics-Informed Graph Attention Network with Temporal Convolutional Encoder for multi-node distribution grid state forecasting under solar PV uncertainty. First benchmark for V/P/Q forecasting on IEEE 33-bus.

Topics

Resources

Stars

4 stars

Watchers

0 watching

Forks

Releases

Contributors

Languages