DeepOPF-U: A Unified Deep Neural Network to Solve AC Optimal Power Flow
  in Multiple Networks
The traditional machine learning models to solve optimal power flow (OPF) are
mostly trained for a given power network and lack generalizability to today's
power networks with varying topologies and growing plug-and-play distributed
energy resources (DERs). In this paper, we propose DeepOPF-U, which uses one
unified deep neural network (DNN) to solve alternating-current (AC) OPF
problems in different power networks, including a set of power networks that is
successively expanding. Specifically, we design elastic input and output layers
for the vectors of given loads and OPF solutions with varying lengths in
different networks. The proposed method, using a single unified DNN, can deal
with different and growing numbers of buses, lines, loads, and DERs.
Simulations of IEEE 57/118/300-bus test systems and a network growing from 73
to 118 buses verify the improved performance of DeepOPF-U compared to existing
DNN-based solution methods.
Heng Liang, Changhong Zhao
# DeepOPF-U: A Unified Deep Neural Network to Solve AC Optimal Power Flow in Multiple Networks

###### Abstract

The traditional machine learning models to solve optimal power flow (OPF) are mostly trained for a given power network and lack generalizability to today's power networks with varying topologies and growing plug-and-play distributed energy resources (DERs). In this paper, we propose DeepOPF-U, which uses _one_ unified deep neural network (DNN) to solve alternating-current (AC) OFF problems in different power networks, including a set of power networks that is successively expanding. Specifically, we design elastic input and output layers for the vectors of given loads and OPF solutions with varying lengths in different networks. The proposed method, using a single unified DNN, can deal with different and growing numbers of buses, lines, loads, and DERs. Simulations of IEEE \(57/118/300\)-bus test systems and a network growing from \(73\) to \(118\) buses verify the improved performance of DeepOPF-U compared to existing DNN-based solution methods.

 Optimal power flow, deep neural networks

## I Introduction

There have been increasing research efforts in leveraging the powerful approximation capabilities of deep neural networks (DNNs) to learn the high dimensional load-to-solution mappings of the important optimal power flow (OPF) problems. High-quality near-optimal OPF solutions can be instantly obtained from well trained DNN models, significantly accelerating the solution process compared to traditional solvers [1, 2]. However, most existing DNN models were built and trained only for a specific power network with a given topology. With the expansion of buses, lines, loads, and distributed energy resources (DERs) and the corresponding change of power network topologies, the existing DNN models need to be rebuilt through repeated trainings, incurring heavy storage and computation burdens.

Solving alternating-current (AC) OPF problems across multiple networks is challenging, due to the difference in network topologies, line admittances, lengths of load and solution vectors, et cetera. Several methods have been developed recently to partly address the topology variation issue. For instance, [5] resampled the training data and retrained the DNNs in real time to adapt to the emerging new topologies, which is often computationally expensive. Reference [6] integrated the topology labels into the training process, while [7] encoded discrete topology representations with line admittances into the DNN input. These methods, without retraining, can directly predict OPF solutions under flexible topologies. However, they are still limited to a fixed number of loads and generators and incapable of incorporating plug-and-play DERs in a network expansion setting. Reference [4] learned a linear controller for an expanding radial network, which is not applicable to networks with general topologies.

In this paper, we propose DeepOPF-U, a novel approach that utilizes _one_ unified DNN to learn the load-to-solution mappings of AC OPF problems across multiple and expanding networks with different numbers of buses, lines, loads, and generators. The contribution of this work includes:

* We design elastic DNN input and output layers with plug-and-play neurons, to adapt to the varying lengths of load and OPF solution vectors in different networks.
* We design an incremental training process to sequentially update the weights of a unified DNN for multiple and expanding networks. The unified DNN can predict the OPF solutions in multiple networks without being retrained.

Simulations on IEEE \(57/118/300\)-bus test systems and a network growing from \(73\) to \(118\) buses demonstrate the adaptive mapping capability of the unified DNN without compromising solution quality. To the best of our knowledge, this is the first work to solve AC OPF problems across multiple networks using a single DNN.

## II AC OPF across Multiple Power Networks

