Electrical Engineering and Energy | 2026 · 5:3

Research Article · Open Access

End to end prediction of optimal power flow in sustainable power system using physics-informed spatiotemporal graph neural network

Abdul-Majid Issah Malori1, Emmanuel Asuming Frimpong1, Francis Effah Boafo1 Elvis Twumasi1, Peter Asigri1, and Bernard Marfo Adjei1
  • 1 Department of Electrical and Electronic Engineering, Kwame Nkrumah University of Science and Technology, PMB University Post Office. Kumasi, Ashanti Region, Ghana
  • Corresponding author: issahmalori@bolgatu.edu.gh
Submitted: 6 May 2026Accepted: 1 June 2026Online first: 10 June 2026DOI:10.64470/elene.2026.33

Abstract

This paper proposes a physics-informed spatiotemporal graph neural network (PIStGNN) for end-to-end ACOPF prediction in sustainable power systems. The proposed framework embeds physical power flow constraints, grid topology, and temporal dynamics of renewable generation. The model is validated on IEEE 33-, 57-, and 118-bus systems using time-series 60,048 datasets generated in Pandapower. All experiments are implemented in Python and performance are evaluated using prediction accuracy, physical feasibility, and computational efficiency. The results show that system voltage profiles remain within acceptable operational limits of 0.96–1.04 p.u. across all scenarios. The system efficiency analysis reveals that moderate renewable penetration reduces transmission losses, while excessive penetration increases losses due to reverse power flow and congestion in larger systems. The proposed PIStGNN achieves prediction errors on the order of 10⁻² p.u. for voltage magnitude and angle while delivering speedups of up to 10,135× compared with Newton–Raphson-based solvers. Furthermore, physics-informed recurrent graph models achieve minimum uncertainty values of 1.06 × 10⁻³, 2.88 × 10⁻³, and 1.19 × 10⁻³ for the IEEE 33-, 57-, and 118-bus systems, respectively. The results demonstrate that integrating physics-informed learning with spatiotemporal graph modeling provides an efficient surrogate for ACOPF prediction in sustainable power systems.

Keywords: Alternating current optimal power flow, Renewable energy, Reconfiguration, Physics-informed, Spatiotemporal graph neural network.

1. Introduction

The efforts to lower greenhouse gas emissions in modern power grids have intensified due to climate change (Roald, et al., 2023) (Zhou, et al, 2024). It is estimated that one-third of global carbon dioxide emissions is produced by electricity generation (Y. Zhou, et al, 2015) (Xie, et al, 2023) (Lin, et al, 2014). An important step toward power system sustainability is renewable energy sources (Xie, Wei , Li, Dong, & Mei, 2023). However, these sources introduce significant intermittency, nonlinearity, and uncertainty into power system operations (C,. Lowery and M., O’Malley, 2012) (Jordehi, 2018) (Abdi, 2021) (Kaffash, 2022) (Roald, et al., 2023) (Singh & Powar, 2024). Consequently, the rapid growth of renewable integration, dynamic load variations, and topological changes makes conventional techniques struggle with computational scalability of Alternating Current Optimal Power Flow (ACOPF) (Hmida, et al, 2018) (Aravena, et al., 2023). Traditional methods such as Interior Point, Newton–Raphson, and Sequential Quadratic Programming, suffer from slow convergence, and local optimality, particularly in uncertain situations (Lei, et al., 2021).The ACOPF problem has long been a mainstay of power system operation and planning. It determines the optimal dispatch of generation units to achieve specific objective while satisfying power network constraints (Yang, et al, 2017) (Halilbasic, et al, 2018). Significant economic benefits can result from exact ACOPF estimation (Kilwein, et al., 2021).Therefore, there is urgent need to implement efficient ACOPF technique for sustainable power system.

To address computational challenges, the data-driven method provides a promising tool for ACOPF assessment with stochastic renewable energy. These methods for solving the ACOPF problem can be divided into two main groups; End to End (E2E) and learning to optimize (L2O) (Hentenryck, 2021).The application of L2O and E2E learning techniques for ACOPF problem require further in-depth improvement (Hasan, et al, 2020). In modern grid, intermittency, uncertainty and topology changes increase the learning difficulties and the demand for learning samples (Gao, et al, 2024).This limits the efficacy of Euclidean-based models like convolutional neural networks (CNNs) and multilayer perceptrons. These methods suffer from over-smoothing, and poor interpretability (Saffari & Khodayar, 2024). Graph Neural Networks (GNNs) have become a potent tool for modeling grid-structured data in order to address these drawbacks. GNNs naturally capture the spatial dependencies of power systems by representing transmission lines as edges and buses as nodes (Zideh, et al, 2024) (Jalving, et al., 2024). However, of GNNs are efficient for static topology and neglects the dynamic evolution of the power network. Moreover, the spatiotemporal GNNs (StGNNs) models extend traditional GNNs by learning both spatial and temporal dynamics of dynamic systems (Wang, 2023). StGNNs are divided into two subcategories based on their learning strategy: the successive spatiotemporal GNNs architectures treat spatial and temporal learning as separate but sequential processes. The spatial features are extracted using the graph convolutional layers and temporal modeling using recurrent mechanisms. In contrast, simultaneous spatiotemporal GNNs learn spatial and temporal features within a unified framework. Its major limitation is it may not fully capture detailed temporal transitions where chronological time modeling is needed. Power system has a dynamic structure as a result of maintenance operations, faults and planned or unplanned outages. This implies that power system is represented by a dynamic graph topology (Yaniv, et al, 2023). Graphs may be homogeneous (uniform node and edge types) or heterogeneous (distinct node and edge properties), with the latter being ideal for modelling power systems. Buses are categorized into slack (S), generator (PV), and load (PQ) nodes to capture their specific operational roles. The evolution of node and edge features over short time intervals is analyzed by short-term spatiotemporal graph neural networks (StGNNs). The Short term StGNNs model abrupt temporal changes in graph-structured data. There are basically two groups namely; 1D-CNN-based and RNN-based models. The 1D-CNN-based models process longer sequences more effectively but have trouble with uncertain data. The RNN-based StGNNs capture variable-length temporal dependencies.

