Physics-Informed Graph Neural Network for Dynamic Reconfiguration of
  Power Systems
To maintain a reliable grid we need fast decision-making algorithms for
complex problems like Dynamic Reconfiguration (DyR). DyR optimizes distribution
grid switch settings in real-time to minimize grid losses and dispatches
resources to supply loads with available generation. DyR is a mixed-integer
problem and can be computationally intractable to solve for large grids and at
fast timescales. We propose GraPhyR, a Physics-Informed Graph Neural Network
(GNNs) framework tailored for DyR. We incorporate essential operational and
connectivity constraints directly within the GNN framework and train it
end-to-end. Our results show that GraPhyR is able to learn to optimize the DyR
task.
Jules Authier, Rabab Haider, Anuradha Annaswamy, Florian Dorfler
# Physics-Informed Graph Neural Network for Dynamic Reconfiguration of Power Systems

###### Abstract

To maintain a reliable grid we need fast decision-making algorithms for complex problems like Dynamic Reconfiguration (DyR). DyR optimizes distribution grid switch settings in real-time to minimize grid losses and dispatches resources to supply loads with available generation. DyR is a mixed-integer problem and can be computationally intractable to solve for large grids and at fast timescales. We propose GraPhyR, a Physics-Informed Graph Neural Network (GNNs) framework tailored for DyR. We incorporate essential operational and connectivity constraints directly within the GNN framework and train it end-to-end. Our results show that GraPhyR is able to learn to optimize the DyR task.

 Graph Neural Network, Dynamic Reconfiguration, Physics Informed Learning.

## I Introduction

The global energy landscape is rapidly evolving with the transition towards renewable energy generation. This transition brings numerous benefits for the climate, but also presents challenges in effectively controlling and optimizing power systems with high penetration of intermittent renewable generation such as solar and wind. New operating schemes are needed to ensure efficient and reliable grid operations in the presence of intermittent generation. Significant research efforts focus on optimizing resource dispatch and load flexibility towards reducing costs and increasing grid efficiency; however there remains efficiency gains to be had when co-optimizing grid topology. To this end, we propose _Dynamic Reconfiguration_ (DyR) in a distribution grid to increase operating efficiency by co-optimizing grid topology and resource dispatch.

The distribution grid reconfiguration problem involves the selection of switch states (open/closed) to meet demand with available generation, while satisfying voltage and operating constraints. Grid reconfiguration can re-route power flows to reduce power losses [1], increase utilization of renewable generation [2, 3], and re-energize grids after contingencies. Presently, DyR is deployed for loss reduction in the EU [2], and for fault conditions in the US using rule-based control schemes. The widespread growth of distributed generation, storage, and electric vehicles creates the opportunity for DyR for loss reduction, whereby topology and dispatch decisions are made _fast and frequently_ in response to faster resource timescales; as solar generation varies, the topology is adapted to supply loads in close proximity to generation, thus reducing losses and improving voltage profiles across the grid.

The DyR problem is a mixed integer program (MIP) due to the discrete nature of switch decisions. It is well known that MIPs are NP-hard (i.e. cannot be solved in polynomial time) and thus may be computationally intractable for large-scale problems. A distribution substation may have 10 feeders each with 5 switches, resulting in over \(10^{15}\) possible topologies. If operating constraints and load conditions result in only \(1\%\) of these topologies, the search space remains prohibitively large for traditional approaches. One option is to restrict the optimization to a single feeder, however optimizing topology over all feeders permits load transfer and generation exports.

Machine learning (ML) offers an alternative by shifting the computational burden to offline training, thereby making dynamic decision making via the online application of ML algorithms computationally feasible. Recent works propose ML for solving MIPs and combinatorial optimization (CO) [4], either in an end-to-end fashion or to accelerate traditional solvers. Graphs play a central role in formulating many CO problems [5], representing paths between entities in routing problems, or interactions between variables and constraints in a general CO [6, 7]. The use of Graph Neural Networks (GNNs) is also being explored to leverage the underlying graph structure during training and identify common patterns in problem instances. The traveling salesman problem (TSP) is a fundamental problem in CO and a standard benchmark which has been extensively studied with traditional optimization techniques. Recently, GNNs have been used to solve the TSP with good performance and generalizability [8, 9, 10]. In this work we leverage GNNs to learn the power flow representation for reconfiguration.