Consider a series of power networks indexed by \(k=1,...,K\). Denote network \(k\) by \(\{\mathcal{N}_{k},\mathcal{E}_{k}\},\) where \(\mathcal{N}_{k}\) and \(\mathcal{E}_{k}\) collect the buses and lines, respectively. We aim to solve the following AC OPF problem in each network \(k\):

\[(\textbf{P}_{k}):\min_{P_{i}^{g},Q_{i}^{g}}\sum_{i=1}^{\mathcal{N} _{k}^{G}}C_{i}(P_{i}^{g}) \tag{1a}\] \[\text{s.t.}\sum_{j\in\mathcal{N}_{k}}\text{Re}\{V_{i}V_{j}^{*}Y_{ ij}^{*}\}=P_{i}^{g}-P_{i}^{d},\ \forall i\in\mathcal{N}_{k},\] (1b) \[\sum_{j\in\mathcal{N}_{k}}\text{Im}\{V_{i}V_{j}^{*}Y_{ij}^{*}\}=Q _{i}^{g}-Q_{i}^{d},\ \forall i\in\mathcal{N}_{k},\] (1c) \[P_{i}^{g}\leq P_{i}^{g}\leq\overline{P}_{i}^{g},\ \forall i\in \mathcal{N}_{k}^{G},\] (1d) \[\underline{Q}_{i}^{g}\leq Q_{i}^{g}\leq\overline{Q}_{i}^{g},\ \forall i\in \mathcal{N}_{k}^{G},\] (1e) \[\underline{Y}_{i}\leq|V_{i}|\leq\overline{V}_{i},\ \forall i\in \mathcal{N}_{k},\] (1f) \[|V_{i}(V_{i}^{*}-V_{j}^{*})Y_{ij}^{*}|\leq\overline{S}_{ij},\ \forall(i,j)\in \mathcal{E}_{k} \tag{1g}\]

where \(\mathcal{N}_{k}^{G}\) denotes the set of buses with dispatchable generators. \(P_{i}^{g}\) and \(Q_{i}^{g}\), \(P_{i}^{d}\) and \(Q_{i}^{d}\) represent the active and reactive power generation, active and reactive power consumption at bus \(i\), respectively. \(V_{i}\) denotes the complex voltage at bus \(i\). \(Y_{ij}\) is the \((i,j)\)-th entry of the network admittance matrix \(\mathbf{Y}\). Constants \(\underline{x}\) and \(\overline{x}\) are the lower and upper limits of variable \(x\). The generation cost at bus \(i\in\mathcal{N}_{k}^{G}\) is \(C_{i}(P_{i}^{g})\).
Problem \(\textbf{P}_{k}\) varies significantly across different networks \(k\). Prior methods [1, 2, 7] solved OPF problems in a specific network by using a dedicated DNN. As a new network emerges or the network successively expands, a new DNN needs to be built and trained, which lacks generalizability.

To overcome the limitation above, we design _one_ unified DNN to learn the load-to-solution mappings of AC OPF problems across multiple and expanding networks. The proposed approach, called DeepOPF-U, is applicable to:

* Multiple networks with different numbers of buses, lines, loads, DERs, and different topologies;
* An expanding network with increasing numbers of buses, lines, loads, and DERs.

## III Unified DNN for Multiple Power Networks

We design a single unified DNN to learn the load-to-solution mappings of AC OPF problems in multiple networks. For problems \(\{\textbf{P}_{k},\ k=1,...,K\}\), suppose their numbers of buses \(N_{1}\leq\cdots\leq N_{K}\). Let \(U_{1}:=[P_{k}^{d\top},Q_{k}^{d\top}]^{\top}\) stack the active and reactive power loads of the smallest network \(\{\mathcal{N}_{1},\mathcal{E}_{1}\}\). Define \(U_{k}:=[U_{k-1}^{\top},u_{k}^{\top}]^{\top}\), \(W_{k}^{1}:=[W_{k-1}^{\top},w_{k}^{1}]^{\top}\), \(W_{k}^{o}:=[W_{k-1}^{o\top},w_{k}^{o}]^{\top}\), \(B_{k}^{o}:=[B_{k-1}^{o\top},b_{k}^{o\top}]^{\top}\), \(X_{k}:=[X_{k-1}^{\top},x_{k}^{\top}]^{\top}\) for \(k=2,\ldots,K\). The unified DNN is designed as a multi-layer fully-connected neural network:

\[U_{k} =[U_{k-1}^{\top},u_{k}^{\top}]^{\top}, \tag{2a}\] \[h^{1} =\sigma([W_{k-1}^{1},w_{k}^{1}]U_{k}+B^{1}),\] (2b) \[h^{i} =\sigma(W^{i}h^{i-1}+B^{i}),\ \forall i=2,...,L\] (2c) \[\left[\begin{array}{c}X_{k-1}\\ x_{k}\end{array}\right] =\sigma^{\prime}\left(\left[\begin{array}{c}W_{k-1}^{o}\\ w_{k}^{o}\end{array}\right]\right)h^{L}+\left[\begin{array}{c}B_{k-1}^{o}\\ b_{k}^{o}\end{array}\right]\right) \tag{2d}\]

where \(u_{k}\) and \(x_{k}\) are the increments of input and output vector lengths from network \((k-1)\) to \(k\). Correspondingly, \(w_{k}^{o}\), \(w_{k}^{o}\) and \(b_{k}^{o}\) are parameters of the plug-and-play neurons to be adaptively activated/deactivated according to the input and output lengths. ReLU function \(\sigma(\cdot)\) and sigmoid function \(\sigma^{\prime}(\cdot)\) are used as activation functions of the hidden layers and the output layer, respectively. The elastic input and output layers (2b), (2d) embed \(K\) DNNs into a unified DNN in an incremental manner. The input, output, and parameters of the unified DNN are demonstrated in Figure 1.

The unified DNN is trained to minimize the following loss function corresponding to power network \(k\):

\[L_{k}:=\sum_{i\in\mathcal{N}_{k}}(|\hat{V}_{i}|-|V_{i}|)^{2}+\gamma(\hat{ \theta}_{i}-\theta_{i})^{2}\]

where \(|\hat{V}_{i}|\) and \(\hat{\theta}_{i}\) are the voltage magnitude and phase angle at bus \(i\) predicted by the DNN; \(|V_{i}|\) and \(\theta_{i}\) are their ground truth; factor \(\gamma\) tunes the relative importance of the two terms.

Inspired by the once-for-all idea [3], we design an incremental training strategy, which sequentially computes the losses \(L_{k}\) and backpropagates it immediately after each \(k\) to update the corresponding DNN parameters. Specifically, for each \(k\), the parameters for the input layer are updated as:

\[(\textbf{D}_{k}):W_{k}^{1}\gets W_{k}^{1}-\alpha\nabla_{W_{k}^{1}}L_{k}\]

where \(\alpha>0\) is the learning rate; similarly for the update of output-layer parameters \(W_{k}^{o}\) and \(B_{k}^{o}\). After the complete training process \(\textbf{D}_{k}\), \(k=1,...,K\), the DNN can predict OPF solutions to \(\textbf{P}_{k}\), \(k=1,...,K\) without retraining.

## IV Numerical Experiments

We consider two sets of test systems. The first set consists of the IEEE \(57\)-bus, \(118\)-bus, and \(300\)-bus feeders from PYPOWER. The second set consists of \(73\)-bus, \(90\)-bus, \(106\)-bus, and \(118\)-bus feeders, which (except the \(118\)-bus feeder itself) are all formed by removing buses (and loads and DERs on them) and lines from the IEEE \(118\)-bus feeder, to emulate a successively expanding case.

For the first set of feeders, load data are uniformly sampled within \([90\%,110\%]\) of the original loads. We sample \(150,000\) data points, \(50,000\) for each feeder, among which \(80\%\) form the training set and \(20\%\) the test set. For the second set of feeders, we use the 5-minute load profile of California ISO on May 20, 2020, which varies by up to \(54\%\) from 00:00 to 23:59, to scale the original load at each bus. This serves as the base load and the test set. In each 5-minute slot, \(400\) data points are sampled uniformly within \([90\%,110\%]\) of the base load, as the training set. The conventional MIPS solver in PYPOWER is used to obtain the ground-truth OPF solutions at the sampled load data points.