Furthermore, purely data-driven StGNNs run the risk of breaking basic physical laws like Kirchhoff's current and voltage laws. The physics informed models embed physical constraints directly into the learning process to guarantee feasibility. That notwithstanding physics-informed deep learning for ACOPF formulations is underexplored in literature (Huang & Wang, 2023). Motivated by these gaps, the paper seeks to solve ACOPF problem using PIStGNNs across different renewable penetration levels and networks. The central research hypothesis is “physical regularization with spatiotemporal graph learning improves solution quality and generalization performance”. The null hypothesis assumes that no performance enhancement is achieved with PIStGNN modeling. To ascertain the stated hypotheses, the following research questions are formulated:

  1. How can PIStGNN be designed to learn physics constraints, topology, and renewable variability?

  2. To what extent does PIStGNN improve ACOPF performance metrics relative to classical approaches?

  3. How robust is the PIStGNN models under different renewable penetration levels, and networks?

The proposed technique combines dynamic graph convolution networks (GCNs) with long short-term memory (LSTM) or gated recurrent units (GRU). The dynamic GCN layers captures the electrical topology using adjacency matrix in the graph convolution operation. The LSTM or GRU layers learn variability from renewable generation, load variations, and operational fluctuations. The PIStGNN algorithm is validated using time-series datasets generated in Pandapower on benchmark IEEE 33-, 57-, and 118-bus systems. The remainder of this paper is organized as follows. Section 2 formulates the ACOPF problem and its physical constraints. It also presents the theoretical foundation of the proposed PIStGNN architecture. Lastly the methodological framework and experimental implementation is described. Section 3 analyzes and discusses the experimental results, while Section 4 concludes with key findings and recommendations for future research.

2. Materials and Methods

2.1 Formulating ACOPF problem

Given that the power system network is modeled as graph network with nn buses and mm edges. For each bus ii, voltage magnitude (ViV_{i}), voltage angle (θi\theta_{i}), active power generated (PiGP_{i}^{G}\ ), reactive power generated (QiGQ_{i}^{G}\ ) , active load (PiDP_{i}^{D}) and reactive load (QiDQ_{i}^{D}). PijfP_{ij}^{f}\ and QijfQ_{ij}^{f}\ also denote the active and reactive power flowing from bus ii to bus jj. The admittance between buses ii and jj is gij−jbijg_{ij} - \ jb_{ij} . θij\theta_{ij} represent the shorthand for θi−θj\theta_{i} - \ \theta_{j}\ . In this context buses are categorized into slack (S)(S), generator (PV)(PV), and load (PQ)(PQ) nodes to capture their specific operational roles. Let the power system at time tt be a graph Gt=(Vt,Et)G_{t} = (V_{t},E_{t}) with N=|Vt|N = \left| V_{t} \right| buses and Et=|ℰt|E_{t} = \left| \mathcal{E}_{t} \right| lines. Node features are stacked as Xt∈ℝN×FX_{t} \in \mathbb{R}^{N \times F} and the model predicts ACOPF-related states/controls Ŷt∈ℝN×O{\widehat{Y}}_{t} \in \mathbb{R}^{N \times O} (e.g.,|Vi|,θi,PiG,QiG,PiD,QiD,Pijf,Qijf\left| V_{i} \right|,\ \theta_{i},\ P_{i}^{G},\ Q_{i}^{G},P_{i}^{D},Q_{i}^{D},\ P_{ij}^{f},\ Q_{ij}^{f}\ ). For a temporal window length TT, the input sequence is {Xt−T+1,…,Xt}\{ X_{t - T + 1},\ldots,X_{t}\}.The ACOPF problem is formulated as shown below:

