Theory
This page fixes the notation used across the ecosystem and states the mathematics behind the evaluators, the Lagrangian dual bound and the penalty method, with references to the papers they come from.
Parametric optimization
A parametric problem maps a parameter vector $p \in \mathbb{R}^{n_p}$ to an instance
\[\mathrm{OPT}(p) \;=\; \min_{x \in \mathbb{R}^{n}} \; f(x; p) \quad \text{s.t.} \quad g_i(x; p) \in \mathcal{S}_i, \quad i = 1, \dots, m, \tag{T1}\]
where each $\mathcal{S}_i$ is a MathOptInterface set (EqualTo, GreaterThan, Interval, Nonnegatives, SecondOrderCone, …). In JuMP, $p$ are variables in MOI.Parameter, $x$ are all other variables (decision_variables), and the constraints, including variable bounds, are constraint_refs (in this order). Maximization is handled by the sign $s = \texttt{objective\_sign}(problem) \in \{1, -1\}$: $s f$ is minimized.
A proxy $\phi_\theta$ maps a batch of parameters $P = [p_1, \dots, p_B]$ to raw outputs; a method's completion turns raw outputs into a prediction $(\hat X, \hat Y)$ of primal and/or dual solutions. Training minimizes a method-specific loss $\mathbb{E}_{p \sim \mathcal{D}} [\ell(\phi_\theta(p); p)]$ over a parameter distribution $\mathcal{D}$ (an AbstractParameterSampler).
evaluate measures. BoundedOutput (T6) and ProjectionRepair (T7) are the optional repair layers described below.Matrix form
For the classes LinearConic and ConvexQuadratic, with parameters entering affinely, MatrixEvaluator represents (T1) as
\[\min_x \; \tfrac12 x^\top Q x + c^\top x + x^\top H p + c_p^\top p + c_0 \quad \text{s.t.} \quad A x + B p + b \in \mathcal{K} = \mathcal{K}_1 \times \dots \times \mathcal{K}_m . \tag{T2}\]
Box-like sets are written as row bounds $l \le A x + B p + b \le u$ ($l_r = u_r$ for equalities, infinite entries allowed); other cones stay as blocks. Violations are
\[\nu_r(x; p) = \max(l_r - a_r^\top x - b_r^\top p - b_r^0, 0) + \max(a_r^\top x + b_r^\top p + b_r^0 - u_r, 0), \qquad \nu_k^{\mathrm{cone}}(x;p) = \operatorname{dist}(A_k x + B_k p + b_k, \mathcal{K}_k). \tag{T3}\]
MatrixEvaluator evaluates (T2) and (T3) for a whole batch with sparse products; on any $(X, P)$ its objective, constraint values and violations equal those of the per-instance JuMPEvaluator, which the tests compare on random points.
Lagrangian dual bound
Dual variables follow the MathOptInterface convention returned by JuMP.dual (MOI documentation, "Duality"): for $\min a_0^\top x + b_0$ s.t. $A_i x + b_i \in \mathcal{C}_i$ the dual is $\max -\sum_i b_i^\top y_i + b_0$ s.t. $a_0 - \sum_i A_i^\top y_i = 0$, $y_i \in \mathcal{C}_i^*$; for maximization the dual is $\min \sum_i b_i^\top y_i + b_0$ s.t. $a_0 + \sum_i A_i^\top y_i = 0$, with the same cones. Hence the signs of the duals depend only on the sets, not on the objective sense: $y_k \in \mathcal{K}_k^*$ for conic blocks, and for a box row $y_r \ge 0$ if only the lower side is finite, $y_r \le 0$ if only the upper side is finite, free otherwise. An Interval row (not a cone) is treated as the pair $f \ge l$ (multiplier $\max(y_r,0)$) and $f \le u$ (multiplier $\min(y_r,0)$), which is the sign convention solvers report for its ConstraintDual (strong duality holds with this convention on a QP with an Interval row, which the tests use as a reference). Writing $f_r = a_r^\top x + b_r^\top p + b^0_r$ for the function value of row $r$ (all rows, box and conic), the Lagrangian of the minimization form (objective $s f$) is
\[L(x, y; p) = s f(x; p) - \sum_{r} y_r\, f_r + \sum_{r \in \text{box}} \big(\max(y_r, 0)\, l_r + \min(y_r, 0)\, u_r\big). \tag{T4}\]
and the dual function is $d(y; p) = \inf_x L(x, y; p)$.
For a box row the last two terms equal $-\max(y_r,0)(f_r - l_r) - \min(y_r,0)(f_r - u_r)$; for a conic block they reduce to $-y_k^\top f_k$. For maximization, $-L$ is exactly the MOI Lagrangian $f + \sum_i y_i^\top (A_i x + b_i)$, which is why the minimization form uses the same $y$.
With $r(y; p) = s(c + H p) - A^\top y$:
\[d(y;p) = \begin{cases} s(c_p^\top p + c_0) - y^\top(Bp + b) + \text{box terms} & \text{if } Q = 0 \text{ and } r(y;p) = 0, \\[4pt] s(c_p^\top p + c_0) - y^\top(Bp + b) + \text{box terms} - \tfrac12 r^\top (sQ)^{+} r & \text{if } sQ \succeq 0 \text{ and } r \in \operatorname{range}(sQ), \\[4pt] -\infty & \text{otherwise.} \end{cases}\]
The first case (LP/conic) is the MOI dual objective above. For invertible $Q$ the second case is the MOI dual of a QP, $-\tfrac12 z^\top Q^{-1} z + b_0 - \sum_i y_i^\top b_i$ with $z = -r$. If $sQ$ is not positive semidefinite, $d(y; p) = -\infty$ for every $y$, so dual_bound returns $-\infty$ ($+\infty$ for maximization), even when the class was declared ConvexQuadratic by hand.
dual_bound(evaluator, Y, P) returns $s\, d(y;p)$ together with the dual infeasibility (largest of the stationarity residual, sign violations and dual-cone distances).
Weak duality. If $y$ is dual feasible (signs and dual cones as above, and $r(y;p) = 0$ or $r \in \operatorname{range}(sQ)$), then $d(y; p) \le s\,\mathrm{OPT}(p)$: the returned bound is $\le \mathrm{OPT}(p)$ for minimization and $\ge$ for maximization. No convexity is needed: for any feasible $x$, every subtracted term in (T4) is $\ge 0$ by the sign conventions, so $L(x,y;p) \le s f(x;p)$. Since dual feasibility does not depend on right-hand-side parameters, the optimal duals of one instance give a bound at every other instance with the same matrices; for a strictly convex QP every sign-feasible $y$ is dual feasible because $\operatorname{range}(sQ)$ is everything. The tests use both facts on random instances.
Tolerance. Numerically, $r$ is accepted when $\|r\|_\infty \le$ atol (or the range residual is). The bound then holds up to the residual: since $L$ is affine in $x$ along the residual, $d(y;p) \le s\,\mathrm{OPT}(p) + \|r\|_\infty \|x^\star\|_1$ for any optimal $x^\star$. Methods that need exact bounds (DLL) complete $y$ so that $r = 0$ holds by construction.
Dual completion (DLL). The DLL paper (Tanneau and Van Hentenryck, 2024) writes the primal (its eq. (6)) and the dual (eq. (7)) as
\[\begin{aligned} &\min \; c^\top x && \text{s.t.} \quad Ax \succeq_{\mathcal K} b, \quad Hx \succeq_{\mathcal C} h, && \text{(6)} \\ &\max \; b^\top y + h^\top z && \text{s.t.} \quad A^\top y + H^\top z = c, \quad y \in \mathcal K^*, \quad z \in \mathcal C^*; && \text{(7)} \end{aligned}\]
with $f = Ax - b$ this is exactly the MOI form above, so dual_bound of a completed DLL prediction is the bound $b^\top \hat y + h^\top \hat z$ of eq. (7a). Its Theorem 1 assumes that for every $\hat y \in \mathcal K^*$ the inner problem (8) is strictly feasible in $Hx \succ_{\mathcal C} h$ and bounded; then a completion $\hat z$ exists and $(\hat y, \hat z)$ is dual feasible (Theorem 2: the optimal completion gives the strongest bound for fixed $\hat y$). For finite variable bounds (its Example 1) the completion is
\[\hat z^l = |c - A^\top \hat y|^+, \qquad \hat z^u = |c - A^\top \hat y|^- \qquad (\hat z^u \le 0 \text{ in MOI signs}).\]
The tests apply this completion to random $\hat y$ and compare the bound with the solver optimum; $\hat y = y^\star$ recovers the optimum.
Strong duality. For a convex problem with a finite optimal value (LPs and convex QPs with affine constraints; for general cones under a constraint qualification such as Slater's condition), the bound at a primal-dual optimal pair equals the optimal value, up to solver tolerance. The tests compare the two on an LP (min and max), a convex QP (min, and concave max), a QP with a singular PSD Hessian and an SOCP.
Measuring a prediction
evaluate(pipe, P, prediction) returns an EvaluationReport with, per instance, the objective $f(\hat x; p)$, the largest violation over all constraints (rows and cones, (T3)), the largest violation over equality rows ($l_r = u_r$) and over the other constraints, and, for dual predictions, $s\,d(\hat y; p)$ and the dual infeasibility. When both a primal and a dual prediction are present it also reports the relative gap $|f(\hat x;p) - s\,d(\hat y;p)| / \max(1, |f(\hat x;p)|)$. Comparing the objective with solver optima gives the optimality gap of a primal proxy.
The penalty method
The reference method minimizes the soft loss of eq. (2) in Donti, Rolnick and Kolter (2021):
\[\ell_{\mathrm{soft}}(\hat x; p) = s f(\hat x; p) + \rho_{\mathrm{eq}} \sum_{r:\, l_r = u_r} \nu_r(\hat x; p)^2 + \rho_{\mathrm{ineq}} \Big(\sum_{r:\, l_r < u_r} \nu_r(\hat x; p)^2 + \sum_k \nu_k^{\mathrm{cone}}(\hat x;p)^2\Big). \tag{T5}\]
For a box row, $\nu_r$ is the ReLU of both one-sided constraints, so (T5) is eq. (2) of that paper with $\lambda_h = \rho_{\mathrm{eq}}$ and $\lambda_g = \rho_{\mathrm{ineq}}$; squared = false uses the 1-norm instead. Deviations: none in the formula. Variable bounds are inequalities $g$ of eq. (2) like any other, and distances to non-decomposable cones (e.g. second-order cones) play the role of $\mathrm{ReLU}(g)$ for conic constraints $g(x) \in \mathcal K$, which eq. (2) does not cover. The loss is averaged over the batch (the expectation in the training objective).
At a feasible point the penalty terms vanish and the loss equals the mean of $s f$ (also for maximization). The tests compare the loss with eq. (2) written out by hand for a small LP, and its Zygote gradient with central finite differences on an LP and on an SOCP (where the cone distance is active).
As the DC3 paper notes, soft losses do not enforce the constraints and can give infeasible outputs; use a method with a completion step when feasibility matters.
Repair layers
Repair layers are method wrappers: they change how a raw prediction is turned into a completed one, and therefore which constraints the completed prediction satisfies, independently of the method that trained the proxy.
Bounded output. BoundedOutput(inner; mode) maps the primal block $z$ of the raw output into the box $l \le x \le u$ declared on the variables, before both the loss and the completion of the inner method:
\[\beta(z)_j = \begin{cases} l_j + (u_j - l_j)\,\sigma(z_j) & l_j, u_j \text{ finite} \\ l_j + \operatorname{softplus}(z_j) & \text{only } l_j \text{ finite} \\ u_j - \operatorname{softplus}(-z_j) & \text{only } u_j \text{ finite} \\ z_j & \text{free} \end{cases} \qquad\text{or}\qquad \beta(z) = \min(\max(z, l), u) = \Pi_{[l,u]}(z). \tag{T6}\]
By construction $l \le \beta(z) \le u$ for every $z$. The smooth map is strictly increasing in each coordinate, so it has no zero-gradient region; the clamp is the Euclidean projection onto the box (the identity on the box, and nonexpansive) but its gradient vanishes outside the box. Changing $x$ can break other primal constraints of the inner method (e.g. equalities), while dual predictions, and hence their dual bounds, are untouched.
Projection repair. ProjectionRepair(inner, optimizer) replaces the primal prediction $\hat x$ by
\[\Pi_{\mathcal F(p)}(\hat x) = \arg\min_{x \in \mathcal F(p)} \|x - \hat x\|_2^2, \tag{T7}\]
solved per instance by a convex solver at inference; training is unchanged. For a convex class with $\mathcal F(p) \neq \emptyset$, $\mathcal F(p)$ is closed and convex, so (T7) has a unique solution, which is feasible up to the solver's tolerance. The projection onto a closed convex set is (firmly) nonexpansive (see, e.g., Bauschke and Combettes, Convex Analysis and Monotone Operator Theory in Hilbert Spaces, Ch. 4), so for every feasible $x$, in particular every optimal $x^\star$, $\|\Pi(\hat x) - x\| \le \|\hat x - x\|$: repair never moves a prediction away from the optimum. Feasible predictions are unchanged (to solver accuracy). The objective value need not improve. Projection layers are one of the remedies for infeasible proxies discussed in the survey of Kotary et al. (2021).
References
- H. H. Bauschke, P. L. Combettes. Convex Analysis and Monotone Operator Theory in Hilbert Spaces. Springer, 2nd ed., 2017.
- P. L. Donti, D. Rolnick, J. Z. Kolter. DC3: A learning method for optimization with hard constraints. ICLR 2021. arXiv:2104.12225.
- J. Kotary, F. Fioretto, P. Van Hentenryck, B. Wilder. End-to-End Constrained Optimization Learning: A Survey. IJCAI 2021. arXiv:2103.16378.
- M. Tanneau, P. Van Hentenryck. Dual Lagrangian Learning for Conic Optimization. NeurIPS 2024. arXiv:2402.03086.
- M. Klamkin, M. Tanneau, P. Van Hentenryck. Dual Interior-Point Optimization Learning. arXiv:2402.02596.
- S. Park, P. Van Hentenryck. Self-Supervised Primal-Dual Learning for Constrained Optimization. AAAI 2023. arXiv:2208.09046.
- F. Fioretto, P. Van Hentenryck, T. W. K. Mak, C. Tran, F. Baldo, M. Lombardi. Lagrangian Duality for Constrained Deep Learning. ECML-PKDD 2020. arXiv:2001.09394.