The unified DNNs are built on PyTorch, with details explained in Table I. The input and output layers have elastic lengths in the given ranges. The length of the output layer is twice the number of buses of the corresponding network, as both voltage magnitudes \(|V_{i}|\) and phase angles \(\theta_{i}\) are output. We apply the Adam optimizer with initial learning rate \(\alpha=1\times 10^{-3}\), mini-batch size \(100\), and \(500\) epochs. The learning rate halves every \(50\) epochs.

Following [2, 7], we use the metrics below to assess the performance. 1) _Optimality loss_: the gaps between the OPF objective values predicted by DeepOPF-U and those returned by MIPS in PYPOWER. It is better to be closer to 0. 2) _Constraint satisfaction_: the percentage of inequality constraints (1d)-(1g) being satisfied, including the active and reactive power generation limits (\(\eta_{Ps}\) and \(\eta_{Q^{g}}\)), voltage magnitude limits (\(\eta_{V}\)), and branch flow magnitude limits (\(\eta_{S_{\ell}}\)). It is better to be closer to \(100\). 3) _Load satisfaction_: the average

\begin{table}
\begin{tabular}{c|c|c|c} \hline \hline \#buses & Input layer & Hidden layers & Output layer \\ \hline
57/118/300 & 84–374 & 1024/512/256 & 114–600 \\
73/90/106/118 & 114–189 & 1024/512/256 & 146–236 \\ \hline \hline \end{tabular}
\end{table} TABLE I: Details of unified DNNs built on PyTorch.

Fig. 1: Demonstration of the unified DNN (2) (omitting activation functions). The sizes of parameter matrices \(W_{k}^{1}\), \(W_{k}^{o}\) and vector \(B_{k}^{o}\) are elastic.
percentage of active (\(\eta_{pq^{4}}\)) and reactive (\(\eta_{Q^{4}}\)) power loads being satisfied. It is better to be closer to \(100\). 4) _Speed-up_: the average number of times by which a DNN accelerates OPF solution compared to MIPS. The higher, the better.

### _Performance across Multiple Feeders_

We compare the proposed DeepOPF-U with DeepOPF-V [2] in the first set of feeders to verify the capability of the former across multiple feeders. The results are shown in Table II. The configurations of two methods are set the same for fair comparison. DeepOPF-U can predict AC OPF solutions in three feeders using a single DNN without compromising solution quality, while DeepOPF-V can only predict solutions in each single feeder with a separate DNN. As a result, DeepOPF-U uses \(44\%\) the storage space of DeepOPF-V, which can be even smaller with more feeders. Meanwhile, DeepOPF-U achieves a computation speed-up (compared to the conventional MIPS solver) similar to that of DeepOPF-V.

### _Performance in Expanding Feeders_

Consider the second set of feeders, which successively expands from \(73\), \(90\), \(106\), to \(118\) buses. Figure 2 shows their OPF objective values over time, solved by DeepOPF-U and the conventional MIPS solver. The result shows that DeepOPF-U can effectively track the OPF solutions in a time-varying (and load-varying) setting, with minor difference from the ground-truth solutions obtained by MIPS.

### _Comparision with State-of-the-Art Methods_

We compare the performance of DeepOPF-U with state-of-the-art DACOPF [1] and EACOPF [8] (at their default settings in the papers) on the IEEE \(2,000\)-bus feeder, as shown in Table III. Note that DeepOPF-U can solve OPF problems in \(57/118/300/2000\)-bus feeders with one unified NN, while the other two methods can only deal with one feeder with one NN. With such better generalizability, DeepOPF-U can still achieve good solution quality, especially more strict satisfaction of voltage constraints, and a significantly higher computation speed-up (compared to MIPS) than other two methods.

## V Conclusion

We proposed DeepOPF-U, a unified DNN to learn the load-to-solution mappings of AC OPF problems across multiple and expanding power networks. Simulation results on IEEE \(57/118/300\)-bus test systems and a system expanding from \(73\) to \(118\) buses demonstrate the adaptive mapping capability, good solution quality, and satisfactory computational speed of the unified DNN.

In the future, we will experiment on the best number of different power networks that can be effectively integrated into a unified DNN. We are also interested in exploring the similarities between OPF problems in different power networks, to characterize the performance of the unified DNN.