minV,θci(PiG)\min_{V,\theta}{ci(Pi\ G)}\ \
(1)
St PiG=PiD+∑j=1NPijfP_{i}^{G} = P_{i}^{D} + \sum_{j = 1}^{N}P_{ij}^{f}
(2)
QiG=QiD+∑j=1NQijfQ_{i}^{G} = Q_{i}^{D} + \sum_{j = 1}^{N}Q_{ij}^{f}
(3)
Pijf=Vi2gij−ViVj(gijcos(θij)−bijsin(θij))P_{ij}^{f} = V_{i}^{2}g_{ij} - V_{i}V_{j}\left( g_{ij}\cos\left( \theta_{ij} \right) - b_{ij}\sin\left( \theta_{ij} \right) \right)
(4)
Qijf=Vi2bij−ViVj(bijcos(θij)+gijsin(θij))Q_{ij}^{f} = V_{i}^{2}b_{ij} - V_{i}V_{j}\left( b_{ij}\cos\left( \theta_{ij} \right) + g_{ij}\sin\left( \theta_{ij} \right) \right)
(5)
V_i≤Vi≤V¯i{\underline{V}}_{i} \leq V_{i} \leq {\overline{V}}_{i}
(6)
P_iG≤PiG≤P¯iG{\underline{P}}_{i}^{G} \leq P_{i}^{G} \leq {\overline{P}}_{i}^{G}
(7)
Q_iG≤QiG≤Q¯iG{\underline{Q}}_{i}^{G} \leq Q_{i}^{G} \leq {\overline{Q}}_{i}^{G}
(8)
(Pijf)2−(Qijf)2≤(Sijmax)2{(P_{ij}^{f})}^{2} - {(Q_{ij}^{f})}^{2} \leq {(S_{ij}^{\max})}^{2}
(9)

where b̂ij=bij−0.5bijC{\widehat{b}}_{ij}\ = b_{ij}\ - \ 0.5b_{ij}^{C} and bijCb_{ij}^{C} is the line charging susceptance. The constraints (2) and (3) enforce power balance, (4) and (5) are the AC power flow equations, (6) limits the bus voltage magnitudes, (7) and (8) represent the active and reactive limits and (9) are the line flow limits.

2.2 Successive Spatiotemporal Graph Neural Network

Figure 1 illustrates the successive spatiotemporal architecture used for ACOPF prediction. The model receives a time series of grid measurements X={X1…,XT}X\ = \ \{ X_{1}\ldots,X_{T}\}. These include voltage magnitude, voltage angle, active/reactive load, and generation at each bus. In Stage 1, a GCN or its physics-informed variant processes the grid topology at each timestep. The GCN captures spatial dependencies between buses by performing message passing along transmission lines. These produces spatial embeddings 𝐒𝟏,…,𝐒𝐓\mathbf{S}_{\mathbf{1}}\mathbf{,\ldots,}\mathbf{S}_{\mathbf{T}} that encode the network structure. In Stage 2, the sequence of spatial embeddings is passed to a temporal recurrent model, either an LSTM or GRU. It learns the temporal dynamics of the system caused by load fluctuations, renewable variability, and switching events. This stage models how the spatial states evolve over time. Finally, the output layer maps the learned representation to predicted system states. The outputs are denormalized physical quantities providing an estimate of the system operating point at the final timestep.

Figure 1: Figure 1 Successive spatiotemporal architecture used for power system state prediction
Figure 1 Successive spatiotemporal architecture used for power system state prediction

2.2.1 Graph Convolution Network Block Based on Physical Grid Topology

The structures of electric power systems constantly change as a result of maintenance operations, the integration of renewable energy sources, equipment failures, and outages. A dynamic graph, in which the nodes (buses) and edges (lines) vary over time is an efficient way to represent this power system. To reflect the changes in connections and node attributes, the adjacency matrix and feature matrices increase in dimension as the graph moves from Gt−1=(Vt−1,Et−1)toGt=(Vt,Et)G_{t - 1} = \left( V_{t - 1},E_{t - 1} \right)\ to\ G_{t} = (V_{t},E_{t}). As shown in Figure 2 the evolution of the transmission network between two-time steps. While red edges in GtG_{t} represent reconfigured line introduced to optimize operational goals, blue edges in Gt−1G_{t - 1} indicate stable connections. These topological shifts are correspondingly mathematically encoded by the adjacency matrices At−1A_{t - 1} and AtA_{t} . Red cells indicate newly created connections during reconfiguration, while blue cells indicate active lines.

Figure 2: Figure 2 Illustration of network structure evolution overtime
Figure 2 Illustration of network structure evolution overtime

The topology may change over time due to switching operations, contingencies, or network reconfiguration. These structural changes are captured through the time-varying adjacency matrix At∈ℝN×NA_{t} \in \mathbb{R}^{N \times N}. where N is the number of buses and Aij=1if buses ii\ and jj are electrically connected. The proposed model strictly uses the physical power grid topology derived from the current network configuration. Therefore, message passing occurs only along actual transmission lines. The normalized adjacency matrix used for graph convolution is defined as

Ãt=Dt−12(At+I)Dt−12{\widetilde{A}}_{t} = D_{t}^{- \frac{1}{2}}(A_{t} + I)D_{t}^{- \frac{1}{2}}
(10)

where DtD_{t} is the degree matrix of AtA_{t} and II is the identity matrix introducing self-loops. The graph convolution operation at layer l is then expressed as

Ht(l+1)=σ(ÃtHt(l)W(l))H_{t}^{(l + 1)} = \sigma\left( {\widetilde{A}}_{t}H_{t}^{(l)}W(l) \right)
(11)

where

  • Ht(l)H_{t}^{(l)} represents the node embeddings at layer l,

  • W(l)W(l) denotes the trainable weight matrix, and

  • σ(⋅)\sigma( \cdot )is a nonlinear activation function such as ReLU.