Grid reconfiguration for distribution grids has been studied with varying solution methodologies including knowledge-based algorithms and single loop optimization [1, 11], heuristic methods [12, 13], and reformulation as a convex optimization problem using big-\(\mathcal{M}\) constraints [14, 15, 16]. However, these methods are not computationally tractable for large-scale optimization in close to real-time applications, and may be limited to passive grids (i.e. no local generation). Machine learning approaches for DyR have also been proposed [17, 3]. In [17] the DyR problem is formulated as a Markov decision process and solved using reinforcement learning. In [3] a light-weight physics-informed neural network is proposed as an end-to-end learning to optimize framework with guarantee certified satisfiability of the power physics. A physics-informed rounding layer explicitly embeds the discrete decisions within the neural framework. These approaches show potential, but both are limited to a given grid topology and
switch locations. Our approach is similar to that of [3] wherein we embed discrete decisions directly within an ML framework.

The main contribution of this paper is **GraPhyR**, a graph neural network (**Gra**) framework employing physics-informed rounding [3] (**PhyR**) for DyR in distribution grids. GraPhyR is an end-to-end framework that learns how to optimize, and is enabled by four key architectural components:

**(1) A message passing layer that models switches as gates:** The gates are implemented as a value between zero and one to model switches over a continuous operating range. Gates control the flow of information through switches in the GNN, modeling the control of physical power flow between nodes.

**(2) A scalable local prediction method:** We make power flow predictions locally at every node in the grid using local features. The predictors are scale-free and so can generalize to grids of any topology and size.

**(3) A physics-informed rounding layer:** We embed the discrete open/closed decisions of switches directly within the neural framework. PhyR selects a grid topology for each training instance upon which GraPhyR predicts a feasible power flow and learns to optimize a given objective function.

**(4) A GNN that takes the electrical grid topology as input:** We treat the grid topology and switch locations as an input which permits GraPhyR to learn the power flow representation across multiple possible distribution grid topologies within and across grids. Thus GraPhyR can optimize topology and generator dispatch: (a) on multiple grid topologies seen during training, and (b) under varying grid conditions such as (un)planned maintenance of the grid.

We demonstrate the performance of GraPhyR in predicting near-optimal and feasible solutions. We also show the effectiveness of GraPhyR in adapting to unforeseen grid conditions.

The remainder of this paper is organized as follows. Section II presents DyR as an optimization problem. Section III presents the GraPhyR method and details the four key architectural components. Section IV presents the simulation results, and conclusions are drawn in Section V.

## II Reconfiguration as an Optimization Problem

We consider DyR of distribution grids with high penetration of distributed generation. We model the power physics using Linearized DistFlow [1] as below:

