Paper · 2025-01-13 · cs.AI
PowerGraph-LLM: Novel Power Grid Graph Embedding and Optimization with Large Language Models
Encodes an IEEE power grid as graph or table text, puts (grid, AC OPF solution) pairs in an LLM prompt or LoRA fine-tuning set, and asks the LLM for the OPF solution as JSON. Fine-tuned Llama-3.1-8B reaches 99.7% valid outputs on 9-bus graph queries (author-reported).
Graph neural networkIn-context learningLow-rank adaptation (LoRA and variants)power-systemsoptimal-power-flowllmin-context-learningloragraph-embedding
AI-compiled by claude-haiku-5-5 on 2026-11-06, not yet reviewed by a human. Every claim cites its source; check it when a detail matters.
In plain words
Working out how much power each generator in an electricity grid should produce, at the lowest cost that still keeps voltages and line limits safe, is a hard optimisation problem. Standard solvers do it, and graph neural networks have been trained to imitate them, but both need a lot of solved examples for each grid size.
This paper asks whether a general-purpose language model can do it instead. The grid is written out as text: either as a graph (the parts and how they connect) or as flat tables of values. Many grids and their solved answers are pasted into the prompt as examples, then a new grid is shown and the model writes out its answer. The authors also fine-tune a smaller open model on the same examples, which makes it much more reliable at producing a valid answer.
The point is that a model can learn the pattern from examples, with no new network designed for the task. The results are promising on small test grids, but the paper is a short letter, and the larger grids and the cost of running these models are only lightly covered.
TL;DR
- Power grids (IEEE test cases) are turned into graph or table text, paired with OPF solutions from a solver, and used as LLM in-context examples or LoRA fine-tuning data §2.
- Off-the-shelf models are weak: gpt-4o-mini is accurate, Llama-3.1-8B is far worse and often returns no parsable JSON §3.2 tab. 1.
- After LoRA fine-tuning on 65,000 pairs, Llama-3.1-8B matches gpt-4o-mini's error range on 9-bus graph queries §3.4 tab. 1.
- No official code was found; every number here is author-reported.
Problem
Solving AC optimal power flow (OPF) is routine but computationally heavy, and the current ML approaches need solver-generated training sets and retraining for each grid size §1. The paper's goal is a method that generalises to new grids from prompts or light fine-tuning, and that supports realistic grid components and constraints, which the authors say earlier LLM work did not §1.
Method
The framework has three parts §2: (1) build the grid's description, (2) generate many grid variants, and (3) solve each variant to get the ground truth. The LLM stage then uses (4) the example pairs as context, (5) the query grid, and (6) the model's answer. A fine-tuning stage (7) turns the same pairs into training data §2 fig. 1.
Grid embedding §2. The starting grid comes from MATPOWER, pandapower or OpenDSS and is converted to a heterogeneous graph with five node types: bus, load, generator, slack and line. Each type has its own feature set, X_b, X_l, X_g, X_s, X_e. New grids are made by mutating these features; for loads, the active and reactive power follow a real profile §2. Test grids in the empirical study perturb loads uniformly by ±20% §3.1.
Ground truth §2. A power flow or OPF solver run on each variant gives generator and slack active/reactive power (Y_g, Y_s) and per-bus voltage magnitude and angle (Y_b).
Two text formats §2. The same features are serialised either as a graph representation (node features and edge connections) or as a tabular representation (features only). The authors note that the tabular form fits more examples in a given context window §2.
Prompt layout §3.1 tab. 2. A system prompt tells the model it is an optimal-power-flow operator returning JSON. It is followed by alternating user and assistant turns: each example input grid, then its solution as JSON. The final user turn holds the query grid, with no solution. In the experiments, 65 example pairs are used and the 66th is the query §3.1.
Scoring §3.1. The answer is parsed as JSON and compared with the solver's output. If no JSON can be read, or values are missing or invalid, the output counts as invalid. The authors state invalid outputs typically occur when the model explains how to solve the problem instead of giving the answer.
LoRA fine-tuning §2 eq. 1. LoRA leaves the base weights frozen and adds a low-rank update to chosen weight matrices:
\Delta W = \frac{\alpha}{r} A \cdot B eq. 1
Here A \in \mathbb{R}^{d \times r}, B \in \mathbb{R}^{r \times k}, r \ll d, k, and \alpha is a scaling factor. Only A and B are trained §2. Each input example is a separate training sample, with the aim of minimising the loss against its solution §2. Each sample contains the system prompt, the problem, and the solution §3.1.
# Build the in-context prompt for one query grid [§3.1] [tab. 2]
# Input: examples (list of (grid_embedding, opf_solution)), query_grid
# Output: list of chat messages
def build_prompt(examples, query_grid):
# System prompt, then one user/assistant turn per example [tab. 2]
messages = [system_message()]
for grid_embedding, opf_solution in examples:
messages.append(user(grid_embedding)) # JSON input
messages.append(assistant(opf_solution)) # JSON output
# The query has no answer [§3.1]
messages.append(user(query_grid))
return messages# Fine-tune one LoRA adapter [§2] [§3.1] [eq. 1]
# Input: pairs of (grid_embedding, opf_solution); rank r; scale alpha
# Output: adapter weights (base model frozen)
def finetune_lora(pairs, r, alpha):
# Freeze base weights; create low-rank factors A and B [eq. 1]
adapter = create_lora_adapter(rank=r, alpha=alpha)
for grid_embedding, opf_solution in pairs:
# One example at a time as its own training sample [§2]
loss = next_token_loss(
model_with(adapter),
prompt=grid_embedding,
target=opf_solution,
)
# Only A and B receive gradients [§2]
update(adapter, loss)
return adapterHyperparameters
| Name | Value | Where | Notes |
|---|---|---|---|
| In-context examples per prompt | 65 pairs | §3.1 | Query is the 66th; 65 is said to fill the context of all models |
| Repetitions | 1,000 | §3.1 | Gives 65,000 context pairs and 1,000 evaluation pairs in total |
| Context window (inference) | 4096 tokens | §3.1 | Ollama v0.5.0 default setup, for Llama models only |
| Quantisation (inference) | Q4_K_M | §3.1 | Llama models only |
| Hardware (inference) | 1× NVIDIA RTX 8000 48GB (8B); 2× for 70B | §3.1 | |
| Base model fine-tuned | Llama-3.1-8B-Instruct | §3.1 | gpt-4o-mini is fine-tuned through the OpenAI API |
| Fine-tuning data | 65,000 pairs | §3.1 | Same pairs as the context set |
| LoRA rank r | 8 | §3.1 | |
| LoRA scale \alpha | 16 | §3.1 | |
| Fine-tuning library | Hugging Face | §3.1 | |
| Fine-tuning hardware | 1× NVIDIA RTX 8000 48GB | §3.1 | |
| Learning rate | not stated | ||
| Epochs, batch size, optimiser | not stated | ||
| LoRA target modules, dropout | not stated | ||
| LLM sampling (temperature, top-p) | not stated | ||
| Test-grid load perturbation | uniform ±20% | §3.1 | IEEE 9-bus; 30-bus grid used only in §3.4 |
Results
Author-reported. Setup: IEEE 9-bus test grids with ±20% load perturbation for the main comparison; a 30-bus grid for the generalisation check; metric is mean squared error (MSE) on generator (GEN), slack (SLACK) and bus (BUS) values, plus the share of valid outputs §3.1 tab. 1. The column header in the table reads "VALID" and the text reports invalid shares, so the values below are the valid share as printed.
Table 1, after LoRA fine-tuning tab. 1:
| Case | LLM | GEN MSE | SLACK MSE | BUS MSE | Valid |
|---|---|---|---|---|---|
| 9-bus | gpt-4o-mini (graph) | 0.018740 | 0.010669 | 0.000269 | 93.1% |
| 9-bus | Llama-8b (graph) | 0.006417 | 0.061813 | 0.000629 | 99.7% |
| 9-bus | Llama-8b (table) | 0.054423 | 0.052320 | 0.001846 | 98.4% |
| 30-bus | Llama-8b (graph) | 0.01807 | 0.016839 | 0.000513 | 89.5% |
Table 1, before fine-tuning (same models) tab. 1:
| Case | LLM | GEN MSE | SLACK MSE | BUS MSE | Valid |
|---|---|---|---|---|---|
| 9-bus | gpt-4o-mini (graph) | 0.205558 | 0.177675 | 0.000806 | 97.7% |
| 9-bus | Llama-8b (graph) | 8461773.406823 | 2213.237469 | 0.074695 | 11.5% |
| 9-bus | Llama-8b (table) | 3.172312 | 1.957585 | 0.001922 | 32.1% |
| 30-bus | Llama-8b (graph) | not reported | not reported | not reported | 0% |
In-context, before fine-tuning §3.2 fig. 2 fig. 3: gpt-4o-mini keeps GEN and SLACK MSE below 0.5 and BUS MSE below 10⁻³ with few invalid outputs. Llama-8B's errors are reported as at least 100 times higher with most outputs invalid. Table representations give lower errors than graphs for both models, and fewer invalid outputs (by 23%, as stated) §3.2. Larger models improve GEN and SLACK error; for BUS error the table form improves with size while the graph form gets worse §3.3 fig. 3.
Fine-tuning §3.4: invalid outputs fall below 2% for the Llama models and rise slightly for gpt-4o-mini. After fine-tuning, graph input beats table input §3.4. The paper states off-the-shelf models fail completely on the 30-bus grid, and that fine-tuned Llama reaches competitive results there §3.4 tab. 1.
Not in the paper: gpt-4o results appear only in the in-context figures §3.1 fig. 3, and no run-to-run variance is given.
Paper vs code
No official code. The paper gives no code link and the arXiv record has none. GitHub searches for "PowerGraph-LLM", "PowerGraphLLM" and "powergraph" returned no repository by the authors. A search scoped to the authors' lab (for SafePowerGraph) was rejected by the API. The predecessor grid tool, SafePowerGraph (arXiv:2407.12421) is cited in §2 but is not this paper's code.
Pitfalls
- Invalid share vs valid share. The table column says "VALID", while the text reports invalid shares. Values match the valid share (e.g. 99.7% valid means 0.3% invalid). The text calls gpt-4o-mini's invalid share a "marginal" increase after fine-tuning, but the table shows valid share fall from 97.7% to 93.1% §3.4 tab. 1.
- Fine-tuning details are missing. Learning rate, epochs, batch size, optimiser, LoRA target modules and dropout are not stated. The training sample format (what is in the loss) is described only as "system prompt, problem, solution" §3.1. Do not assume a default.
- Unstated inference settings. Sampling temperature and top-p are not stated. The 4096-token window applies to the Ollama Llama runs; the token-count check against 65 examples is not described §3.1.
- Numerically extreme baseline. Before fine-tuning, Llama-8B's graph GEN MSE is about 8.5 million tab. 1. Be aware of this when comparing averages across models.
- Small evaluation. Main results use the IEEE 9-bus grid with load-only perturbation §3.1. Only one model is tested on the 30-bus grid §3.4. Generalisation to larger or richer grids (constraints, line limits) is not shown, though the introduction claims realistic components §1.
- Unit and scale of angles. Bus MSE covers voltage magnitude and angle together §3.1. Units and normalisation are not stated.
- Repetition count. "Repeated 1,000 times" could mean 1,000 grids or 1,000 prompts over the same grid pool; the text does not say §3.1.
- Figure numbers. Fig. 4 and Fig. 5 are two captions in one figure environment in the source. They are numbered here in source order; check against the compiled PDF.
- Cost. Each query carries 65 full example grids, so prompts are long and inference is slow on local hardware §3.1. The paper gives no latency or cost numbers.
Lineage
- Builds on: SafePowerGraph, arXiv:2407.12421, for grid representation and mutation §2. LoRA, arXiv:2106.09685, for the fine-tuning method §2 [eq. 1]. Llama 3 herd, arXiv:2407.21783, for the Llama-3.1 models §3.1.
- Compared against: Liu et al. (IEEE TPS 2023) and Ghamizi et al. (PESGM 2024) GNN approaches §1; Yan & Xu (IEEE TPS 2023) LLM-in-the-loop DRL §1; Huang et al. (PESGM 2024), which the authors say covers only a toy economic-dispatch case §1.
- Superseded by: not known from this wiki.
Source and license
Adapted from “PowerGraph-LLM: Novel Power Grid Graph Embedding and Optimization with Large Language Models” by Fabien Bernier, Jun Cao, Maxime Cordy, Salah Ghamizi (arXiv:2501.07639), used under CC BY 4.0. Changes: condensed and restructured for implementation, with tables, equations and algorithms taken from the paper and its code, each cited to its source. Not affiliated with or endorsed by the authors.