The initial layer uses the raw node features: Ht(0)=XtH_{t}^{(0)} = X_{t}\ . After LL graph convolution layers, the spatial representation becomes St=Ht(L)S_{t} = H_{t}^{(L)}. Which encodes topology-aware electrical interactions among buses. This formulation aligns with the implementation based on PyTorch Geometric’s GCNConv operator, where graph message passing occurs strictly along the actual transmission network topology determined by the current breaker and switch states.

2.2.2 Long short-term memory block

Long Short-Term Memory (LSTM) networks are well suited for time-series prediction in dynamic systems. Therefore, highly appropriate for sustainable power system operation analysis. Power grids with high renewable penetration exhibit strong temporal characteristics. For accurate spatiotemporal modeling of ACOPF states, it essential to capture both short-term and long-term operational fluctuations. The LSTM architecture consist of memory cell, which functions as an information accumulator. The memory control is achieved through three gating mechanisms;

  1. Input Gate: determines which components of the current input should be written into the memory cell.

  2. Forget Gate: decides which information from the previous cell state should be removed.

  3. Output Gate: regulates how the updated cell state contributes to the hidden state and network output.

Through these gating operations, LSTMs mitigate the vanishing and exploding gradient problems in recurrent neural networks. This ensures stable gradient propagation during training. Figure 3 shows the LSTM computational unit. XtX_{t}, denotes the input vector at time step tt. While ht−1h_{t - 1} and ct−1c_{t - 1} represent the previous hidden and cell states, respectively. These states are updated to the current hidden state hth_{t} and cell state ctc_{t}. It achieved through nonlinear transformations by sigmoid (σ)(\sigma) and hyperbolic tangent (tanh)(tanh) activation functions.

Figure 3: Figure 3 The LSTM internal gating structure
Figure 3 The LSTM internal gating structure

Figure 3 depicts the gating structure of the LSTM unit. It comprises, forget, input, and output gates that regulate temporal information flow.

  1. Forget Gate

The forget gate (Figure 4a) determines which information is discarded from the previous cell state. It receives the current input XtX_{t} and previous hidden state ht−1h_{t - 1}:

ft=σ(Wfxt+Ufht−1+bf)f_{t} = \sigma(W_{f}x_{t} + U_{f}h_{t - 1} + b_{f})
(12)

where (σ)(\sigma) outputs values in (0,1)(0,1), represents the degree of information retention. Values close to zero indicate forget, while values near one retain information.

2) Input Gate

The input gate (Figure 4b) controls the incorporation of new information into the cell state through a two-stage process:

First, a sigmoid layer determines which elements will be updated:

it=σ(Wixt+Uiht−1+bi)i_{t} = \sigma(W_{i}x_{t} + U_{i}h_{t - 1} + b_{i})
(13)

Second, a candidate memory vector is generated:

c̃t=tanh(Wcxt+Ucht−1+bc){\widetilde{c}}_{t} = tanh(W_{c}x_{t} + U_{c}h_{t - 1} + b_{c})
(14)

The cell state is then updated by combining retained historical information and new candidate content:

ct=fti⊙ct−1+it⊙c̃tc_{t} = f_{t}^{i} \odot c_{t - 1} + i_{t} \odot {\widetilde{c}}_{t}
(15)

3) Output Gate

The output gate regulates the information propagated to the hidden state and subsequent time steps:

ot=σ(Woxt+Uoht−1+bo)o_{t} = \sigma(W_{o}x_{t} + U_{o}h_{t - 1} + b_{o})
(16)
ht=ot⊙tanh(ct)h_{t} = o_{t} \odot tanh(c_{t})
(17)

This mechanism ensures relevant components of the updated memory cell influence the output.

2.2.3 Gated Recurrent Unit (GRU) block

The GRU block captures the temporal dependencies using a simplified gating mechanism as shown in Figure 4. The GRU merges memory and hidden representations into a single hidden state unlike LSTM. This reduction in structural complexity often yields faster training and lower parameter count. This can be advantageous for real-time ACOPF surrogate learning.

Figure 4: Figure 4 The gated recurrent unit network
Figure 4 The gated recurrent unit network

Given input XtX_{t} and previous hidden state ht−1h_{t - 1}, the standard GRU equations are defined as:

update gate zt=σ(Wzxt+Uzht−1+bz)z_{t} = \sigma(W_{z}x_{t} + U_{z}h_{t - 1} + b_{z})
(18)
reset gate rt=σ(Wrxt+Urht−1+br)r_{t} = \sigma(W_{r}x_{t} + U_{r}h_{t - 1} + b_{r})
(19)
candidate hidden state h̃t=tanh(Whxt+Uh(rt⊙ht−1)+bh){\widetilde{h}}_{t} = tanh(W_{h}x_{t} + U_{h}(r_{t} \odot h_{t - 1}) + b_{h})
(20)
hidden state update ht=(1−zt)⊙ht−1+zt⊙h̃th_{t} = \left( 1 - z_{t} \right) \odot h_{t - 1} + z_{t} \odot {\widetilde{h}}_{t}
(21)

Where σ(•)\sigma( \bullet ) is the sigmoid function, tanh(•)tanh( \bullet ) is the hyperbolic tangent, and ⊙\odot denotes elementwise multiplication.

2.2.4 Successive Spatiotemporal GNN (GCN–LSTM)

Let the input sequence over a temporal window of length TT be

X={X1,X2,…,XT},Xt∈RN×FX = \left\{ X_{1},X_{2},\ldots,X_{T} \right\},X_{t} \in R^{N \times F}
(22)

