DC3: A LEARNING METHOD FOR OPTIMIZATION WITH HARD CONSTRAINTS
Anonymous authors
Paper under double-blind review
A BSTRACT
Large optimization problems with hard constraints arise in many settings, yet classical solvers are often prohibitively slow, motivating the use of deep networks as cheap “approximate solvers.”
Unfortunately, naive deep learning approaches typically cannot enforce the hard constraints of such problems, leading to infeasible solutions.
In this work, we present Deep Constraint Completion and Correction (DC3), an algorithm to address this challenge.
Speciﬁcally, this method enforces feasibility via a differentiable procedure, which implicitly completes partial solutions to satisfy equality constraints and unrolls gradient-based corrections to satisfy inequality constraints.
We demonstrate the effectiveness of DC3 in both simple quadratic programming tasks and the real-world setting of AC optimal power ﬂow, where hard constraints encode the physics of the electrical grid.
In both cases, DC3 achieves near-optimal objective values while preserving feasibility.
I NTRODUCTION
Traditional approaches to constrained optimization are often expensive to run for large problems, necessitating the use of inexpensive function approximators.
Neural networks are fast to compute and have high expressivity, making them ideal as function approximators.
However, while deep learning has proven its power for unconstrained problem settings, it has struggled to perform well in domains where it is necessary to satisfy hard constraints at test time.
For example, in power systems, weather and climate models, materials science, and many other areas, data follows wellknown physical laws, and violation of these laws can lead to answers that are unhelpful or even nonsensical.
There is thus a need for fast, optimal neural network approximators that can operate in settings where traditional optimizers are slow (such as non-convex optimization), yet where strict feasibility criteria must be satisﬁed.
In this work, we introduce Deep Constraint Completion and Correction (DC3), a framework for applying deep learning to optimization problems with hard constraints.
Our approach embeds differentiable operations into the training of the neural network to ensure feasibility.
Speciﬁcally, the network outputs a partial set of variables with codimension equal to the number of equality constraints, and completes this partial set into a full solution.
This completion process guarantees feasibility with respect to the equality constraints and is differentiable (either explicitly, or via the implicit function theorem).
We then ﬁx any violations of the inequality constraints via a differentiable correction procedure based on gradient descent.
Together, this process of completion and correction ensures feasibility with respect to all constraints.
Further, this process is fully differentiable and can be incorporated into standard deep learning methods.
Our key contributions are:
• Framework for incorporating hard constraints.
We describe a general framework, DC3, for incorporating (potentially non-convex) equality and inequality constraints into deeplearning-based optimization algorithms.
• Practical demonstration of feasibility.
We implement the DC3 algorithm in both convex and non-convex optimization settings. We demonstrate the success of the algorithm in producing approximate solutions with signiﬁcantly greater feasibility than other deep learning approaches, while maintaining near-optimality of the solution.
• AC optimal power ﬂow.
We show how the general DC3 framework can be used to optimize power ﬂows on the electrical grid. This difﬁcult non-convex optimization task must be solved at scale and is especially critical for renewable energy adoption. Our results greatly improve upon the performance of general-purpose deep learning methods on this task.
R ELATED W ORK
Our approach is situated within the broader literature on fast optimization methods, and draws inspiration from literature on implicit layers and on incorporating constraints into neural networks.
We brieﬂy describe each of these areas and their relationship to the present work.
Fast optimization methods.
Many classical optimization methods have been proposed to improve the practical efﬁciency of solving optimization problems.
These include general techniques such as constraint and variable elimination (i.e., the removal of non-active constraints or redundant variables, respectively), as well as problem-speciﬁc techniques (e.g., KKT factorization techniques in the case of convex quadratic programs)
(Nocedal & Wright, 2006).
Our present work builds upon aspects of this literature, applying concepts from variable elimination to reduce the number of degrees of freedom associated with the optimization problems we wish to solve.
In addition to the classical optimization literature, there has been a large body of literature in deep learning that has sought to approximate or speed up optimization models.
As described in reviews on topics such as combinatorial optimization (Bengio et al., 2020) and optimal power ﬂow (Hasan et al., 2020), machine learning methods to speed up optimization models have thus far taken two main approaches.
The ﬁrst class of approaches, akin to work on surrogate modeling (Koziel & Leifsson, 2013), has involved training machine learning models to map directly from optimization inputs to full solutions.
However, such approaches have often struggled to produce solutions that are both feasible and (near-)optimal.
The second class of approaches has instead focused on employing machine learning approaches alongside or in the loop of optimization models, e.g., to learn warmstart points (e.g., see Baker (2019)) or to enable constraint elimination techniques by predicting active constraints (e.g., see Misra et al.
We view our work being part of the former set of approaches, but drawing important inspiration from the latter: that employing structural knowledge about the optimization model is paramount to achieving both feasibility and optimality.
Constraints in neural networks.
While deep learning is often thought of as wholly unconstrained, in reality, it is quite common to incorporate (simple) constraints within deep learning procedures.
For instance, softmax layers encode simplex constraints, sigmoids instantiate upper and lower bounds,
ReLUs encode projections onto the positive orthant, and convolutional layers enforce translational equivariance (an idea taken further in general group-equivariant networks (Cohen & Welling, 2016)).
Recent work has also focused on embedding specialized kinds of constraints into neural networks, such as conservation of energy (see, e.g., Greydanus et al.
(2019) and Beucler et al.
and homogeneous linear inequality constraints (Frerix et al., 2020).
However, while these represent common “special cases,” there has to date been little work on building more general hard constraints into deep learning models.
Implicit layers.
In recent years, there has been a great deal of interest in creating structured neural network layers that deﬁne implicit relationships between their inputs and outputs.
For instance, such layers have been created for SAT solving (Wang et al., 2019), ordinary differential equations (Chen et al., 2018), normal and extensive-form games (Ling et al., 2018), rigid-body physics (de Avila
Belbute-Peres et al., 2018), sequence modeling (Bai et al., 2019), and various classes of optimization problems (Amos & Kolter, 2017; Donti et al., 2017; Djolonga & Krause, 2017; Tschiatschek et al., 2018;
Wilder et al., 2018; Gould et al., 2019).
(Interestingly, softmax, sigmoid, and ReLU layers can also be viewed as implicit layers (Amos, 2019), though in practice it is more efﬁcient to use their explicit form.)
In principle, such approaches could be used to directly enforce constraints within neural network settings, e.g., by projecting neural network outputs onto a constraint set using quadratic programming layers (Amos & Kolter, 2017) in the case of linear constraints, or convex optimization layers (Agrawal et al., 2019) in the case of general convex constraints.
However, given the computational expense of such optimization layers, these projection-based approaches are likely to be inefﬁcient.
Instead, our approach leverages insights from this line of work by using implicit differentiation to backpropagate through the “completion” of equality constraints in cases where these constraints cannot be solved explicitly (such as in AC optimal power ﬂow).
DC3: D EEP C ONSTRAINT C OMPLETION AND C ORRECTION
In this work, we consider solving families of optimization problems for which the objectives and/or constraints vary across instances.
Formally, let x ∈ R
d
denote the problem data, and y ∈ R n denote the solution of the corresponding optimization problem (where y depends on x ).
For any given x , our aim is then to ﬁnd y solving:
[Equation]
(where f , g , and h are potentially nonlinear and non-convex).
Solving such a family of optimization problems can be framed as a learning problem, where an algorithm must predict an optimal y from the problem data x .
We consider deep learning approaches to this task – that is, training a neural network N θ , parameterized by θ , to approximate y given x .
A naive deep learning approach to approximating such a problem involves viewing the constraints as a form of regularization.
That is, for training examples x
( i ) , the algorithm learns to minimize a composite loss containing both the objective and two “soft loss” terms representing violations of the equality and inequality constraints:
[Equation]
An alternative framework (see, e.g., Zamzam & Baker (2019)) is to use supervised learning on examples ( x ( i ) , y ( i ) ) for which an optimum y ( i ) is known.
In this case, the loss is simply ||
ˆ y − y
( i ) ||
However, both these procedures for training a neural network can lead in practice to highly infeasible outputs (as we demonstrate in our experiments), because they do not strictly enforce constraints.
To address this challenge, we introduce the method of Deep Constraint Completion and Correction (DC3), which allows hard constraints to be integrated into the training of neural networks.
In particular, the DC3 method includes the following two innovations:
Equality completion.
We provide a mechanism to enforce equality constraints during training and testing, inspired by the literature on variable elimination.
Speciﬁcally, rather than outputting the full-dimensional optimization solution directly, we ﬁrst output a subset of the variables, and then infer the remaining variables via the equality constraints – either explicitly, or by solving an implicit set of equations (through which we can then backpropagate via the implicit function theorem).
Inequality correction.
We correct for violation of the inequality constraints by mapping infeasible points to feasible points using an internal gradient descent procedure that is itself differentiable during training.
This allows us to ﬁx inequality violations while taking steps along the manifold of points satisfying the equalities, which yields an output that is feasible with respect to all constraints.
Overall, our algorithm is to train a neural network N θ ( x ) to output a partial set of variables z .
These variables are then completed to a full set of variables ˜
y satisfying the equality constraints.
In turn, ˜ y is corrected to ˆ y to satisfy the inequality constraints while continuing to satisfy the equality constraints.
The overall network is trained using backpropagation on the soft loss described in
Equation (2) (which is necessary for correction, as noted below).
Importantly, both the completion and correction procedures are differentiable either implicitly or explicitly (allowing network training to take them into account), and the overall framework is agnostic to the choice of neural network architecture.
Pseudocode for this full procedure is given in Algorithm 1.
We note that as this procedure is somewhat general, in cases where constraints have additional structure, specialized techniques may be more appropriate to use.
For instance, while we examine linearly-constrained settings in our experiments for the purposes of illustration, in practice, techniques such as Minkowski-Weyl decomposition or Cholesky factorization (see Frerix et al.
Amos & Kolter (2017)) may be more efﬁcient in these settings.
However, for more general settings without this kind of structure – e.g., for non-convex problems such as AC optimal power ﬂow, which we examine in our experiments – the DC3 framework can provide a (differentiable) mechanism for satisfying hard constraints in practice.
We now describe the completion and correction procedures in more detail.
1: assume equality completion procedure ϕ x : R m → R n − m // to solve equality constraints 2: 3: procedure TRAIN ( x ) 4: init neural network N θ : R d → R m 5: while not converged do 6: compute partial set of variables z
= N θ ( x ) 7: complete to full set of variables ˜
y
= (cid:2) z T ϕ x ( z ) T (cid:3) T ∈ R n 8: correct to feasible (or approx. feasible) solution ˆ y = ρ ( t train ) x (˜ y ) 9: compute constraint-regularized loss (cid:96) soft (ˆ y ) 10: update θ using ∇ θ (cid:96) soft (ˆ y ) // e.g., via GD 11: end while 12: end procedure 13: 14: procedure TEST ( x , N θ ) 15: compute partial set of variables z = N θ ( x ) 16: complete to full set of variables ˜
y
= (cid:2) z T ϕ x ( z ) T (cid:3) T 17: correct to feasible solution
ˆ y =
ρ ( t test )
(˜ y ) 18: return ˆ y 19: end procedure
3. E QUALITY COMPLETION
Assuming that the problem (1) is not overdetermined, the number of equality constraints h x ( y )
=must not exceed the dimension of the decision variable y ∈ R n : that is, the number of equality constraints equals n − m for some m ≥ 0 .
Then, given m of the entries of a feasible point y , the other ( n − m ) entries are, in general, determined by the ( n − m ) equality constraints.
We exploit this observation in our algorithm, noting that it is considerably more efﬁcient to output a point in R m and complete it to a point y ∈ R n such that h x ( y ) = 0 , as compared with outputting full-dimensional points y ∈ R n and attempting to adjust all coordinates to satisfy the equality constraints.
In particular, we assume that given m entries of y , we either can solve for the remaining entries explicitly (e.g. in a linear system) or that we have access to a process (e.g. Newton’s Method) allowing us to solve any implicit equations.
Formally, we assume access to a function ϕ
x : R m → R n − m , such that h x (cid:16)(cid:2) z T ϕ x ( z ) T (cid:3) T (cid:17) = 0 , where (cid:2)
z T ϕ x ( z ) T (cid:3) T is the concatenation of z and ϕ x ( z ) .
In our algorithm, we then train our neural network N θ to output points z ∈ R m , which are completed to (cid:2)
z T ϕ x ( z ) T (cid:3) T ∈ R n .
A challenge then arises as to how to backpropagate the loss during the training of N θ if ϕ x ( z ) is not a readily differentiable explicit function – for example, if the completion procedure uses Newton’s Method.
We solve this challenge by leveraging the implicit function theorem, as e.g. in OptNet (Amos & Kolter, 2017) and SATNet (Wang et al., 2019).
This approach allows us to express, for any training loss (cid:96) , the derivatives d (cid:96) /
d z using d (cid:96) /
d ϕ x ( z ) .
Namely, let J h ∈ R ( n − m ) × n denote the Jacobian of h x ( y ) with respect to y .
By the chain rule:
[Equation]
which yields
[Equation]
We can then backpropagate losses through the network by noting that
[Equation]
We note that in practice, the Jacobian ∂ϕ x ( z ) / ∂z should generally not be computed explicitly due to space complexity considerations; instead, it is often desirable to form the result of the left matrix- vector product ( ∂(cid:96) /
∂ϕ x ( z ) )
( ∂ϕ x ( z ) / ∂z ) directly.
This process is well-described in e.g. Amos & Kolter (2017), and also in detail for the problem of AC optimal power ﬂow in Appendix C.
I NEQUALITY CORRECTION
While the completion procedure described above guarantees feasibility with respect to the equality constraints, it does not ensure that the inequality constraints will be satisﬁed.
To additionally ensure feasibility with respect to the inequality constraints, our algorithm incorporates a correction procedure that maps the outputs from the previous step into the feasible region.
In particular, we employ a gradient-based correction procedure that takes gradient steps in z towards the feasible region along the manifold of points satisfying the equality constraints .
Let ρ x ( y ) be the operation that inputs a point y = (cid:2)
z T ϕ x ( z ) T (cid:3) T and moves it closer to satisfying the inequality constraints by taking a step along the gradient of the inequality violation with respect to the partial variables z .
Formally, for a learning rate γ > 0 , we deﬁne:
[Equation]
While gradient descent methods do not always converge to global (or local) optima for general optimization problems, if initialized close to an optimum , gradient descent is highly effective in practice for non-pathological settings (see e.g. Busseti et al.
; Lee et al.
At test time, the input to the DC3 correction procedure should already be close to feasible with respect to the inequality constraints, as it is the output of a differentiable completion process that is trained using the soft loss (cid:96) soft . Therefore, we may expect that in practice, the limit lim t →∞ ρ ( t ) x ( y ) will converge to a point satisfying both inequality and equality constraints (while for problems with linear constraints as in § 4.1, the correction process is mathematically guaranteed to converge).
As the limit lim t →∞ ρ ( t ) x ( y ) is difﬁcult to calculate in practice, we make approximations at both training and test time.
Namely, we apply ρ ( t ) x ( y ) to the output of the completion procedure, with t =
t train relatively small at train time (to allow backpropagation through the correction) and t = t test relatively large at test time (to ensure convergence to a feasible point).
E XPERIMENTS
We evaluate DC3 both in a simple quadratic programming (QP) setting and on the real-world task of AC optimal power ﬂow (ACOPF).
In particular, we assess our method on the following criteria:
• Optimality : How good is the objective value f x ( y ) achieved by the ﬁnal solution?
• Feasibility : How much, if at all, does the solution violate the constraints?
Speciﬁcally, what are the maximum and mean feasibility violations of the inequality and equality constraints:
max(ReLU( g x ( y ))) , mean(ReLU( g x ( y ))) , max( h x ( y )) , and mean( h x ( y )) ?
• Speed : How fast is the method?
We compare DC3 against the following methods (referred to by abbreviations in our tables below):
• Optimizer :
A traditional optimization solver.
For QP settings, we use OSQP (Stellato et al., 2020), as well as the batched, differentiable solver qpth developed as part of OptNet (Amos & Kolter, 2017).
For ACOPF, we use the solver provided by PYPOWER , a Python port of MATPOWER (Zimmerman et al., 1997).
• NN : A simple deep learning approach trained to minimize a soft loss (Equation (2)). [Table]
We compare the performance of DC3 and other algorithms according to the objective value and max/mean values of equality/inequality constraint violations, each averaged across test instances.
We also compare the total time required to run on all 833 test instances, where all deep learning methods and qpth are run with full parallelization, and where we use † to denote that the baseline optimizer is run sequentially.
(Std. deviations across 5 runs are shown in parentheses for all ﬁgures reported.)
Lower values are better for all metrics. We ﬁnd that methods other than DC3 and Optimizer violate feasibility (as shown in red). DC3 gives a feasible output with reasonable objective value about 40 × faster than qpth , and about 360 × faster than the osqp optimizer (though in the latter case, this speedup is in part because we have taken advantage of the fact that DC3 is readily parallelizable, whereas the same is not true for osqp ). • NN, ≤ test : The NN approach, with a gradient-based correction procedure 1 applied to the output at test time in an effort to mitigate violations of equality and inequality constraints.
Unlike in DC3, correction is not used during training, and completion is not used at all.
• Eq.
NN : A more sophisticated approach inspired by 2 that in Zamzam & Baker (2019), where (i) the neural network outputs a partial set of variables ˆ z , which is completed to the full set using the equality constraints, (ii) training is performed by supervised learning on optimal pairs ( x ( i ) , z ( i ) ) with loss function
||
ˆ z − z
( i ) || 22 , not using the objective value at all.
• Eq.
NN, ≤ test : The approach in Eq.
NN, augmented with gradient-based correction at test time to mitigate violations of equality and inequality constraints.
In addition, we consider weaker versions of DC3 in which components of the algorithm are ablated:
• DC3, (cid:54) = .
The DC3 algorithm with completion ablated.
All variables are output by the network directly and correction is performed by taking gradient steps for both equality and inequality constraints.
• DC3, (cid:54)≤ train .
The DC3 algorithm with correction ablated at train time.
Correction is still performed at test time.
• DC3, (cid:54)≤ train/test .
The DC3 algorithm with correction ablated at both train and test time.
• DC3, no soft loss .
The DC3 algorithm with training performed to minimize the objective value, without auxiliary terms capturing equality and inequality violation.
As our overall framework is agnostic to the choice of neural network architecture, to facilitate comparison, we use a ﬁxed neural network architecture across all experiments: fully connected with two it can work well in practice), in principle, one could consider employing a combination of PV/PQ switching and gradient-based corrections in the context of ACOPF.
hidden layers of size 200, including ReLU activation, batch normalization, and dropout (with rate 0.2) at each hidden layer (Ioffe & Szegedy, 2015; Srivastava et al., 2014).
For our correction procedure, we use t train = 100 for the QP tasks and t train = 5 for ACOPF, and t test = 100 in both cases (see Appendix B).
All neural networks are trained using PyTorch (Paszke et al., 2019).
To generate timing results, all neural nets and the qpth optimizer were run with full parallelization on a GeForce GTX 1080 Ti GPU, and the osqp and PYPOWER optimizers were run sequentially on an Intel Xeon 2.60GHz CPU.
For these and many additional reasons (e.g., our DC3 implementation is not tightly optimized), we emphasize that all timing comparisons are approximate.
4. Q UADRATIC PROGRAMS
As a ﬁrst test of the DC3 method, we consider solving convex quadratic programs with a quadratic objective function and linear constraints.
Formally, the problem we consider is given by:
[Equation]
for constants Q ∈ R n × n (cid:23)
[Equation]
, p [Equation] R n , [Equation]
R [Equation] , G [Equation]
∈
[Equation]
and variable x ∈ R n eq which varies between problem instances.
Our algorithm must learn to approximate the optimal y given x as input.
In our experiments, we take Q to be a diagonal matrix with all diagonal entries drawn i.i.d.
from the uniform distribution on [0 , 1] , ensuring that Q is positive semi-deﬁnite.
We take matrices A, G with entries drawn i.i.d.
from the unit normal distribution.
We assume that in each problem instance, all entries of x are in the interval [ − 1 , 1] .
In order to ensure that the problem is feasible, we take h = (cid:80) j | ( GA + ) ij | , where A + is the Moore-Penrose pseudoinverse of A ; namely, for this choice of h , the point y =
A + x is feasible (but not, in general, optimal), because:
[Equation]
During training, we use examples x with entries drawn i.i.d.
from the uniform distribution on [ − 1 , 1] .
While we examine this quadratic programming setting for the purposes of illustration, we note that the general DC3 method may indeed not be the most efﬁcient deep learning-based method for constraint enforcement in this setting.
Speciﬁcally, as previously-discussed, more specialized techniques are available for linearly-constrained settings such as this one.
As such, our goal in examining this set of quadratic programming problems is to analyze the performance of DC3 in a well-understood setting, before moving on to the more challenging (non-convex) setting of ACOPF.
We assess our method for different problem classes characterized by the above QP, letting n = 100 and performing experiments with different numbers of inequality and equality constraints.
In particular, we evaluate settings with n ineq = 50 and where the number of equality constraints varies as n eq = 10 , 30 , 50 , 70 , 90 , and similar settings where we ﬁx n eq = 50 and vary the number of inequality constraints as n ineq = 10 , 30 , 50 , 70 , 90 .
We run each experiment 5 times over 10, examples x (with a train/test/validation ratio of 10:1:1).
Hyperparameters were tuned to maximize performance for each method individually (see Appendix B).
Optimality, feasibility, and timing results for the setting with n ineq = 50 , n eq = 50 are reported in Table 1, and results for the remaining experiments are reported in Table 2 and (in the Appendix) Table A.1.
In our experiments, we ﬁnd that DC3 preserves feasibility with respect to both equality and inequality constraints, while achieving reasonable objective values.
For every baseline deep learning algorithm, on the other hand, feasibility is violated signiﬁcantly for either equality or inequality constraints.
As expected, “DC3 (cid:54) = ” (completion ablated) results in violated equality constraints, while “DC3 (cid:54)≤ ” (correction ablated) violates inequality constraints.
Ablating the soft loss also results in violated inequality constraints, leading to an objective value signiﬁcantly lower than would be possible were the constraints satisﬁed.
In terms of timing, DC3 runs about 40 × faster than qpth , and about 350 × faster than the OSQP optimizer.
We note that this latter comparison is not apples-to-apples, as DC3 is run with full parallelization on a GPU, while OSQP is run sequentially on a CPU.
However, we report results in this manner given that in practice, standard solvers such as OSQP are not readily fully parallelizable,
[Table]
whereas deep learning-based (approximate) optimizers can easily exploit massively parallel batch processing within deep learning frameworks.
4. AC OPTIMAL POWER FLOW
We now show how DC3 can be applied to the problem of AC optimal power ﬂow (ACOPF).
ACOPF is a fundamental problem for the operation of the electrical grid, and is used to determine how much power must be produced by each generator on the grid in order to meet demand.
As the amount of renewable energy on the power grid grows, this problem must be solved more and more frequently to account for the variability of these renewable sources, and at larger scale to account for an increasing number of distributed devices (Rolnick et al., 2019).
However, ACOPF is a non-convex optimization problem and classical optimizers scale poorly on it.
While many specialized approaches to this problem have started to emerge, including approaches from machine learning (see, e.g., Zamzam & Baker (2019) for a discussion), we here assess the ability of our more general framework to address this problem.
Formally, a power network may be considered as a graph on b nodes, representing different locations ( buses ) within the electrical grid, and with edges weighted by complex numbers w ij ∈ C ( admittances ) that represent how easily current can ﬂow between the corresponding locations in the grid.
Let W ∈ C n × x denote the graph Laplacian (or nodal admittance matrix ).
Then, the problem of
ACOPF can be deﬁned as follows:
Given input variables p d ∈ R b , q d ∈ R b (representing real power and reactive power demand at the various nodes of the graph), output the variables p g ∈ R b , q g ∈ R b [Table] (representing real power and reactive power generation ) and v ∈ C b (representing real and imaginary voltage ), according to the following optimization problem:
[Equation]
More details about how we apply DC3 to the problem of ACOPF are given in Appendix C.
We assess our method on a 57-node power system test case available via the MATPOWER package.
We conduct 5 runs over 1,200 input datapoints (with a train/test/validation ratio of 10:1:1).
As with the QP task, hyperparameters for ACOPF were tuned to maximize performance for each method individually (see Appendix B).
Optimality, feasibility, and timing results are reported in Table 3.
We ﬁnd that DC3 achieves comparable objective values to the optimizer, and preserves feasibility with respect to both equality and inequality constraints.
As with the QP task, for every baseline deep learning algorithm, feasibility is violated signiﬁcantly for either equality or inequality constraints.
Ablations of DC3 also suffer from constraint violations, though the effect is less pronounced than for the QP task, especially for ablation of the correction.
We also see that DC3 runs about 45 × faster than the optimizer (though again, this is in part due to its ability to readily exploit parallelism within deep learning frameworks).
C ONCLUSION
We have described a method, DC3, for fast approximate solutions to optimization problems with hard constraints.
Our approach includes a neural network that outputs a partial set of variables, a differentiable completion procedure that ﬁlls in remaining variables according to equality constraints, and a differentiable correction procedure that ﬁxes inequality violations.
We ﬁnd that DC yields solutions of signiﬁcantly better feasibility and objective value than other approximate solvers on convex and non-convex optimization tasks.
We note that, while DC3 provides a general framework for tackling constrained optimization, depending on the setting, the expensiveness of both the completion and correction procedures may vary (e.g., implicit solutions may be more time-consuming, or gradient descent may converge more or less easily).
We believe that, while our method as stated is broadly applicable, it will be possible in future work to design further improvements tailored to speciﬁc problem instances, for example by designing problem-dependent correction procedures.
A A DDITIONAL QP TASK RESULTS
[Table]
B D ETAILS ON HYPERPARAMETER TUNING
The following parameters were kept ﬁxed for all neural network-based methods across all experiments, based on a small amount of informal experimentation to ensure training was stable and properly converged:
• Epochs:• Batch size: 3• Hidden layer size: 200 (for both hidden layers) • Correction procedure stopping tolerance: 10 −• Correction procedure momentum: 0.
For all remaining parameters, we performed hyperparameter tuning via a coordinate search over relevant parameters.
Central values for this coordinate search were determined via a small amount of informal experimentation to ensure training was stable on that central set of parameters.
Final parameters were chosen so as to prioritize feasibility (as determined via the mean and max violations of equality and inequality constraints), followed by objective value.
B. Q UADRATIC PROGRAMS
We list the ranges over which different hyperparameters were tuned for each method, with central values for the coordinate search in italics , and the ﬁnal parameter values in bold .
In order to minimize the amount of tuning, we employ the hyperparameters obtained for DC3 to “DC3, (cid:54)≤ train” and “DC3, no soft loss” as well (rather than tuning the latter two methods separately).
For this set of experiments, we set the learning rate of the gradient-based correction procedure ρ x to 10 − 7 for all methods, as most methods went unstable for higher correction learning rates.
[Equation]
DC3, no soft
[Equation]
DC3, (cid:54) =
NN
Eq.
NN
Lr 10 − 2 , 10 − 3 , 10 −10 − 2 , 10 − 3 , 10 −10 − 2 , 10 − 3 , 10 −10 − 2 , 10 − 3 , 10 −λ g + λ h 1, 10 , 1, 10 ,1, 10 ,– λ h
[Table]
[Table]
test 5, 10, 50, 100 ,5, 10, 50, 100 ,5, 10, 50, 100 ,5, 10, 50, 100 ,
[Table]
train 1, 2, 5 , 10,1, 2, 5 , 10,– –
[Table]
AC OPTIMAL POWER FLOW
We list the ranges over which different hyperparameters were tuned for each method, with central values for the coordinate search in italics , and the ﬁnal parameter values in bold .
As in the previous setting, in order to minimize the amount of tuning, we employ the hyperparameters obtained for
DC3 to “DC3, (cid:54)≤ train” and “DC3, no soft loss” as well (rather than tuning the latter two methods separately).
[Equation]
(cid:54)≤ train
DC3, no soft loss
DC3, (cid:54) =
NN
Eq.
NN
Lr
[Table] [Table]
[Table] [Table]
[Table] [Table]
[Table] [Table]
[Table] [Table]
[Table] [Table]
[Table]
λ g + λ h 1, 10 , 1, 10 ,1, 10 ,–
[Table]
g
[Table]
h 0.
[Table] [Table]
[Table] [Table] [Table]
[Table] [Table]
– t test
[Table] [Table]
[Table] [Table]
[Table] [Table]
[Table]
Lr, ρ x
[Table]
[Table]
[Table]
[Table] [Table] [Table]
[Table]
[Table] [Table]
[Table] [Table]
[Table]
C D ETAILS OF DC3 FOR ACOPF C. P ROBLEM SETTING
We consider the problem of ACOPF deﬁned in § 4.2.
Let B denote the overall set of buses (i.e., nodes in the power network).
In any instance of ACOPF there exists a set D ⊆ B of load (demand) buses at which p g and q g are identically zero, as well as a set R ⊆ B of reference (slack) buses at which p g and q g are potentially nonzero, and where the voltage angle ∠ v is known.
Let G =
B \ ( D ∪ R ) be the remaining generator buses at which p g and q g are potentially nonzero, but where the voltage angle ∠ v is not known.
Then, we may rewrite Equation (6) as follows, where v ≡ | v | e i ∠ v and W ≡ W r + W i i : minimize p g ,q g , | v | , ∠ v ∈ R |B| p
Tg Ap g + b T p g
[Equation]
subject to p min g
[Equation]
max
[Equation]
C
[Equation]
1h
[Equation]
where v r = | v | cos( ∠ v ) and v i = | v | sin( ∠ v ) (While we write the problem in this form to minimize notation, in practice, some of the constraints in the above problem – e.g., (C.1b), (C.1c), and (C.1f) – can be condensed.)
C. O VERALL APPROACH
As pointed out in Zamzam & Baker (2019), given p d , q d , ( p g ) G and | v | B\D , the remaining variables ( p g ) R , ( q g ) B\D , | v | D , and ( ∠ v ) B\R can be recovered via the power ﬂow equations (C.1g)–(C.1h).
As such, our implementation of DC3 may be outlined as follows.
• Input: x = (cid:2) p
Td q Td (cid:3) T .
(The constant ∠ v R is ﬁxed across problem instances.)
• Neural network:
Output α ∈ [0 , 1] |G| and β ∈ [0 , 1] |B|−|D| (applying a sigmoid to the ﬁnal layer of the network), and compute:
[Equation]
(In other words, output a partial set of variables, and enforce box constraints on this set of variables via sigmoids in the neural network.)
• Completion procedure:
Given z = (cid:104) ( p g ) T G | v | T B\D (cid:105) T , solve Equations (C.1g)–(C.1h) for the remaining quantities ( p g ) R , ( q g ) B\D , | v | D , and ( ∠ v ) B\R as described below.
Output all decision variables y
=
(cid:2) ( p g ) T G ( q g
[Equation]
T G
[Equation]
T
[Equation]
• Correction procedure: Correct y using the gradient-based feasibility correction procedure described in § 3.2.
• Backpropagate: Compute the loss and backpropagate as described below to update neural network parameters.
Repeat until convergence.
We now describe the forward and backward passes through the completion procedure, where we have introduced several “tricks” that signiﬁcantly reduce the computational cost, including some that are speciﬁc to the ACOPF setting.
For ease of notation throughout, we will let J ∈ R 1+2 |B| denote the Jacobian of the equality constraints (C.1e)–(C.1h) with respect to the complete vector y of decision variables.
This matrix, which we pre-compute, will be useful throughout our computations.
C. S OLVING THE COMPLETION
The neural network outputs ( p g ) G and | v | B\D are the inputs to the completion procedure.
Theoretically, we could use Newton’s method to solve for all additional variables from the equality constraints.
However, in practice we ﬁnd that solving for all variables using Newton’s method is sometimes unstable.
Fortunately, we can divide the completion procedure into two substeps, where
Step 1 invokes Newton’s method to identify some of the variables, while Step 2 solves in closed form for the others.
This greatly improves the stability of the completion procedure.
Step 1.
Compute | v | D , ( ∠ v ) B\R via Newton’s method using real power ﬂow constraints (C.1g) at buses B \ R , and reactive power constraints (C.1h) at buses D (note that the number of equations matches the number of variables being identiﬁed).
We initialize Newton’s method by ﬁxing variables determined by the neural network and those already determined in Step 1 of the completion process, and initializing | v | D , ( ∠ v ) B\R at generic initial values (these are provided in the ACOPF task setup and are typically used to initialize state-of-the-art solvers).
Note that the remaining variables, those determined in Step 2 of the completion process, do not actually appear in the relevant equality constraints and therefore do not need to be set.
Let J Step 1 denote the submatrix of J corresponding to the equality constraints (C.1g) B\R and (C.1h) D and the voltage variables | v | D and ( ∠ v ) B\R that we are solving in this step.
At the t th step of Newton’s method, let h Step 1 ( t )
∈ R |B|−|R| + |D| denote the vector of values on the left-hand side of the relevant equality constraints (which we wish to equal identically zero), evaluated at the current setting of all problem variables.
Our Newton’s method updates are then
[Equation]
Step 2.
Compute the remaining variables ( p g ) R and ( q g ) B\D via the remaining equality constraints – that is, the real power ﬂow equations (C.1g) at buses R and the reactive power
ﬂow questions (C.1h) at buses in B \ D .
Steps 1 and 2 together allow us to complete all the decision variables.
C.
B ACKPROPAGATING
THROUGH THE COMPLETION
Let z denote the input to the completion procedure and let z 1 and z 2 denote the variables respectively derived during Steps 1 and 2 of completion.
That is:
[Equation]
Then, we wish to backpropagate gradients of an arbitrary loss function (cid:96) ( x, z, z 1 , z 2 ) , both in order to train our neural network and to perform our gradient-based correction procedure.
That is, we must compute the total derivative d (cid:96)/ d z given the partial derivatives ∂(cid:96)/∂z, ∂(cid:96)/∂z 1 , and ∂(cid:96)/∂z 2 .
Applying the chain rule through the two steps of the completion procedure
[Equation]
we have:
[Equation]
We now consider each of these terms in this equality, except for ∂(cid:96)/∂z, ∂(cid:96)/∂z 1 , ∂(cid:96)/∂z 2 , which we may assume have already been computed.
Step 2.
Let J Step 2 denote the submatrix of J corresponding to the partial derivatives of the equality constraints used in Step 2 with respect to the voltage variables | v | T , ( ∠ v ) T .
Then, we have:
[Equation]
As ∂ ( q g ) B\D ∂ ( p g ) G = 0 , this gives us both the terms ∂z 2 /∂z 1 , ∂z 2 /∂z in (C.3).
Step 1.
Consider the total differential through the equality constraints (C.1g) B\R and (C.1h) D , where all terms besides W r
and W i are viewed as parameters through which to differentiate.
We rearrange this total differential to put differentials of input quantities to Step 1 on one side and differentials of outputs from Step 1 on the other side:
[Equation]
where J Step 1 is as in the forward pass of Step 1, and J Step 1b denotes the submatrix of J corresponding to the equality constraints (C.1g) B\R and (C.1h) D and the voltage variables ( | v | ) B\D , ( ∠ v ) R .
While we could compute
[Equation]
explicitly, we can improve efﬁciency by not computing and storing a large intermediate Jacobian explicitly.
Instead, we can directly compute what we need, which is the product of this Jacobian with matrices of smaller dimensions.
Deﬁne
[Equation]
using our computation (C.4) above to evaluate ∂z 2 /∂z 1 .
Note furthermore that J − 1 Step 1 was already computed in the forward pass, meaning that we do not need to perform an additional matrix inversion.
Now, we can use (C.5) to derive:
[Equation]
which gives us
[Equation]
Putting it all together.
Combining our logic described above for Steps 2 and 1, we can recover all terms in (C.3) and therefore identify d (cid:96)/ d z .