\[\min_{\mathbf{\psi}}\,f(\mathbf{x},\mathbf{\psi}) =\sum_{(i,j)\in\mathcal{A}}(p_{ij}^{2}+q_{ij}^{2})R_{ij}\] (1) s.t. \[p_{j}^{G}-p_{j}^{L} =\sum_{k:(j,k)\in\mathcal{A}\cup\mathcal{A}_{sw}}\!\!\!\!\!\!\!\! \!\!\!\!\!\!\!\!\!\!\!\!\!\!\!\!\!\!\!\!\!\!\!\!\!\!\!\!\!\!\!\!\!\!\!\!\!\! \!\!\!\!\!\!\!\!\!\!\!\!\!\!\!\!\!\!\!\!\!\!\!\!\!\!\!\!\!\!\!\!\!\!\!\!\!\! \!\!\!\!\!\!\!\!\!\!\!\!\!\!\!\!\!\!\!\!\!\!\!\!\!\!\!\!\!\!\!\!\!\!\!\!\!\! \!\!\!\!\!\!\!\!\!\!\!\!\!\!\!\!\!\!\!\!\!\!\!\!\!\!\!\!\!\!\!\!\!\!\!\!\! \!\!\!\!\!\!\!\!\!\!\!\!\!\!\!\!\!\!\!\!\!\!\!\!\!\!\!\!\!\!\!\!\!\!\!\!\! \!\!\!\!\!\!\!\!\!\!\!\!\!\!\!\!\!\!\!\!\!\!\!\!\!\!\!\!\!\!\!\!\!\!\!\!\! \!\!\!\!\!\!\!\!\!\!\!\!\!\!\!\!\!\!\!\!\!\!\!\!\!\!\!\!\!\!\!\!\!\!\!\!\! \!\!\!\!\!\!\!\!\!\!\!\!\!\!\!\!\!\!\!\!\!\!\!\!\!\!\!\!\!\!\!\!\!\!\!\!\! \!\!\!\!\!\!\!\!\!\!\!\!\!\!\!\!\!\!\!\!\!\!\!\!\!\!\!\!\!\!\!\!\!\!\!\!\!\! \!\!\!\!\!\!\!\!\!\!\!\!\!\!\!\!\!\!\!\!\!\!\!\!\!\!\!\!\!\!\!\!\!\!\!\!\!\!\!\! \!\!
### _Message Passing_

The GNN models the distribution grid topology as an undirected graph, with switch embeddings modeling the switches in the electrical grid. The GNN's message passing layers incorporate these embeddings as gates, which enables GraPhyR to learn the representation of linearized Ohm's law of (5) across multiple topologies in a physics-informed way. The input to the GNN are the grid topology and nodal loads, and the output is a set of node and switch embeddings which will be used to make reconfiguration, power flow, and voltage predictions.

#### Iii-A1 Grid Topology as Input Data for Graph Structure

An input to the GNN is the grid topology described by \(\mathcal{G}(\mathcal{N},\mathcal{A},\mathcal{A}_{sw})\), using which the GNN models the physical grid topology as an undirected graph \(\mathcal{G}(\mathcal{N},\mathcal{E},\mathcal{E}_{sw})\) with \(N\) nodes, \(M\) lines, and \(M_{sw}\) switches. Trivially, \(\mathcal{E}\) (\(\mathcal{E}_{sw}\)) represents the undirected communication links along the directed edges \(\mathcal{A}\) (\(\mathcal{A}_{sw}\)) to support message passing and extracting the problem representation in the embeddings. By including \(\mathcal{G}(\mathcal{N},\mathcal{A},\mathcal{A}_{sw})\) as an input to the GNN, our GraPhyR framework is able to adapt to changing grid conditions, rather than requiring a large training dataset with multiple scenarios.

#### Iii-A2 Initial Node, Line, and Switch Embeddings

The second input data to the GNN is the load data \(\mathbf{x}^{0}\) which defines the node embeddings. The load data contains the active and reactive power load \(p_{i}^{L}\) and \(q_{i}^{L}\) for each node \(i\) in the grid and thus determines the initial node embeddings \(x_{i}^{0}\) of every node \(i\) in the corresponding graph where \(\mathbf{x}^{0}=\left[x_{1}^{0},\ldots,x_{N}^{0}\right]^{T}=\left[(p_{0}^{L},q_ {0}^{L}),\ldots,(p_{N}^{L},q_{N}^{L})\right]^{T}\). The line embeddings are set to one and are not updated by the message passing layers. The switch embeddings determine the value of the gate and are randomly initialized, similar to randomly initializing weights in a neural network. The switch embeddings are updated through the message passing layers. Initial line and switch embeddings are given by \(z_{ij}^{0}\), \(\forall\{i,j\}\in\mathcal{E}\cup\mathcal{E}_{sw}\).

#### Iii-A3 Message Passing Layers

In each hidden layer of the GNN the nodes in the graph iteratively aggregate information from their local neighbors. Deeper GNNs have more hidden layers and thus have node embeddings which contain information from further reaches of the graph. For each node embedding \(x_{i}^{0}\) in the graph, the first message passing layer is defined in (13) where \(\mathcal{N}_{i}\) denotes the set of neighboring nodes to node \(i\). For each switch embedding \(z_{ij}^{0}\) in the graph, the first message passing layer is defined in (15).

\[x_{i}^{1}=ReLU(W_{1}^{0}x_{i}^{0}+\sum_{j\in\mathcal{N}_{i}}\{W_ {2}^{0}\cdot f(z_{ij}^{0})\cdot x_{j}^{0}\}) \tag{13}\] \[f(z_{ij}^{0})=\begin{cases}sig(z_{ij}^{0})&\text{if }\{i,j\}\in \mathcal{E}_{sw}\\ 1&\text{otherwise}\end{cases}\] (14) \[z_{ij}^{1}=ReLU(W_{3}^{0}(x_{i}^{0}+x_{j}^{0})+W_{4}^{0}z_{ij}^{0}), \forall\{i,j\}\in\mathcal{E}_{sw} \tag{15}\]

For the remaining message passing layers, denoted by \(l\in\{1,2,\ldots,\mathcal{L}-1\}\), a residual connection is added to improve prediction performance and training efficiency [18]. The resulting node and switch embeddings are:

\[x_{i}^{l+1}=x_{i}^{l}+ReLU(W_{1}^{l}x_{i}^{l}+\sum_{j\in\mathcal{ N}_{i}}\{W_{2}^{l}\cdot f(z_{ij})\cdot x_{j}^{l}\}) \tag{16}\] \[f(z_{ij}^{l})=\begin{cases}sig(z_{ij}^{l})&\text{if }\{i,j\}\in \mathcal{E}_{sw}\\ 1&\text{otherwise}\end{cases}\] (17) \[z_{ij}^{l+1}=z_{ij}^{l}+ReLU(W_{3}^{l}(x_{i}^{l}+x_{j}^{l})+W_{4} ^{l}z_{ij}^{l}),\forall\{i,j\}\in\mathcal{E}_{sw} \tag{18}\]

The line embeddings are trivially set to one. We omit residual connections in the first message passing layer to expand the input embeddings \(x_{i}^{0}\) with dimensions of the input data, to an arbitrarily large hidden embeddings dimension \(h\). This allows the GNN to learn more complex representations by extracting features in a higher dimensional space.

#### Iii-A4 Gates

We implement gates in the message passing layer by applying a sigmoid to the switch embeddings, as in (14) and (17). The function \(f(z_{ij})\) acts like a filter for the message passing between two neighboring nodes, attenuating the information signal if the switch is closed. The gate models the switches as a continuous switch (ex. a household light dimmer), controlling information flow in the same way a switch controls power flow between two nodes.

#### Iii-A5 Global Graph Information

In the final message-passing layer, we calculate a global graph embedding, \(x_{G}^{\mathcal{L}}=\sum_{i=1}^{N}x_{i}^{\mathcal{L}}\). This embedding offers information access across the graph and can reduce the need for an excessive number of message passing layers for sparse graphs, such as those in power systems. This improves the computational efficiency.

Fig. 1: GraPhyR: proposed framework to solve the DyR problem.
### _Prediction_

After the \(\mathcal{L}\) message passing layers, the embeddings extracted from the input data are used to predict the switch open/close status and a subset of the power flow variables, denoted as independent variables.

#### Iii-B1 Variable Space Partition

We partition the variable space into independent and dependent variables. The independent variables constitute the active power flows \(p_{ij}\), nodal voltages \(v_{i}\), and switch open/close status \(y_{ij}\). The dependent variables constitute the reactive power flows \(q_{ij}\), and nodal generation \(\{p_{i}^{G},q_{i}^{G}\}\). We leverage techniques for variable space reduction to calculate the dependent variables from the independent variables, using constraints (2)-(12). This step ensures that the power physics constraints have certified satisfiability, as further discussed in Section III-E.

This partition is non-unique. It critically depends on the structure of the given problem which determines the relationship between the sets of variables, and the neural architecture which determines the relationship between inputs, predictions, and consecutive neural layers. **We further advocate that the neural architecture itself must be physics-informed, to embed domain knowledge and physical constraints directly into the neural network, as we have done in GraPhyR.**

#### Iii-B2 Local Prediction Method

Our prediction method leverages two key observations: (i) the relationship between power flows and voltages are the same for any node-edge pair and are modelled by the physics equations (2)-(5); (ii) the binary nature of switches makes it inherently different from a distribution line. Using these, we define two local prediction methods which use multi-layer perceptrons: a line predictor (L-predictor) and a switch predictor (S-predictor), shown in Fig. 3. The L-predictor in (19) predicts power flow and the voltages of the two nodes connected by the line using the node and global embeddings. The S-predictor also predicts the probability for the switch to be closed, using the switch embeddings \(z_{ij}^{\mathcal{L}}\) in addition to the node and global embeddings, as in (20). All predictions are denoted with a hat (i.e. \(\hat{v}_{i}\)) and will be processed in subsequent layers to render the final topology and dispatch decisions.

\[[\hat{p}_{ij},\hat{v}_{i}^{j},\hat{v}_{j}^{i}]=\text{L-predictor} [x_{i}^{\mathcal{L}},x_{j}^{\mathcal{L}},x_{G}^{\mathcal{L}}],\qquad\forall(i, j)\in\mathcal{A} \tag{19}\] \[[\hat{p}_{ij},\hat{v}_{i}^{j},\hat{v}_{j}^{i},\hat{y}_{j}]=\text{ S-predictor}[x_{i}^{\mathcal{L}},x_{j}^{\mathcal{L}},z_{ij}^{\mathcal{L}},x_{G}^{ \mathcal{L}}],\;\forall(i,j)\in\mathcal{A}_{sw} \tag{20}\]

Our local predictors exploit the full flexibility of GNNs. They are permutation invariant to the input graph data; are independent of the size of the graph (scale-free); and are smaller than the corresponding global predictor for the same grid. The first feature means our framework is robust to changes in input data. The last two features means our framework is lightweight and scalable. This would not be possible with a global predictor which predicts all independent variables from node and switch embeddings across the graph. The size of the input and output layers of a global predictor would depend on the size of the graph and the number of switches, and is the limitation in [3]. Table I summarizes the size of local and global predictors for the reconfiguration problem, where \(h\) is the dimension of the hidden graph embeddings.

### _Voltage Aggregation and Certified Satisfiability of Limits_

The local predictions obtained from the L-predictor and S-predictor generate multiple instances of voltage predictions for each node as indicated by a superscript. Specifically, the number of instances corresponds to the degree of the node \(i\), \(|\delta_{\mathcal{E}\cup\delta_{\mathcal{E}_{sw}}}(i)|\). We aggregate the voltage predictions to a unique value for each node in the grid as \(\hat{v}_{i}=\frac{1}{|\delta_{\mathcal{E}\cup\delta_{\mathcal{E}_{sw}}}(i)|} \sum_{j:\{i,j\}\in\mathcal{E}\cup\delta_{\mathcal{E}_{sw}}}\hat{v}_{i}^{j}\). The voltage predictions are then scaled onto the box constraints (10) with \(v_{i}=\underline{v}\cdot(1-\hat{v}_{i})+\overline{v}\cdot\hat{v}_{i}\). Notably, by selecting voltages as an independent variable in our variable space partition, we certify that voltage limits across the grid will always be satisfied, a critical aspect of power systems operation.

### _Topology Selection using Physics-Informed Rounding_

The S-predictor provides probabilistic predictions for open/close decisions of each switch. We recover binary decisions using a physics-informed rounding (PhyR) algorithm [3]. We exploit the radiality of distribution grids, which requires \(\mathcal{S}=N-1-M\) switches to be closed so there are always \(N-1\) conducting lines. The PhyR method selects the \(\mathcal{S}\) switches with the largest probabilities \(\hat{y}_{ij}\) and closes them by setting the corresponding \(y_{ij}=1\); the remaining switches are opened, \(y_{ij}=0\). This enforces (6) and (11). Note that as distribution grid technologies advance, bidirectional and loop flows may be easily incorporated in new protection schemes.

Fig. 3: Local predictions made by the switch and line predictors use the node and switch embeddings extracted after \(\mathcal{L}\) message passing layers.

Fig. 2: Message passing layers where switches are denoted by red-dashed lines. The node and switch embeddings are represented by blue and red colored blocks respectively, where the number of squares per-block indicates the dimension of the embeddings \(h\).
This would remove the radiality constraint, which GraPhyR can accommodate with suitable modifications to PhyR.

A note must be made about the practical implementation: PhyR is implemented with \(\min\) and \(\max\) operators which return gradients of \(0\), "killing" the gradient information necessary for backpropagation. We preserve these gradients in the computational graph by setting all but one switches to binary values, those with \(\mathcal{S}-1\) largest probabilities. Training guides the remaining switch towards a binary value.

### _Certified Satisfiability of Power Physics_

The final neural layer recovers the full variable space and enforces power flow constraints through open switches. The following steps happen sequentially:

1. Given \(\mathbf{y}\) and the independent variables we compute the reactive power flows \(\hat{q}_{ij}\) using (4)-(5).
2. Given \(\mathbf{y}\) we enforce (7) and (8) as \(p_{ij}=(\hat{p}_{ij}-0.5)\cdot 2\mathcal{M}y_{ij}\) and \(q_{ij}=(\hat{q}_{ij}-0.5)\cdot 2\mathcal{M}y_{ij}\) respectively. By explicitly setting flows through open switches to zero we enforce the constraints in a hard way.
3. Active and reactive power nodal generation is calculated using (2) and (3), respectively.

### _Loss Function_

The neural network learns to optimize by using an unsupervised framework. It has two objectives: to minimize line losses in (1), and to minimize inequality constraint violations of generation constraint (9) and connectivity constraints (12). Denoting these constraints as \(h(\mathbf{x},\boldsymbol{\psi})\leq 0\), we regularize the loss function using a soft-loss penalty with hyperparameter \(\lambda\). The loss function is \(l=f(\mathbf{x},\boldsymbol{\psi})+\lambda||\text{max}\{0,h(\mathbf{x}, \boldsymbol{\psi})\}||_{2}\).

**Remark 1**: _The inequality constraints (7), (8), and (10) have certified satisfiability by design of GraPhyR._

**Remark 2**: _Our loss function is unsupervised, and does not need the optimal solutions, which may be unknown or computationally prohibitive to compute._

## IV Experimental Results

### _Dataset and Experiment Setup_

We evaluate GraPhyR on a canonical distribution grid BW-33 [1] with 33 nodes, 29 lines, and 8 switches. We generate a variant of BW-33, called \(\mathcal{G}_{1}\) with 33 nodes, 27 lines, and 10 switches. We use the dataset from [3] which introduces distributed solar generation in the grid with a penetration of \(25\%\) generation-to-peak load. Loads are perturbed about their nominal value as typically done in literature. The two networks are shown in Fig. 4. The dataset has 8600 data points per grid which are divided as \(80/10/10\) for training/validation/testing.

We implement GraPhyR using PyTorch and train on the MIT supercloud [19]. GraPhyR has \(4\) message passing layers each with dimension \(8\) (\(\mathcal{L}=4,h=8\)). The L-predictor and S-predictor have a single hidden layer with dimension 24 and 32 respectively. We use \(10\%\) dropout, batch normalization, and ReLU activation in both predictors. The soft loss hyperparameter is \(\lambda=100\), big-\(\mathcal{M}\) relaxation parameter is \(0.5\) per unit (p.u.), and voltage bounds are \(\underline{v}=0.83,\overline{v}=1.05\) p.u. which adapts to the lossy behavior of BW-33 [1, 3]. We use ADAM optimizer with a learning rate of \(\gamma=5e^{-4}\), a batch size of \(200\), and train for 1500 epochs. We evaluate the performance of the neural framework using a committee of networks approach. We train 10 models with independent weight initialization and average the predictions across all models.

### _Performance Metrics_

We adopt the performance metrics defined in [3] to assess prediction performance. The asterisks notation (i.e. \(v^{*}\)) denotes the optimal solution obtain from a MIP solver.

**Dispatch error:** optimality metric of mean-squared error (MSE) in optimal generator dispatch: \(\frac{1}{N}\sum_{j\in\mathcal{N}}{(p_{j}^{G}-p_{j}^{G*})^{2}}+(q_{j}^{G}-q_{ j}^{G*})^{2}\).

**Voltage error (VoltErr):** optimality metric of MSE in nodal voltage prediction: \(\frac{1}{N}\sum_{j\in\mathcal{N}}{(v_{j}-v_{j}^{*})^{2}}\).

**Topology error:** optimality metric of the Hamming distance [20] between two topologies, calculated as the ratio of switch decisions not in the optimal position: \(\frac{1}{M_{sw}}\sum_{(i,j)\in\mathcal{A}_{sw}}{(y_{ij}-y_{ij}^{*})^{2}}\).

**Inequality violation:** feasibility metric of the magnitude of violations in constraint set, measuring the mean and maximum as \(\frac{1}{|h|}\sum_{k}\max{\{0,h^{k}(\mathbf{x},\boldsymbol{\psi})\}}\) and \(\max_{k}{\{\max\{0,h^{k}(\mathbf{x},\boldsymbol{\psi})\}}}\).

**Number of violations exceeding a threshold:** feasibility metric of the number of inequality constraints which are violated by more than an \(\epsilon\) threshold: \(\sum_{k}{\mathbb{T}}_{\max{\{0,h^{k}(\mathbf{x},\boldsymbol{\psi})\}>\epsilon}}\).

### _Case (a). GraPhyR with Local vs. Global Predictors_

We first compare GraPhyR with local predictors to a variant with a global predictor, termed Global-GraPhyR. The global predictor determines all independent variables (real power flows, voltages, switch probabilities) using all node and line embeddings. We implement the global predictor with a single hidden layer of the same size as the input dimension. The global predictor has input/output dimensions of 328/78 as compared to the L-predictor and S-predictor with dimensions of 24/3 and 32/4 respectively. Note that the global predictor predicts one voltage per node so voltage aggregation is not needed. We also compare the performance of GraPhyR with that of prior work which use a simple neural network with two hidden layers [3]: _SiPhyR_ which employs PhyR; and _InSi_ which approximates a step function.

Fig. 4: Grid topology of BW-33 (left) and the synthetic \(\mathcal{G}_{1}\) (right). Switches indicated with green dashed lines. Solar generator locations indicated with yellow nodes.
Table II-(a) shows the prediction performance for these methods. We first observe that **the GNN frameworks achieve lower dispatch error**, with Global-GraPhyR outperforming SiPhyR by two orders of magnitude. The GNN uses topological information to optimize the dispatch and satisfy loads. Second, **the PhyR-based frameworks achieve lower topology errors** by up to 10%, by embedding the discrete decisions directly within the ML framework. However, the topology error remains high (\(>30\%\)), demonstrating the challenge in learning to optimize this combinatorial task. Finally, **SiPhyR and Global-GraPhyR achieve the best performance across feasibility metrics**, with lower magnitude and number of inequality violations. Notably, the maximum inequality violation is an order of magnitude higher for InSi which does not benefit from PhyR, and GraPhyR which makes local predictions. This is expected. First, PhyR explicitly accounts for binary variables within the training loop to enable the end-to-end learning: PhyR selects a feasible topology upon which the neural framework predicts a near-feasible power flow solution. Second, GraPhyR sacrifices some prediction performance for the flexibility to train and predict on multiple graphs. Figure 5 plots the mean inequality violations for GraPhyR. The constraints are always respected for voltage (by design) and connectivity (by constraint penalty). Nodal generation constraints are frequently violated as the lowest cost (lowest line losses) solution is to supply all loads locally.

We next test the limits of topology prediction within our ML framework by comparing with a semi-supervised approach. The loss function includes a penalty on the switch status:

\[l_{sm}=f(\mathbf{x},\boldsymbol{\psi})+\lambda||\text{max}\{0,h(\mathbf{x}, \boldsymbol{\psi})\}||_{2}+\mu||\mathbf{y}-\mathbf{y}^{*}||_{2} \tag{21}\]

Table II-(a) shows the performance of the semi-supervised GraPhyR. We also include results of Supervised-SiPhyR from [3] which uses a regression loss for voltages, generation, and switch status, and an inequality constraint violation penalty:

\[l_{sup}(z,\varphi)=\|(\mathbf{v}-\mathbf{v}^{*})^{2}+(\mathbf{p} ^{\mathbf{G}}-\mathbf{p}^{\mathbf{G}*})^{2}+(\mathbf{q}^{\mathbf{G}}-\mathbf{ q}^{\mathbf{G}*})^{2}\|_{2}^{2}\] \[+\|(\mathbf{y}-\mathbf{y}^{*})^{2}\|_{2}^{2}+\lambda||\text{max} \{0,h(\mathbf{x},\boldsymbol{\psi})\}||_{2} \tag{22}\]

The results show that Semi-supervised GraPhyR outperforms Supervised-SiPhyR on topology error, achieving near-zero error. This substantial difference can be attributed to the GNN which embeds topological data directly within the framework. Although these (semi-)supervised approaches achieve good performance, they are not practicable. They require access to the optimal solutions, which may be computationally prohibitive to generate across thousands of training data points.

A note must be made on computational time. Solving the DyR problem using Gurobi (a commercial MIP solver) takes on average 201 milliseconds for BW-33, and 18 seconds for a 205-node grid per instance. Actual computational times vary significantly with varying load conditions which stress grid voltages (Ex. 17-fold increase for the 205-node grid during high load periods [3]). In contrast, the inference time of GraPhyR is only 84 milliseconds for a batch of 200 instances.

### _Case (b). Prediction Performance on Multiple Grids_

A key feature of GraPhyR is its ability to solve the DyR problem across multiple grid topologies. We trained and tested GraPhyR on two grids (BW-33 and \(\mathcal{G}_{1}\)) that have the same number of nodes but different number of lines and switches. Table II-(b) shows these results. The performance of GraPhyR on the two grids is similar to that of GraPhyR on a single grid, showing that GraPhyR can learn the power flow representation across multiple topologies and across multiple grids.

Fig. 5: Magnitude of the inequality violations for GraPhyR. The constraint sets on nodal generation, voltage limits, and connectivity constraints are separated by black vertical lines.
### _Case (c). Adapting to Changing Grid Conditions_

We next test GraPhyR on changing grid conditions, such as (un)planned maintenance by the grid operator or switch failure. Since power flows are highly correlated with the grid topology, changes in the set of feasible topologies due to maintenance or equipment failure can significantly change the prediction accuracy. Rather than training on multiple scenarios, we train only on the BW-33 grid for normal operating conditions and test on cases where a switch is required to be open or closed.

Results are shown in Table II-(c). Generally the dispatch error, voltage error, and average inequality violation magnitudes remain similar to cases of normal operation. However, there is a notable increase in the number of inequality violations, and when forcing a switch open, an order of magnitude increase in the maximum inequality violations. Forcing a switch open removes an edge from the GNN graph. The resulting graph is more sparse, reducing access to information during message passing and changing the information contained in the node and switch embeddings.

The topology error is more nuanced. When switch 36 is closed, there is an increase in voltage and topology error. This is because without any operator requirements on switch statuses, switch 36 remains optimally open for all load conditions. Thus, when switch 36 is required to be open, there is a significant decrease in topology error, by almost 10%. Since we did not trained on other scenarios, GraPhyR struggles to optimize the topology and predict voltages when the grid conditions deviate significantly from the training data - such as when switch 36 is closed. Similar performance degradation happens when switch 35 is required to be open; this switch is optimally closed for all load conditions. Interestingly, the status of switch 10 (open or closed) does not affect the topology error, although this switch is typically closed in the training data. There may be multiple (near-)optimal topologies with similar objective value. Regularizing the dataset or performance metrics against these multiple solutions may be necessary to improve prediction performance.

## V Conclusion

We developed GraPhyR, an end-to-end physics-informed Graph Neural Network framework to solve the dynamic reconfiguration problem. We model switches as gates in the GNN message passing, embed discrete decisions directly within the framework, and use local predictors to provide scalable predictions. Our simulation results show GraPhyR outperforms methods without GNNs in learning to predict optimal solutions, and offers significant speed-up compared to traditional MIP solvers. Further, our approach adapts to unseen grid conditions, enabling real-world deployment. Future work will investigate the scalability of GraPhyR to larger grids (200+ nodes), approaches to reduce inequality constraint violations, and regularization strategies to improve topology prediction. Finally, further efforts are needed in developing good datasets with representative timeseries data in distribution grids.