where NN is the number of buses and F is the node feature dimension. For each time step tt, the graph convolution block extracts spatial features using the grid adjacency: Ht(o)=XtH_{t}^{(o)} = X_{t}

Ht𝓁+1=σ(ÃtHt(𝓁)W𝓁+b(𝓁)),𝓁=0,1,…,L−1H_{t}^{\mathcal{l +}1} = \sigma\left( {\widetilde{A}}_{t}H_{t}^{\left( \mathcal{l} \right)}W^{\mathcal{l}} + b\left( \mathcal{l} \right) \right),\ \ \ \ \ \ \ \ \ \ \mathcal{l =}0,1,\ldots,L - 1
(23)

where Ã\widetilde{A} is the normalized adjacency matrix, W(𝓁)W\mathcal{(l)} and b(𝓁)b\mathcal{(l)} are trainable parameters, LL is the number of graph convolution layers, and σ(⋅)\sigma( \cdot ) is the nonlinear activation function. The final spatial embedding at time step t is St=Ht(L)∈ℝN×DS_{t} = H_{t}^{(L)} \in \mathbb{R}^{N \times D} where DD is the spatial embedding dimension. Since the recurrent block in the implementation uses a standard PyTorch LSTM, the spatial embedding is reshaped into a vector sequence before temporal modeling:

zt=vec(St)∈ℝN×Dz_{t} = vec(S_{t}) \in \mathbb{R}^{N \times D}
(24)

The temporal dynamics are then modeled sequentially using a standard LSTM:

(ht,ct)=LSTM(zt,ht−1,ct−1)(h_{t},c_{t}) = LSTM(z_{t},h_{t - 1},c_{t - 1})
(25)

where hth_{t} and ctc_{t} denote the hidden state and cell state at time step tt, respectively. The final temporal representation is mapped to the output prediction through a fully connected layer:

Ŷ=WohT+bo\widehat{Y} = W_{o}h_{T} + b_{o}
(26)

where Ŷ\widehat{Y} contains the predicted ACOPF-related quantities.

2.2.5 Successive Spatiotemporal GNN (GCN–GRU)

For the GRU-based variant, the same spatial encoder is used, and the recurrent stage becomes

ht=GRU(zt,ht−1)h_{t} = GRU(z_{t},h_{t - 1})
(27)

with output prediction Ŷ\widehat{Y}, this formulation reflects the actual implementation in which graph convolution is applied. The temporal sequence learning is performed afterward using a standard recurrent unit.

2.2.6 Residual Successive Spatiotemporal GNN

For the residual variants, a skip connection is added between the projected spatial input and the recurrent output. Let the projected residual input be

rt=Wrzt+brr_{t} = W_{r}z_{t} + b_{r}
(28)

Then the residual recurrent representation is h̃t=ht+rt{\widetilde{h}}_{t} = h_{t} + r_{t} and the final output becomes Ŷ\widehat{Y}. The residual connection improves gradient flow during training.

2.3 Customized Loss Function

The physics-informed loss function is a linear combination of Mean Squared Error (MSE) and a regularization term based on the equality and inequality constraints. The PIStGNN is trained to predict the ACOPF optimality while maintaining physical feasibility.

Ltotal=w1Ldata+w2Lphys+w3Lsafe+w4LbranchL_{total} = w_{1}L_{data} + w_{2}L_{phys} + w_{3}L_{safe} + w_{4}L_{branch}
(29)

Where Li∈{Ldata,Lphys,Lsafe,Lconst}L_{i} \in \{ L_{data},L_{phys},L_{safe},L_{const}\} denotes the loss terms.

1) Data fidelity loss

It ensures supervised consistency between the predicted stateŷ\widehat{y} and the ground-truth ACOPF solution yy:

Ldata=∥ŷ−y∥22L_{data} = \left\| \widehat{y} - y \right\|_{2}^{2}
(30)

where all variables are normalized to ensure numerical stability. This term ensures that the PIStGNN accurately approximates reference ACOPF solutions generated using conventional solvers.

2) Physics consistency loss

This regularization term embeds AC power flow physics into the training process. The complex power injection at each bus is defined as:

S=P+jQ=V•(YbusV)*S = P + jQ = V \bullet {(Y_{bus}V)}^{*}
(31)

Where VV and YbusY_{bus} represent the complex bus voltage vector and admittance matrix respectively. P and Q stand for active and reactive power respectively.

Lphys=|Pnet−Re(V•(YbusV)*)|2+|Qnet−Im(YbusV)2|2L_{phys} = \left| P_{net} - Re(V \bullet {(Y_{bus}V)}^{*}) \right|^{2} + \left| Q_{net} - Im{(Y_{bus}V)}^{2} \right|^{2}
(32)

This constrains satisfy nonlinear AC power flow equations to reduce the risk of non-compliant predictions as observed in purely data-driven models.

3) Operational safety loss

A soft penalty function is used to maintain voltage security within permissible bounds;

Lsafe=ReLU(|V|−Vmax)2+ReLU(Vmin−|V|)2L_{safe} = ReLU{(|V| - V_{\max})}^{2} + ReLU{(V_{\min} - |V|)}^{2}
(33)

