{'fraction_non_alphanumeric': 0.031071198514645144, 'fraction_numerical': 0.006176347997423364, 'mean_word_length': 4.589157136806438, 'pattern_counts': {'":': 0, '<': 0, '<?xml version=': 0, '>': 0, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 4, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
Learning Optimal Solutions for Extremely Fast AC Optimal Power Flow

In this paper, we develop an online method that leverages machine learning to obtain feasible solutions to the AC optimal power flow (OPF) problem with negligible optimality gaps on extremely fast timescales (e.g., milliseconds), bypassing solving an AC OPF altogether. This is motivated by the fact that as the power grid experiences increasing amounts of renewable power generation, controllable loads, and other inverter-interfaced devices, faster system dynamics and quicker fluctuations in the power supply are likely to occur. Currently, grid operators typically solve AC OPF every 15 minutes to determine economic generator settings while ensuring grid constraints are satisfied. Due to the computational challenges with solving this nonconvex problem, many efforts have focused on linearizing or approximating the problem in order to solve the AC OPF on faster timescales. However, many of these approximations can be fairly poor representations of the actual system state and still require solving an optimization problem, which can be time consuming for large networks. In this work, we leverage historical data to learn a mapping between the system loading and optimal generation values, enabling us to find near-optimal and feasible AC OPF solutions on extremely fast timescales without actually solving an optimization problem.


I. INTRODUCTION
AC optimal power flow (OPF) problems are solved by grid operators in order to achieve the most economic generation dispatch to meet network power demands while adhering to the physical constraints of the network. With the increasing integration of fluctuating renewable energy sources, system operators are required to perform more frequent adjustments of the generators set-points. Currently, real-time adjustments are realized using the automatic generation control (AGC) which may lead to sub-optimal operational points due to the use of restrictive affine control policies. Various linearizations or approximations of the AC OPF problem have been developed throughout the years to address the computational burden of solving the AC OPF in real time, but in many cases cannot guarantee feasibility of the approximate solution, and still require solving an optimization problem, which can be prohibitive as the network size grows.
Very recently, machine learning (ML) approaches have been leveraged for solving difficult optimization tasks [13]- [18]. The data-driven nature of ML approaches is very pertinent as large quantities of measurements are being generated in modern systems but are not yet being fully utilized [19]. In the area of power systems, ML approaches have been proposed to recover the power systems state [20], to enhance solving optimal power flow problems (i.e., for learning a good starting point for AC OPF: [21], for learning the active set of the DC OPF problem: [22], [23]) and for directly bypassing the use of solvers or iterative methods to learn solutions in an online fashion (i.e. leveraging ML to obtain the solution of mixedinteger quadratic programs: [24], and for learning a feasible and optimal DC OPF solution: [25]).
In [23], neural networks are used to learn a mapping from uncertainty realizations to the active set of a DC OPF problem as an intermediate step towards learning the optimal solution. Once the active set is determined, the optimal solution to the original problem can be recovered by solving a linear system of equations. This work illustrated the benefits of using data to exploit the structure of the OPF problem and solve DC OPF on timescales appropriate for corrective control. However, showing the benefit of this particular framework for AC OPF problems, which are very difficult to solve in real time, has not yet been demonstrated. In addition, if the correct active set is not identified during the classification, the resulting solution of the DC OPF will be incorrect, and additional resources must be used for identifying the correct active set.
The work in [25] demonstrated that it is possible to learn the solution of the DC OPF problem directly and preserve feasibility. Encouraged by the extremely fast solution times for DC OPF with feasible solutions and negligible optimality losses when using a neural network in [25], we explored the potential and limitations of learning a mapping from the system loading to optimal generation setpoints and voltages in AC OPF. Towards this goal, we developed a framework for using learning to obtain solutions to AC OPF problems that lends itself to real-time applications without using the DC approximation or other linearizations of the problem.
Our approach thus offers the following benefits over traditional approaches to solve the the AC OPF problem and over learning approaches to solve the DC OPF problem: • There is no need to directly tackle the AC OPF optimization problem.
• No approximations, linearizations, or convexifications of the power flow equations are used. • No distributed techniques or computationally intensive platforms are needed; the neural network maps system loading onto optimal generation values and voltage magnitudes in roughly 1 millisecond on a laptop computer (in the considered networks). • Recovery of the full AC OPF solution is ensured through a fast iterative procedure, resulting in a final optimal and feasible solution. Recently, the authors of [16] proposed a machine learning model that targets approximating the AC OPF solutions directly. The AC OPF problem is treated as a regression task where the generator set-points are estimated from the grid demand profile. Fixing the active power injection at all generators, including the slack bus, drastically affects the feasibility of the solution. Hence, the reported feasibility percentage is almost 50% for a maximum of 10% change in the base load profile in a small network. In addition, the design of the learning approach in [16] does not allow for a post-processing step where a feasible solution is obtained by refining the infeasible solution. In addition, the design of the test scenarios with only 10% deviation without considering correlation makes the representativeness of the study questionable.
The emergence of learning techniques in general can be attributed to the availability of increased computing power and an abundance of data collection and storage. Within the power systems realm, a large quantity of data is generated by grid operators by repeatedly solving AC OPF problems throughout the day. This data is utilized for other tasks, and often is not stored for long periods of time, as grid operators struggle to see additional use cases for the data [19]. This paper demonstrates an additional purpose for this data by using it to train a neural network (offline) which can produce optimal solutions to the AC OPF problem (online). To achieve this, we learning a mapping from the network loads to the optimal generator set-points, where a novel parameterization of the AC OPF solutions is used to enforce generation limits. In addition, strictly feasible solutions are used to train the learning model, and the output of the model is constrained to adhere to active power generation and voltage magnitude constraints. In order to circumvent solutions that violate the system requirements, the solution feasibility is ensured by solving a set of power flow equations. Fig. 1 shows the architecture of the proposed approach in the operation phases. By using this framework, we can determine optimal generation set-points on timescales that are appropriate for balancing fast fluctuations in renewable generation and load.
The remainder of this paper is organized as follows. In Section II, the AC OPF problem formulation is presented. Then, the propoed learning approach is outlined in Section III, and the simulation results are presented in Section IV. Section V conculdes the paper and presents several directions for future research.

II. PROBLEM FORMULATION
In this section, we will describe the AC OPF problem and our data-driven approach to reformulate the problem appropriately. First, consider a power network with N buses collected in set N , and set G collects the set of nodes with generators, and set L collects the set of load buses. The nodal power injection at bus n ∈ N is denoted by p n + j q n . Also, let p g,n + j q g,n , and p l,n + j q l,n denote the power generated at bus n ∈ G and the load demand and bus n ∈ L, respectively. Note that the sets G and L are both subsets of N but need not to be disjoint. The voltage at bus n is denoted by v n , and define v := [v n ] n∈N , p := [p n ] n∈N , and q := [q n ] n∈N which collect the voltage phasors, active power injection, and reactive power injection at all buses, respectively. Therefore, the AC OPF problem can be formulated as where p g,n (q g,n ) and p g,n (q g,n ) denote the minimum and maximum active (reactive) power injection from the generator installed at bus n ∈ G, and |v| and |v| represent the lower and upper limits on the voltage magnitudes. The vector collecting the active power injection from all generators is denoted by p g , and the cost of generating power from the generator installed at bus n is denoted by c n (p g,n ). The nonlinear power flow equations are collected in the equality constraint (1e).
Given the active and reactive power demand at the load buses, the active power generated by the generators, and the voltage magnitudes at the generator buses, the vector v can be recovered by solving the power flow equations [26]. Utilizing this property, we treat the AC OPF problem as an operator with inputs representing the load profile while the generators' active power injections and voltage magnitudes are the output of this operator. In other words, we treat the OPF as an operator [27] with inputs comprising p l,n and q l,n for all n ∈ L and with output representing |v n | for buses n ∈ G and p g,n for nodes n ∈ G/{n 0 }, where n 0 is the index of the reference bus. Therefore, the goal of the proposed data-driven approach is learn the underlying OPF mapping between the load demand at all load buses and the generators' active power and voltage magnitude set-points.
Any active power generation p g,n that satisfies (1b) can be written as p g,n = p g,n + α n p g,n − p g,n , where 0 ≤ α n ≤ 1. Similarly, the voltage magnitude at bus n ∈ G can be parameterized by β n ∈ [0, 1] which is given by Define the sets A := [α n ] n∈G/{n0} |0 ≤ α n ≤ 1 and B := [β n ] n∈G |0 ≤ β n ≤ 1 . Therefore, the AC OPF operator can be written as where P l and Q l represent the sets of active and reactive load demand at all buses n ∈ L, respectively. Paremterizing the solution of the AC OPF problem using the parameters α n and β n will prove useful when approximating the mapping Ω using artificial neural networks.

III. LEARNING FEASIBLE AC OPF SOLUTIONS
Artificial neural networks (hereafter, NN) are well-suited for modeling high-dimensional, complex, non-linear relationships between input features and output variables. They are capable of considering massive amounts of training data (here, solutions to the AC OPF problem) and uncovering natural relationships in the data to perform classification or regression tasks extremely quickly. It is for this reason that they have been used previously for predicting OPF solutions [16], [25] and the active set of OPF problems [16], [23]. In this section, we discuss the generation of training data for the NN, training of the NN, and how the overall feasible solution to the AC OPF problem is obtained.

A. Approximating the mapping between loads and the optimal solution
In order to approximate the mapping Ω, we utilize a deep neural network model which leverages sigmoid activation functions. For finite-width deep neural networks, smooth functions can be approximated up to a specified accuracy which depends on the smoothness parameters of the function as well as the neural network size [20], [28]. That is, if a neural network g(·; θ) is optimally trained with samples of f (·) on a closed set, then the distance between the output of the neural networkŷ = g(·; θ) and ground-truth mapping y = f (·) can be bounded as where is function of the smoothness parameters of f (·) and the size of the neural network g(·; θ). As the solution of AC OPF is often on the boundary of the feasibility set [29], we aim at ensuring that the neural network outputs are in the interior of the AC OPF feasibility set.
In order to avoid these cases where the voltage magnitude is exactly at the maximum or the lower voltage limits, we generate the training by solving the following restricted AC OPF problem (R-ACOPF).
minimize v,{pg,n,qg,n} n∈G n∈G c n (p g,n ) (3a) subject to p g,n ≤ p g,n ≤ p g,n (3b) q g,n ≤ q g,n ≤ q g,n (3c) Therefore, the generated solutions are guaranteed to be in the interior of the feasibility region with respect to the voltage magnitudes. Note that this data-driven approach approximates a mapping that deviates from the original AC OPF mapping. However, the training samples generated by solving (3) are strictly in the interior of the voltage magnitudes feasibility set. Therefore, any bounded deviations in the learned mapping are expected to remain within the voltage limits. The parameter λ can thus be considered as an algorithmic tuning parameter that addresses the optimality and feasibility trade-off. Notice that large values of λ may render the original problem infeasible, and hence, the parameter λ has to be tuned in order to obtain strictly feasible solutions.
In addition, to ensure the generation limits adhere to the prescribed AC OPF constraints, we use sigmoid functions at the output layer of the NN. This ensures that the output is bounded between 0 and 1 for the values of α n and β n . Designing the output layer of the neural network to be a sigmoid function acts as an implicit constraint on the learned AC OPF mapping, which illustrates the reasoning for reparameterizing the AC OPF solutions in terms of α n and β n . Although enforcing general constraints on the output of the neural network makes the training process challenging, incorporating a sigmoid function at the output layer does not increase the complexity of the training process.

B. Generating training samples
In a physical grid, historical AC OPF runs would be used as the training set for the neural network, yielding an abundance of data representing a wide variety of system states. However, for the purposes of simulation and testing, we must generate this set of training data. Let p l ∈ R |L| denote the vector collecting the load demand at all load buses. We generate the instances of load demand using the truncated Gaussian distribution where p l,0 denotes a base loading profile, Σ l denotes the covariance matrix, and µ denotes the maximum allowable deviation from the base load profile, which we set to 0.7 in our simulations. The covariance matrix accounts for the relationships between loading patterns at different locations throughout the network. Here, we generated load profile realizations using a Gibbs sampler algorithm [30]. For considering deviations in the reactive power demand, we randomly chose the power factor of each load at each instance from a uniform distribution between 0.8 and 1. Rarely, the generated load profile can result in an infeasible solution for the AC OPF problem, and hence infeasible for the R-AC OPF problem as well. In such cases, we discard this load profile from the training set, as it does not represent a physically realizable state of the power system.

C. Learning model
A deep NN model (i.e., a NN with more than two layers) is used to approximate the mapping between the load profile and the optimal voltage magnitude and active power injections of the generators. The size of the input of the NN is 2|L| representing the active and reactive load demand at the load buses, and the number of outputs is 2|G| − 1 representing the voltage magnitude at the generator buses and the active power injection at all generators except the one at the slack/reference bus. Fig. 2 depicts the architecture of the deep NN learning model utilized in our approach. Let (x i , y i ) denote the i-th pair of data within the training set. The model is thus trained using the classical empirical loss minimization formulation which is given by where I represents the total number of the training samples, g(·; θ) represents the NN mapping where θ collects the trainable parameters.

D. Recovering feasible solutions
As mentioned in Section II, we pursue feasibility by both restricting the training set to include strictly feasible solutions and adhere to generation and voltage limits by constraining the output of the neural network. While this ensures feasibility of the learned values, the overall power flow equations and other generation constraints must be adhered to. Thus, the power flow equation are solved in order to recover and ensure feasibility of the overall AC OPF solution. Let p o g,n and |v o n | denote the output of the neural network representing the active power injection and voltage magnitude of bus n ∈ G. Then, solving the power flow problem can be formulated as follows where the output of the NN representing the voltage magnitude and active power injection at generator n are denoted by |v o n | and p o g,n , respectively. find v, p g , q g (4a) subject to |v n | = |v o n | ∀n ∈ G (4b) p g,n = p o g,n ∀n ∈ G/n 0 (4c) h(v, p g , q g ) = 0 (4d) In rare cases, the solution of the power flow equations result in reactive power injections at the generators that exceed the limits in (1c). Let the solution of the power flow equations in (4) representing the reactive power injection at bus n ∈ G be denoted by q o g,n . Also, denote the set of buses where the reactive power limits are violated by G Q . Then, we define q r g,n at the buses G Q as q r g,n = min(q g,n , max(q o g,n , q g,n )).
Consequently, a modified power flow problem is to be solved in order to obtain the feasible operating point of the network which is formulated as The proposed approach is summarized in Algorithm 1. While an additional small amount of time is needed to solve the power flow equations and check the feasibility of all of the remaining variables, the overall solution procedure from end-to-end is extremely fast, as we are dealing with a simpler problem which is solving the power equations and not solving a nonconvex optimization problem. In addition, note that the objective function value in the original problem (1) is not altered by adjusting reactive power and voltage to preserve feasibility.
Algorithm 1 Proposed learning-based approach for AC OPF Input: {p l,n , q l,n } n∈L for n ∈ G Q do q r g,n ← min q g,n , max{q o g,n , q g,n } end {v r , p r g , q r g } ←− solution of (6) end end

IV. SIMULATION RESULTS
In this section, we discuss the considered networks and analyze the optimality and feasibility obtained using the proposed approach. MATPOWER [31] was used to generate 100, 000 training samples for each considered network and to solve the power flow equations for the obtained optimal generator setpoints. Table I shows the number of nodes, generators, lines, and the base operating costs of the IEEE 118-, 57-, and 39-bus systems used in this paper. For the NN network model, we utilized a NN with 3 hidden layers with sigmoid activation function for all layers. The width of the first two hidden layers is equal to the number of inputs (2|L|) and the width of the third hidden layer is equal to the number of outputs (2|G| − 1) for all networks. The learning model was implemented using the Python-based TensorFlow software library [32] and trained using the Adam optimizer [33].

B. Time comparisons
We denote the time consumed to obtain an AC OPF solution using our method for the t-th test instance by τ o,t , where this time includes the time needed to evaluate the neural network, the time needed to solve the power flow equations, and the time consumed by solving any additional power flow equations to ensure the feasibility of the solution. For comparison purposes, let τ OPF,t denote the time consumed by the 'PDIPM' (primal-dual interior point method) solver to solve the original AC OPF problem optimally. In the considered experiments, this solver was on average the fastest and most successful solver. To measure the computational improvements, we define a speedup factor (SF) as which we can use to measure the relative speedup of the learning-based framework versus solving the AC OPF directly. In Fig. 3, the relative histogram of the speedup factor is depicted for the IEEE 118-bus network with λ = 0.005. The speedup factor ranges from 6x to 22x for this case, which shows the potential of proposed approach to identify feasible AC OPF solutions extremely quickly, even in the slower cases. The two humps in the histogram result from the fact that the second stage of the algorithm is only needed for a portion of the test cases.

C. Feasibility and optimality
After passing the network demands through the learning model, we obtain the generator set-points. Those set points are guaranteed to satisfy constraints (3b) and (3d) given the design of the output layer of the neural network. Further, to ensure feasibility of the overall AC OPF solution, the infeasibility of the generated solution with respect to the reactive power limit constraints (3c) needs to be ensured by solving the power flow equations, as outlined in problem (6). We evaluate the infeasibility of this constraint for the solutions obtained directly using our learning model by defining a metric δ q which is given by where ξ q,t collects all the reactive power limit violations across all buses. The n-th element of the vector ξ q,t is given by ξ q,t,n = max{q g,n − q o g,n , 0} + max{q o g,n − q g,n , 0}, where q r g,n denote the recovered reactive power injection at bus n by solving the power flow equations at the set point given by the output of the neural network.
Let p g denote the optimal generation set-points obtained by solving the AC OPF problem (1), and denote the generators' active power injection set-points obtained by our data-driven approach by p o g . The average optimality of the solutions obtained through the proposed approach is evaluated with the following , where c(p o g,t ) and c(p g,t ) denote the total objective function value resulting from the solution obtained using our approach  and the optimal cost found from solving the original AC OPF, respectively. Denote by p o t , q o t , and v o t the solution obtained using our approach for a particular test scenario t. The feasibility of the solution is measured by assessing the satisfaction of the power flow equations. The maximum infeasibility is thus evaluated as follows: Tables II, III, and IV illustrate the results from evaluating 1, 000 AC OPF test scenarios for each network. In the 118bus test case, the initial infeasibility of the solution is higher when the value of lambda is set to be zero. This is attributed to the fact that the training samples in this case (λ = 0) are on the boundary on the original problem feasibility set. For this reason, we did not include the results for (λ = 0) for the other test cases.
As seen in all of the network simulations, the maximum infeasibility observed in the all of the test scenarios is very low (and well-within most solver tolerances for feasibility). The average computational speedup by using the data-driven approach versus solving the AC OPF directly is also significant, ranging from nearly a 8x speedup factor up to over a 15x SF. These tables also show the average infeasibility, δ q , of the reactive power limits (3c) encountered, in MVAR, after solving the power flow equations with the learned generator active power set-points and voltages. Note, however, that the feasibility of these constraints is ensured using the procedure in Algorithm 1, and the time required to do this is taken into account in the results.
Further restricting the feasible set of voltages by increasing λ from 0.005 to 0.01 generally has a positive impact on feasibility while mildly impacting the overall optimality of the solution. However, regardless of the λ chosen here, the impact on the optimality of the learned solution is minimal for all considered networks, indicating that using the learningassisted approach of recovering AC OPF solutions can pre- serve optimality and feasibility while providing significant computational speedups.

V. CONCLUSIONS AND FUTURE WORK
In this paper, we presented a framework for solving AC OPF problems which utilizes machine learning to learn a mapping between system loading and optimal generation values. We provided a method to guarantee feasibility of the solution in the original AC OPF problem by training the model on strictly feasible solutions and then solving the power flow equations to recover the remainder of the complex network voltages and the reactive power generation values. From start to finish, the framework can recover a feasible solution to the AC OPF problem extremely quickly with a negligible sacrifice in optimality. Thus, the learning framework is overall faster and can provide a more accurate solution than the use of traditional methods that are used to solve AC OPF quickly such as linearizing or approximating the nonlinear power flow equations.
Future work includes exploring the efficacy of this framework on much larger networks (i.e., thousands of buses), and using learning to solve computationally intense, mixed integer problems such as security constrained AC OPF problems on faster timescales. The results in this paper also prove encouraging for using learning as a tool for quickly finding solutions to nonconvex optimization problems in areas outside of power systems. In potential applications where learning the optimal solution while ensuring feasibility is not possible or very difficult, we ask the reader to consider developing or using learning-assisted or learning-enhanced optimization techniques, wherein machine learning and optimization work hand-in-hand to find optimal solutions of the original problem, either by using learning to quickly find a starting point for the optimization, or by learning the solution of a subset of variables.