APQP and Canonicalization¶
DiffAPQP supports continuous affine-parametric quadratic and linear programs written as ordinary CVXPY models. The user works with named, domain-specific variables and parameters; DiffAPQP constructs the canonical matrix form internally.
Original domain model¶
The original optimization problem may contain several scalar, vector, or matrix decisions, denoted collectively by \(z\), and several parameter blocks, denoted collectively by \(\hat y\):
This is the model users express in CVXPY. The symbols and shapes can retain their engineering meaning, such as generator schedules, bus injections, network flows, demand forecasts, or renewable forecasts.
Canonical APQP¶
A QP is affine-parametric when its linear objective coefficient, objective offset, and constraint right-hand sides depend affinely on the parameters. The canonical APQP used by DiffAPQP is
where \(P\succeq0\). The affine parameter-to-data maps are
The matrices \(P\), \(A\), and \(G\) are constant across parameter values. For each parameter block \(\hat y_i\):
- \(Q_i\) maps it into the linear objective coefficient;
- \(d_i\) maps it into the scalar objective offset;
- \(B_i\) maps it into the equality right-hand side;
- \(H_i\) maps it into the inequality right-hand side.
The canonical dimensions are
The equality and inequality duals are \(\tilde\nu\in\mathbb R^{n_{\mathrm{eq}}}\) and \(\tilde\lambda\in\mathbb R^{n_{\mathrm{in}}}\), respectively.
An affine-parametric LP is the special case \(P=0\).
Automatic canonicalization¶
DiffAPQP represents canonicalization by
During layer construction, DiffAPQP asks CVXPY to compile the original problem, validates the resulting QP structure, and extracts the constant data and the affine maps \(Q_i\), \(d_i\), \(B_i\), and \(H_i\). Matrix-shaped parameters and variables are flattened in CVXPY's column-major order.
No manual standardization required
The APQP equations describe DiffAPQP's internal representation. Users
should formulate the engineering model naturally with CVXPY and pass the
original cvxpy.Problem directly to SolMapLayer or ValueFuncLayer.
The standard-form solver produces \(\tilde z^\star\). DiffAPQP records how the canonical variable is assembled and retrieves each original named decision through a linear selection/permutation map:
This retrieval map is also used in the solution-map backward pass.
Power-system interpretation¶
Consider a simple economic-dispatch model with generator output \(p_g\) and predicted demand \(\hat p_d\):
Here \(p_g\) is part of \(z\) and \(\hat p_d\) is part of \(\hat y\). After substitution:
- \(P=0\) and \(q=c_g\);
- power balance gives \(A=\mathbf 1^T C_g\) and \(b(\hat p_d)=\mathbf 1^T C_d\hat p_d\);
- the upper line limit gives \(M C_g p_g\le\bar p_f+M C_d\hat p_d\);
- the lower line limit gives \(-M C_g p_g\le\bar p_f-M C_d\hat p_d\).
Thus demand enters the equality and inequality right-hand sides through \(B_i\) and \(H_i\). A predicted market price would instead commonly enter the linear objective through \(Q_i\).
Supported CVXPY structure¶
The current implementation requires:
- a minimization problem with at least one named parameter and named decision;
- a continuous, DCP-compliant QP or LP;
- DPP compliance when parameters are present;
- a constant positive-semidefinite \(P\);
- constant decision-coefficient matrices \(A\) and \(G\);
- affine parameter dependence through \(q\), \(c\), \(b\), or \(h\);
- canonical variables that preserve the names and flattened sizes of the original CVXPY variables.
Parameterized \(P\), \(A\), or \(G\), integer or Boolean decisions, and nonlinear
constraints are outside the current layer contract. See the exact validation
and shape rules in the
SolMapLayer and
ValueFuncLayer
references.
Batches share one APQP template¶
Each batch row supplies one value of \(\hat y\). The values of \(q(\hat y)\), \(c(\hat y)\), \(b(\hat y)\), and \(h(\hat y)\) may differ by sample, but all samples share \(P\), \(A\), \(G\), and the same affine maps. This fixed structure enables the repeated-solve accelerations described in the efficient forward pass.