where ReLU(x)=max(0,x)ReLU(x) = max(0,x).

  1. Branch capacity loss (Inequality constraint)

Lbranch=1LB∑[ReLU(|Sk|−Sk,max)2]L_{branch} = \frac{1}{LB}\sum_{}^{}{\lbrack ReLU\left( \left| S_{k} \right| - S_{k,max} \right)^{2}\rbrack}
(34)

where the branch apparent power flow is:IR=Ybranch,k(Vfrom,k−Vto,k),|Sk|=|Vfrom,k•Ik*|I_{R} = Y_{branch,k}\left( V_{from,k} - V_{to,k} \right),\ \ \ \ \left| S_{k} \right| = \left| V_{from,k} \bullet I_{k}^{*} \right|. Ybranch,kY_{branch,k} is the series admittance of branch 𝐤\mathbf{k}, extracted as  Y{𝐛𝐮𝐬}[𝐟𝐫𝐨𝐦,𝐭𝐨]Y_{\{\mathbf{bus}\}\lbrack\mathbf{from},\ \mathbf{to}\rbrack}. Sk,maxS_{k,max} is the thermal rating of the branch in per-unit.

2.4 Performance Evaluation Metrics in Learning-based ACOPF

  1. Optimality

The optimality measures how close the objective function value obtained by a learning-based scheme is to the value produce by a benchmark solver (ground truth). The optimality is evaluated by first computing the optimality loss (gap). This is obtained by calculating the Mean Absolute Error (MAE) of the objective function across a set of test samples, as expressed in equation (35). Subsequently, the optimality score is computed based on equation (36).

Optimalityloss=1N∑i=1N|VMi∘−VMi*|Optimality\ loss = \frac{1}{N}\sum_{i = 1}^{N}\left| {VM}_{i}^{{^\circ}} - {VM}_{i}^{*} \right|
(35)
Optimality=1−1N∑i=1N|VMi∘−VMi*|Optimality = 1 - \frac{1}{N}\sum_{i = 1}^{N}\left| {VM}_{i}^{{^\circ}} - {VM}_{i}^{*} \right|
(36)

where ii denotes the index of the test samples and N represents the total number of test samples. The variables VMt∘{VM}_{t}^{{^\circ}} and VMt*{VM}_{t}^{*} denote the voltage magnitude obtained from the learning-based scheme and the benchmark solver, respectively. Similarly, VAt∘{VA}_{t}^{{^\circ}} and VAt*{VA}_{t}^{*} represent the voltage angle associated with the machine learning-driven model and the benchmark solver. The optimality is quantified such that smaller MAE values indicate closer agreement with the benchmark solver. And higher optimality corresponds to better performance of the learning-based method.

  1. Constraint satisfaction rate:

The quality of solutions obtained by machine learning techniques can be assessed by measuring the constraint satisfaction rates. These metrics are defined as:

Constraintsatisfactionsate(%)=nsnc×100%Constraint\ satisfaction\ sate\ (\%) = \frac{n_{s}}{n_{c}} \times 100\%
(37)

Where ns,ncn_{s},n_{c} denote the total number of satisfied equality and inequality constraints, and total number of constraints, respectively

  1. Computational efficiency

The computational efficiency metrics offer valuable insights into the efficiency and speed of model execution. The computational efficiency is typically analyzed via speedup factor. The computational efficiency metrics are described as follows:

Speedfactor=1T∑t=1TCTt*1T∑t=1TCTt∘Speed\ factor = \frac{\frac{1}{T}\sum_{t = 1}^{T}{CT}_{t}^{*}}{\frac{1}{T}\sum_{t = 1}^{T}{CT}_{t}^{{^\circ}}}\
(38)

CTt∘{CT}_{t}^{{^\circ}} and CTt*{CT}_{t}^{*} denote the computation time for solving the OPF problem using a learning-based model and a benchmark solver, respectively.

2.5 Detailed Implementation of PIStGNN

Figure 5 shows an integrated framework that combines data-driven learning and physics-informed modeling, ACOPF under renewable energy integration. The overall methodology consists of two main stages: (i) data generation, and (ii) supervised physics-informed spatiotemporal learning,

Figure 5: Figure 5 Detailed implementation of PIStGNN
Figure 5 Detailed implementation of PIStGNN

2.5.1 Data generation pipeline

