This repository contains the official implementation of the paper “Fast Diffusion with Physics-Correction for ACOPF.” It provides code and resources to reproduce the methods and results presented in the paper. Pre-Print
@article{shekhar2026fast,
title={Fast Diffusion with Physics-Correction for ACOPF},
author={Shekhar, Shashank and Karn, Abhinav and Keshav, Kris and Bansal, Shivam and Pareek, Parikshit},
journal={arXiv preprint arXiv:2602.03020},
year={2026}
}
-
Clone the repository
-
Create and activate a Python virtual environment
python3 -m venv venv
source venv/bin/activate- Install the required packages
pip install -r requirements.txtThis will generate a dataset with 5000 samples for the 6-bus system and save it as actual_data_6.csv:
python main.py --generate-dataset --dataset-samples 5000 --dataset-network case6ww --dataset-save-path actual_data_6.csvThis will train the model using the generated 6-bus dataset and perform DDIM sampling:
python main.py --ppcase case6ww --train --sample --ddim --epochs 100 --batch_size 64 --neurons 4096 --layers 2 --samples 1000 --ddim --dataset-save-path actual_data_6.csv- Adjust
--epochs,--batch_size,--neurons,--layers, and--samplesas needed. - The
--ppcaseargument specifies the pandapower case to use (e.g.,case6ww,case24_ieee_rts,case118).
This will use the best saved model checkpoint and perform DDPM sampling:
python main.py --ppcase case6ww --sample --samples 1000- By default, this will use DDPM sampling. To use DDIM, add
--ddim. - Make sure the checkpoint file (
best_ddim_denoiser.pth) exists from a previous training run.
The example.py script provides a quick way to analyze and visualize the results of your actual and generated datasets. It computes key metrics (KL divergence, Wasserstein distance) and generates comparison plots for selected features and buses.
- Histogram comparison for selected features (customizable in the script)
- Scatter plots for P vs Q and V vs Theta for selected buses
- Buswise KL divergence bar plots for all features
How to use:
- Ensure you have your ground truth and generated CSV files (e.g.,
test_data.csvandgenerated.csv). - Edit the top of
example.pyto select which features/buses to plot, if desired. - Run:
python example.py- You can use any supported pandapower case by changing the
--ppcaseargument. - For other bus systems, adjust the dataset generation and training commands accordingly.
- All outputs and logs will be saved in the current directory by default.
To construct the training data, we repeatedly solve the AC Optimal Power Flow (ACOPF) problem across a wide range of loading scenarios, generator operating limits, and network configurations. Each solved instance provides a ground-truth system state, which is used as a training sample for the diffusion model.
The diffusion model is trained for T = 1000 time steps using a linear noise schedule, with
For inference, we use DDIM sampling with 30 steps and a stochasticity parameter of
The neural network consists of three hidden layers, each with 4096 neurons, and uses the SiLU activation function with Layer Normalization throughout. All experiments are conducted on NVIDIA A100 GPUs.
| Hyperparameter | Value |
|---|---|
| Diffusion steps (T) | 1000 |
| (\beta_{\min}) | |
| (\beta_{\max}) | |
| Noise schedule | Linear |
| Epochs | 700–1000 |
| DDIM steps (inference) | 30 (unless stated otherwise) |
| Stochasticity parameter (\eta) | 0.2 |
| Batch size | 64 |
| Optimizer | AdamW |
| Learning rate | |
| Weight decay | |
| Activation function | SiLU |
| Hidden layers | [4096, 4096, 4096] |
| Normalization | LayerNorm |