{'fraction_non_alphanumeric': 0.027885178676039835, 'fraction_numerical': 0.005565319273579379, 'mean_word_length': 4.732370718603089, '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': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
SAVER: Safe Learning-Based Controller for Real-Time Voltage Regulation

Fast and safe voltage regulation algorithms can serve as fundamental schemes for achieving a high level of renewable penetration in the modern distribution power grids. Faced with uncertain or even unknown distribution grid models and fast-changing power injections, model-free deep reinforcement learning (DRL) algorithms have been proposed to find the reactive power injections for inverters while optimizing the voltage profiles. However, such data-driven controllers can not guarantee satisfaction of the hard operational constraints, such as maintaining voltage profiles within a certain range of the nominal value. To this end, we propose SAVER: SAfe VoltagE Regulator, which is composed of an RL learner and a specifically designed, computational efficient safety projection layer. SAVER provides a plug-and-play interface for a set of DRL algorithms that guarantees the system voltages to be within safe bounds. Numerical simulations on real-world data validate the performance of the proposed algorithm.

projection for safe voltage control policy, yet it only works for the special case where only one single node's voltage hits the safety boundary, while this paper's safety layer works for the general voltage safety set.
The advantages of applying the proposed data-driven voltage regulator are multi-fold. First, it utilizes the empirically proven advantages of RL algorithms to search the space of neural network parameterized voltage controllers, that can optimize the voltage derivations and control costs without the exact grid information. Second, it limits the search of the safe policy only to local control actions within the neighborhood of a trained RL policy, adding little computation burden for the resulting controller. Third, the use of such a safety layer encodes the physical constraints, and opens the door for designing a practical controller for inverters.

II. PRELIMINARIES: POWER FLOW MODELS AND PROBLEM FORMULATION
In this work, we focus on the voltage regulation model for a radial distribution network. We use the graph G = (N ∪ {0}, E) to represent a radial distribution feeder with N + 1 buses with bus 0 denoting the reference bus, and E is the set of connected transmission lines. we denote p ∈ R N and q ∈ R N as the nodal active and reactive power injections respectively.
The relationship between the voltage and power injections can be stated as power flow equations. For each line, denote s ik = p ik + jq ik as the complex power flow from bus i to bus k, and denote the line impedance as z ik = r ik + jx ik . We adopt the DistFlow formulation [15] as follows (1) defines a nonlinear relationship between the active power injection p, reactive power injection q, and the nodal voltage magnitude v. We consider our control devices are inverter-based DERs (such as renewable generators, battery energy storage), that can change their reactive power output q in a fast timescale to provide voltage regulation. Denote the set of controllable q i , i ∈ C using the set of nodes C. At each time step, the optimal voltage regulation problem can be then formulated as follows: The control objective (2a) is to reduce the total control cost for controllable inverters plus the penalty on voltage deviation for all buses, with η as a hyperparameter that balances the weights of the two costs. System operators can choose different function forms of c q i (·) and c v i (·) to achieve operational goals. Equation (2b) is the voltage safety constraints that should be ensured at each time step.
The challenge of directly solving (2) lies in the fact that even though we can design a convex cost function (e.g., a quadratic cost over reactive power injection and squared loss of voltage deviation), the underlying power flow (1) is nonlinear and nonconvex, making directly solving the optimization problem involving (2b) a hard problem. For the convex relaxation methods based on SOCP or SDP formulations, even though the resulting optimization problem is tractable, it needs the exact information on grid topology and line parameters. In addition, it can take a significant amount of time to solve the optimization problem for large grids, which may not fulfill the goal of achieving fast timescale voltage regulation. These challenges lead to the design need for a computationally efficient model-free controller.

III. LEARNING A VOLTAGE REGULATOR
In this section, we describe how we formulate the voltage regulation problem as a RL problem, and illustrate the need for explicitly incorporating safety as a constraint for standard RL algorithm.
RL provides a powerful paradigm for solving (2), in the sense that during the training process, we can train a policy network that maps the states to reactive power injections, to minimize the control objectives defined by (2a). First, we define a Markov Decision Process (MDP) of 4-tuple (S, A, P, r) to represent the voltage control model. The states and actions for timestep t can be defined as, Without loss of generality, in this paper, we use s(t), a(t) and s, a interchangeably. The state transition model P : S×A → S, is determined by the power flow equations (1) and external dynamics such as renewable generation and nodal demand; and r : S × A → R is a scalar function that is defined as follows where v 0 = v 0 · 1 and v 0 is the feeder head voltage.
To summarize, given MDP model and an initial policy π θ , the RL for optimal voltage control problem is formulated as where π θ (s t ) are the parameters of the voltage control policy, and S represent the set of safety constraint. γ is a discount factor. To be more specific, c(s(t), a(t)) refers to the state safety constraint v j ≤ v j (p, q) ≤v j , j ∈ N . The underlying dynamics including external variable v ext is modeled as (5d). During the training phase, RL agent interacts with the environment driven by the power flow equations, and learns the reactive power dispatch a = π θ (s) to maximize the accumulated discounted reward. Recent developments of deep RL models have enabled a set of deep learning based algorithms to efficiently solve such reward maximization problem, such as Deep Q Learning for discrete actions (e.g., tap position) [16], and Deep Deterministic Policy Gradient (DDPG) for continuous actions [17]. However, one intrinsic challenge for DRL policies is to validate the policies given by deep neural networks can always guarantee the voltage staying within the safe region [v i ,v i ], i ∈ N . This is due to the fact that during the DRL training stage, the RL agent only focused on maximizing the reward while there is no hard constraint on π θ to ensure safety. In addition, even if the learned policy appears "safe" on the training data (with finite training episodes), it is not guaranteed to be safe under all scenarios. The lack of formal safety guarantees is a major obstacle in the deployment of RL to real-world power systems, as a violation of safe operation constraints can lead to severe impacts such as voltage collapse and cascading failure. Motivated by the challenge above, our goal is to ensure the RL algorithm obtain provably safety guarantee during both policy training and policy deployment (after training).

IV. SAFETY VOLTAGE LAYER
In this section, we will first discuss how to explicitly obtain the safety constraints for the RL controller with a tractable form. We will then describe our proposed safe controller design.
To ensure safety during both training and execution, we first need to identify unsafe actions, and then modify the reactive power injections so that the voltage is within safe bounds. We achieve this by incorporating the power flow relationship in a compact way for the learned RL agents. In the original DistFlow formulation, we can further neglect the line loss via setting By collecting v = [v 1 , ..., v n ] T and substituting p ij and q i j into the last equation of (6), we can represent the voltage profile in a more compact form where v 0 is the voltage for the feeder head, and R and X are positive matrices. Once we get the policy π θ and the safety constraint model for the voltage profile, we want to find the reactive power injections that avoid unsafe voltage deviations. At each control time step, it leads to the following optimization problem By solving (8), we find q which are not only close to the action given by the deep RL agent, but also satisfy the hard constraints over nodal voltage.
Since (8) is a convex, quadratic optimization problem, and we can use standard QP-solvers to solve it efficiently in polynomial time [18]. Alternatively, we can first learn the active constraints, and then use the closed-form solution for the equality constrained problem. If there is at most one constraint that is tight, [13] developed a closed-form solution. However, for voltage control, there is usually more than one constraint on voltage magnitude that can be active. Therefore, we need to solve (8) rather than using the closed-form solution, unless all active constraints can be identified beforehand [19]. In the following, we also give two remarks regarding the linear power flow model and the model knowledge.
Remark 1 Effects of Power Flow Linear Approximation (7): We note that in our safety layer design, the use of linearized power flow is restricted to validate if the policy π θ gives safe voltage. Thus we are not losing the representation capability of deep RL on the complex relationship between power injections and voltage. Moreover, the linear DistFlow model has been proved accurate verified by real-world data when estimating the voltage box constraints in (8) [20].
Remark 2 Knowledge of Distribution Grid: Another assumption we make for the proposed safety layer is that we can explicitly write out the inequality constraints involving grid parameters R and X. Such assumption can be justified when the RL agent has access to historical grid operational data, and can therefore employ machine learning or statistical methods to estimate these parameters. There are also emerging techniques for estimating both the network topology and line parameters for distribution grid with observational data [5], [21]. We leave the discussion of incorporating model learning error to tighten voltage safety range [v, v] to future work.

V. CASE STUDY
In this section, we demonstrate the effectiveness of the proposed safety layer method for voltage control. Specially, we show that by incorporating the safety layer in a standard deep deterministic policy gradient (DDPG) [17] algorithm, we can always find actions satisfying voltage constraints. We compare the proposed safety layer with baseline linear policy or deep RL methods, and validate the improved performance in terms of control costs and safety measures.
Experiment Setup Throughout the simulation, we use the IEEE 13-bus test feeder to validate the algorithm performance. We use real-world load data from CAISO 1 , and normalize the demand value based on the 13-bus system configurations. The nominal voltage magnitude at each bus is 12kV , and we allow ±5% voltage deviation for each node. We visualize 20 sample days of training data in Fig. 2.
We employ DDPG algorithm to train the deep RL agent, and we employ 3-layer neural networks for both the policy network and value network in the DDPG agent. For each episode, we collect rollouts for 24 hours, and we also keep a replay buffer for states throughout RL training process.
For model comparison, we also use a linear policy to output the reactive power injections. Such linear policy actively considers the voltage magnitude bound, but may take non-optimal control actions which incur larger system costs or short-term voltage violations. We refer readers to [22] for the details of such an algorithm. For the implementation of all the algorithms, we also constrain the reactive power injections within box constraints considering the regulating capabilities of the inverter of each DER. Once we get the control actions from each controller, we use the full power flow model to calculate the resulting voltage. We test the performance of the proposed safe RL approach, standard RL approach, and baseline linear policy using a high-resolution real-world load and renewable data in Fig 3 (left). Based on the time resolution of the PV and load trajectory, controllers adjust their control output every 6s. We use Pytorch to build all RL models and run the training process. We report the computation time in MacBook Pro Personal Laptop with 16 GB 2400 MHz DDR4 memory and 2.2 GHz Intel Core i7 processor.
Simulation Results We first compare the voltage profile using three different control schemes. In Fig. 3, we show the nodal voltage magnitude for one day's test data. It can be seen that all three algorithms take actions to try to stabilize the voltage within the safe region ([11.4kV, 12.6kV ]). But during the middle of the day, both linear controller and standard RL agent lead to greater voltage deviation than the operational limits. The linear policy is relatively "slow" in the sense of acting to load and renewables generation change, causing the spikes in voltage profiles. The RL agent finds the control actions using least control efforts (which will be explained in detail in Table I), but more than half of nodal voltage at noon are exceeding the upper limits. This shows that even though the trained RL agent is able to find control actions to maximize the reward, such training scheme can not exclude unsafe voltage deviations during test time. On the contrary, the proposed safe layer helps maintain voltage staying within the safety bounds. We can further observe that the resulting safe policy manages to reduce the voltages for multiple buses at the same time, meaning that it is possible to refine a trained RL agent to explicitly handle the hard, safety constraints.
In Fig. 4, we look into the nodal voltage profile, where mean and variance of voltage deviation are plotted for the three methods. We can observe that linear policy leads to voltage profile with the largest deviation across all buses, which shows that the linear model may not achieve satisfactory performance faced with renewables integration in the distribution grid. On average, the safe RL policy can reduce the voltage deviation by more than 30% compared to RL counterparts, showing the necessity of incorporating safety constraints into model-free algorithm design.
We report the statistics for solution time, average control efforts, and control results in Table I. Evaluations are based on simulation results for all 14420 test data samples. The linear policy and RL agent take nearly the same time to compute the reactive power injections. The safe RL does not add much burden to the fast RL policy inference process. The average computation time for the safe RL method is still much smaller than the control step resolution (6s), making it realistic to implement for real-time voltage regulation. This shows that the benefits of the proposed algorithm: with minimal added  computational costs, we can find safe policies as a plug-in-play module for off-the-shelf RL algorithms. And all three methods take much shorter time than solving a model-based optimization problem, e.g., by taking SOCP relaxation on the voltage regulation task [6]. Note that in practice, we can also resort to the safety layer computation to mini-batches for parallel computation, which can further accelerate the solution process of the proposed algorithm. The effects of the safety layer are further reflected in the average reactive power injection, and the occurrences of unsafe voltage deviation. As is shown in Table I, safe RL may take more reactive power resources to achieve the regulation task. But compared to both linear policy and standard DDPG agent, the safe RL agent can guarantee for almost all test instances, the resulting voltages are safe. Only for 0.01% of the test samples, safe RL can not find a safe policy, which may be caused by the representation limitation of the linearized power flow model, or the inability to find feasible control actions by only controlling reactive power injections at DER buses.

VI. CONCLUSION AND DISCUSSION
In this work, we present SAVER, a computationally efficient safe layer for model-free learning-based voltage regulators. By explicitly taking the constraints on voltage magnitude into controller design, we show the resulting controller can always output reactive power injections that guarantee voltage safety. Simulation results demonstrate such safety layer involving linear constraints over the voltage magnitude can be an effective plug-in module for off-the-shelf deep RL algorithms. For future work, we will explore how to autonomously identify the nonlinear relationship between reactive power injections and nodal voltages and ensure safe control at the same time. More advanced safe control schemes based on both active and reactive power injections will also be investigated.