The data pipeline generates spatiotemporal power system datasets for training and evaluating the proposed graph neural network models. Three benchmark systems from the Pandapower library are used: the IEEE 33-bus, IEEE 57-bus, and IEEE 118-bus networks. These systems represent distribution and transmission grids with increasing structural complexity. The IEEE 33-bus system is a radial distribution network with normally open tie-lines enabling reconfiguration, whereas the IEEE 57-bus and IEEE 118-bus systems are meshed transmission networks without predefined tie-lines. The base power values are 10 MVA for the 33-bus system and 100 MVA for the 57-bus and 118-bus systems. Each bus at every timestep is described by an 11-dimensional feature vector capturing local electrical conditions. The features include active and reactive load demand, power injections from the external grid, conventional generation, renewable generation, voltage magnitude, voltage angle, and the normalized bus degree representing local connectivity. The power quantities are converted to per-unit values using the system base power. Voltage magnitude is mean-centered around 1.0 p.u., and the node degree is normalized by the maximum degree in the network. To emulate measurement uncertainty, Gaussian sensor noise is added to the primary electrical variables during data generation. Ground-truth targets are obtained from AC power flow solutions computed in Pandapower. Although the full target vector contains multiple electrical quantities, the graph neural networks are trained to predict only voltage magnitude deviation and voltage angle for each bus. Temporal operating conditions are generated using synthetic load and renewable generation profiles. Load demand follows a 24-hour “camel-shaped” curve with morning and evening peaks, with an additional ±5% random perturbation to represent short-term variability. Solar generation follows a bell-shaped daytime curve. It is also affected by seasonal variation and stochastic cloud conditions. While wind generation follows a night-peaking coastal profile governed by weather-dependent wind speed ranges. Weather evolution is also modeled using a first-order Markov chain. It enables temporally correlated renewable generation patterns. The data generator also simulates network reconfiguration events. In the radial IEEE 33-bus system, switching occurs by closing a tie-line and opening another line within the resulting loop to maintain radiality. For the meshed IEEE 57-bus and 118-bus systems, cycles are identified and a line is opened to create a temporary tie-line before reconfiguration. Each switching configuration is assigned a unique topology identifier, and the corresponding bus admittance matrix (Ybus)(Y_{bus}) is recomputed. Before training, the generated data undergo preprocessing. Raw simulation outputs are aggregated, converted to per-unit values, and split chronologically into training (70%), validation (15%), and testing (15%) subsets. The processed datasets, including node features, targets, topology identifiers, admittance matrices, and network connectivity information, are stored as PyTorch tensors to support efficient training and evaluation of the proposed models.

2.5.2 Model Architectures

The graph neural network architectures are implemented to evaluate spatiotemporal learning for AC optimal power flow prediction. The models are grouped into spatial-only and spatiotemporal categories and are implemented using PyTorch and PyTorch Geometric. Graph message passing is performed using the GCNConv operator. The node interactions occur strictly along the physical transmission network defined by the grid topology. The spatial-only models process a single system snapshot with input tensor shape (B, N, F). Where B is the batch size, N the number of buses, and F the number of node features. The standardGCN model uses a fixed adjacency matrix corresponding to the base network topology. The dynamicGCN extends this model by updating the adjacency matrix for each sample to reflect the current switching configuration or contingency state. The physics informed graph convolution network (PIGCN) architecture uses the same structure as dynamicGCN but applies physics-informed loss function. This combines equation (30) with penalties enforcing equations (31) – (34). These models follow a successive spatiotemporal pipeline. The spatiotemporal models operate on sequential inputs with tensor shape (B, T, N, F), where T denotes the temporal window length. For each timestep, graph convolution extracts spatial embeddings equation (24). These are stacked across time and reshaped into per-node sequences. The sequences are then processed using equation (25) or (27) to capture temporal dependencies caused by renewable variability and load dynamics. Two variants are considered: physics informed graph convolution long short-term memory (PIGCLSTM) and physics informed graph convolution gated recurrent unit (PIGCGRU). To mitigate oversmoothing in deeper graph networks equation (28) is applied. This introduces two residual variants: physics-informed residual graph convolutional long short-term memory network (PIResnetGCLSTM) and physics-informed residual graph convolutional gated recurrent unit network (PIResnetGCGRU). The residual graph convolution blocks consist of two GCNConv layers with skip connections. This allows stable training of deeper spatial representations. For all spatiotemporal models, the recurrent layer outputs the hidden representation at the final timestep. The output is mapped through a fully connected layer to predict the network state as expressed in equation (26). The shape of the final output is presented as (B,N,2)(B,\ N,\ 2). The voltage magnitude deviation and voltage angle recorded as output at each bus.

2.5.3 Software environment and dependencies

The study is implemented in Python (version 3.10 or later) and trained in either GPU enabled through CUDA 12.x or CPU-only environments. The project repository is obtained using a standard Git workflow. Subsequently, a Python virtual environment is created and activated. This setup ensures compatibility across different hardware configurations and maintain consistent software dependencies. The core machine learning components are implemented using PyTorch (version 2.10.0). This provides tensor computation and automatic differentiation capabilities. PyTorch Geometric (version 2.7.0) is used to implement the graph neural network operations. The GCNConv operator is used for graph convolution. The training workflow, include training loops, callbacks, and logging utilities. Lightning (version 2.6.1) is applied to manage the training. Additionally, NetworkX, a dependency of Pandapower, is used for graph operations such as cycle detection during topology switching events. This software environment ensures efficient training of graph neural network models while supporting reproducible experimentation across different computational platforms. The power system simulations and benchmark network models are generated using Pandapower (version 2.14.0 or later). The Pandapower provides standard IEEE test systems and AC power flow solvers. Finally, Weights & Biases (version 0.25.0) is used to track the performance.

2.5.4 Configuration and hyperparameter settings

