PGLearn - An Open-Source Learning Toolkit for Optimal Power Flow

Michael Klamkin, Mathieu Tanneau, Pascal Van Hentenryck · DOI

Introduction

Optimal Power Flow (OPF) serves as the mathematical foundation for modern electricity markets, determining the most cost-effective generator dispatch while adhering to complex physical grid constraints. As the integration of renewable energy sources increases grid volatility, the need for rapid OPF solutions has become paramount. While Machine Learning (ML) offers a promising avenue for accelerating these computations, the field has historically lacked standardization. Researchers often rely on private, small-scale datasets generated with simplistic noise models that fail to reflect real-world grid correlations. This lack of a common benchmark makes it difficult to compare ML architectures fairly and creates a high barrier to entry due to the computational cost of high-quality data generation.

Methodology: A Two-Part Software Ecosystem

To address these challenges, the authors present PGLearn, a comprehensive open-source toolkit designed to bridge the gap between power systems optimization and machine learning. The ecosystem consists of two primary components:

  1. PGLearn.jl (Julia): A robust data generation engine built upon PowerModels.jl and JuMP. It automates the process of solving complex optimization problems—including non-convex AC-OPF, linear DC-OPF, and Second-Order Cone (SOC) relaxations—to produce high-fidelity ground-truth labels.
  2. ML4OPF (PyTorch): A dedicated library for training and evaluating ML models on OPF tasks. It provides specialized layers for enforcing physical constraints and utilities for handling standard power grid data formats.
The PGLearn ecosystem architecture, bridging optimization (PGLearn.jl) and machine learning (ML4OPF).

A key methodological innovation is the correlated demand sampling strategy. Unlike traditional methods that perturb loads independently, PGLearn models demand by combining global regional trends with local fluctuations. This approach ensures that the generated datasets capture a realistic range of operating conditions, reflecting phenomena like regional heatwaves or synchronized industrial activity.

Dataset Characteristics

The PGLearn collection, hosted on Hugging Face, represents a significant scale-up in publicly available power systems data. It includes over 10 million standardized samples across 14 reference networks, ranging from small 14-bus synthetic cases to massive systems with over 24,000 buses (e.g., Midwest24k).

Notably, the dataset provides both primal and dual solutions (Lagrange multipliers). The inclusion of dual variables is critical for research into electricity pricing and for developing "dual optimization proxies" that can provide mathematically guaranteed lower bounds on operational costs. Furthermore, for large-scale systems like the Texas 7k-bus case, the toolkit includes synthetic hourly time-series data interpolated to 5-minute intervals, enabling research into temporal grid dynamics.

Key Insights: The Role of Correlation

A central finding of this work is that independent noise sampling leads to overly simplistic data distributions. Such distributions fail to capture the complex global dynamics inherent in real-world power grids.

Comparison of demand distribution and power flow between correlated and independent sampling strategies.

As shown in the comparative analysis, correlated sampling produces a much broader and more realistic distribution of total demand and branch power flows. Training models on these more complex distributions is essential for developing ML solutions that are robust enough for practical deployment. Furthermore, the authors advocate for standardized metrics beyond simple Mean Squared Error (MSE), such as Distance to Feasible Set and Optimality Gap, to better measure a model's adherence to physical laws and economic efficiency.

Results and Impact

The initial release of the PGLearn dataset required approximately 30,000 CPU-hours of computation—a significant investment that the authors have effectively "subsidized" for the research community. By providing open-access data and open-source tools in both Julia and Python, the project significantly lowers the barrier to entry for ML researchers. The toolkit’s ability to handle "Extra-Large" cases (10k+ buses) demonstrates its scalability and relevance to the challenges faced by real-world Independent System Operators (ISOs).

Limitations and Future Work

While PGLearn marks a major step forward, some limitations remain. The datasets are currently based on synthetic or anonymized snapshots due to security and privacy constraints. Additionally, the current focus is on demand fluctuations and simple $N-1$ contingencies; future iterations aim to incorporate more complex topology changes, such as bus reconfigurations. The authors also plan to expand the toolkit to include market-clearing elements like reserve products and piece-wise linear production curves to further align the datasets with real-world market operations.

Summary updated

BibTeX
@misc{klamkin2025pglearn,
  author = {Michael Klamkin and Mathieu Tanneau and Pascal Van Hentenryck},
  title = {{PGLearn - An Open-Source Learning Toolkit for Optimal Power Flow}},
  year = {2025},
  eprint = {2505.22825},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/2505.22825},
}
Figure