The training processes are controlled through configuration files. It defines parameters for data generation and model training. These parameters enable systematic experimentation across different operating conditions. The data generation is configured using configs/data_generation.yaml. A 10,008 timesteps dataset is generated which represents different operation conditions under uncertainty. The renewable penetration levels are given [0.0,0.2,0.4,0.6,0.8,1.0]\lbrack 0.0,\ 0.2,\ 0.4,\ 0.6,\ 0.8,\ 1.0\rbrack to evaluate system behavior from conventional operation to fully renewable scenarios. The grid reconfiguration events occur probabilistically with a switching rate of 10% per timestep. This allows the network topology to change dynamically during simulation. The system uncertainty is measured using gaussian noise to electrical variables. With standard deviations given as 0.005 p.u. for voltage magnitude, 0.01 p.u. for power injections, and 0.02 radians for voltage angles. Overall, 30% of buses are assumed to have PMU-quality measurements. This emulates realistic monitoring infrastructure. The renewable generation is constrained with practical operating limits of 0.98 maximum utilization coefficient. The weather weight vectors define initial probability distributions for solar and wind states. It ensures weather-driven renewable variability is modeled. In addition, model training parameters are specified in configs/training.yaml. The graph neural networks are trained using a batch size of 32. For spatiotemporal models, a temporal sequence length of four timesteps. Each bus is represented by 11 input features. The models predict voltage magnitude deviation and voltage angle as outputs per bus. Both the graph convolution layers and recurrent layers (LSTM or GRU) use a hidden dimension of 64. The spatial encoder consists of four GCN layers or residual blocks. The Adam optimizer with an initial learning rate of 0.001 is used optimize the model. The learning rate scheduling follows a ReduceLROnPlateau strategy. This strategy reduces the learning rate by a factor of 0.5 if the validation loss does not improve for 10 epochs. The training is limited to a maximum epoch of 200. A fixed random seed of 42 is used to ensure reproducibility. The training objective incorporates additional penalty terms for physics-informed models. These include weights for power balance (λ=0.1)(\lambda = \ 0.1), voltage magnitude limits (λ=0.01)(\lambda\ = \ 0.01), and branch capacity constraints (λ=0.01)(\lambda\ = \ 0.01). Finally, a comparisons analysis is conducted with classical solvers.

2.5.5 Evaluation and benchmarking

The proposed models’ performance is evaluated using a dedicated pipeline implemented in scripts/evaluate.py. Each trained model is tested on a held-out dataset and assessed along three primary dimensions. These include prediction accuracy, physical feasibility, and computational efficiency. The prediction accuracy is measured using MAE (as shown in equation (35)) between the predicted and ground-truth. This metric quantifies the model’s ability to approximate the steady-state operating point of the power system. The physical feasibility is assessed by verifying whether the predicted system states satisfy key electrical constraints. Equation (37) measures constraint satisfaction rates. The constraints computed are active power balance (P), reactive power balance (Q), voltage magnitude limits (V), and branch flow capacity limits (S). The power balance violations are evaluated using a tolerance threshold of 0.5%. At the same time, voltage and branch constraints are checked against their respective operational limits. These metrics show how the predicted states adhere to the physical laws governing power system operation. The performance is evaluated by comparing the inference speed of the proposed GNN models with four classical solvers available in Pandapower. These include: Newton–Raphson (NR), Newton–Raphson with the Iwamoto multiplier (NRI), Gauss–Seidel (GS), and Backward/Forward Sweep (BFS). Multiple runtime trials are conducted to obtain stable timing measurements. The Test-Time Augmentation (TTA) approach is also used to analyze predictive uncertainty. The model performs inference across multiple perturbed inputs and the variance of the resulting predictions is computed. This variance provides an estimate of the model’s sensitivity to input perturbations and serves as a measure of predictive uncertainty.

3. Result and Discussion

3.1 Data Profile Analysis of Power Systems with Renewable Integration

Figure 6–8 shows the data profile analysis of system behavior under high renewable penetration for the IEEE 33-bus, 57-bus, and 118-bus systems. The analysis considers demand–supply balance, generation mix, renewable generation variability, and voltage health across buses. The indicators provide insight into the operational feasibility and stability of renewable power systems. The demand–supply balance curves demonstrate daily load patterns for all systems. In Figure 6 peak demand occurs around 18:00 and demand varies between 1.1 MW and 3.8 MW. The generation profile closely follows the demand curve with reserve margin of 0.05–0.15 MW. A similar trend is observed in the Figure 7, where demand ranges from 380 MW to 1300 MW. In Figure 10, demand varies between 1300 MW and 4300 MW. The generation mix shows that renewable energy sources have the largest share. In the IEEE 33 bus system, renewable generation ranges between 1.2 MW and 3.5 MW. As displayed in Figure 8 and Figure 8, renewable output increases to 1200 MW and 4500 MW, respectively. The conventional generators and external grid support serve as balancing resources during periods of renewable variability. The analysis demonstrates that there is direct correlation between renewable generation capacity increases and power system variability. In IEEE 33 bus system, renewable output increases from 0 MW at 0% penetration to 9 MW at 100% penetration. In the IEEE 57 and IEEE 118 bus systems, maximum renewable outputs reach approximately 1300 MW and 3600 MW respectively. The overall distribution indicates that renewable generation increases with system size. Finally, the voltage analysis confirms that the network maintains stable operating conditions across all buses. For the IEEE 33 system, bus voltages remain within 0.98–1.01 p.u. The IEEE 57 system maintains voltages between 0.99–1.02 p.u. In the larger IEEE 118 system, voltages vary between 0.96–1.04 p.u., but remain within the acceptable limits of 0.9–1.1 p.u. These results indicate that even under high renewable penetration scenarios, the systems maintain adequate voltage regulation and operational stability.