REVIEW 2 major objections 5 minor 1 cited by
Code generation for solving and differentiating through convex optimization problems
T0 review · 2 major / 5 minor · reviewed 2026-08-16 · deepseek-v4-flash
Pith's one-line read C code now differentiates through convex optimization problems
desk verdict A genuinely useful software extension that combines codegen with argmin differentiation, but the missing gradient-correctness check keeps the central claim from being fully demonstrated. read the letter →
The pith
A machine-rendered reading of the paper's core claim, the machinery that carries it, and where it could break.
The reading
What carries the argument
The load-bearing object is the KKT system formed from the active constraint set at optimality. Differentiating it yields a linear system solved through a regularized quasidefinite matrix with iterative refinement, and low-rank row and column addition and deletion algorithms update the sparse LDL factorization when the active set changes between solves. This combination turns repeated differentiation into a sequence of cheap rank-one updates rather than full refactorizations, which is what makes the compiled differentiator fast.
What would settle it
Solve a quadratic program family at a parameter value where a constraint just becomes active, compute the generated gradient of the solution, and compare it with a central finite-difference Jacobian of the solution map; a mismatch of order one as the parameter crosses the kink would show that the generated derivative is not a true derivative, and a tuning loop built on it can be expected to fail.
Extended reading notes
Core claim
The paper's central discovery is that differentiating through a convex optimization problem can be compiled: for any disciplined parametrized programming problem that reduces to a quadratic program, the parameter-to-solution mapping can be differentiated by forming the KKT system at the active constraints, differentiating it, and propagating a gradient through the affine canonicalization and retrieval steps—all in generated C code. The authors extend CVXPYgen with a custom gradient computation, add CVXPY and CVXPYlayers interfaces, and report that the generated differentiator is about an order of magnitude faster than general-purpose CVXPYlayers in three applications: elastic net hyper-parameter tuning, approximate dynamic programming controller tuning, and financial portfolio optimization. They state that, to their knowledge, CVXPYgen is the first code generator for convex optimization that supports differentiation.
Load-bearing premise
The gradient code assumes that the parameter-to-solution map is locally unique and differentiable, and that the active constraint set used to build the KKT system is correctly identified and stable; when the solution is nonunique or at a kink, the returned gradient is not a true derivative.
Editorial extensions
If this is right
- Users of CVXPY can generate, compile, and deploy a solver-and-differentiator pair for a problem family, enabling gradient-based parameter tuning without a Python interpreter in the loop.
- The differentiator can be wired into autodifferentiation frameworks through the provided Python interface, so gradients of arbitrary scalar functions that contain optimization steps become available.
- Because the generated code is C, it can run in embedded and hard real-time settings, where parser-solver approaches are infeasible.
- The reported speedups imply that repeated gradient evaluations, which previously dominated tuning loops, stop being the bottleneck.
Reading between the lines
- The low-rank update strategy should extend to second-order information: repeated Hessian-vector products through the solution map could reuse the same factorization machinery.
- A testable extension is to relax the disciplined parametrized programming requirement to non-affine parameterizations by differentiating through the canonicalization itself, allowing problems like the original approximate dynamic programming formulation to be differentiated directly.
- The speed advantage is likely to grow when the problem family is solved many times with few active-set changes, suggesting the method is especially suited to model-predictive control and online portfolio rebalancing, where consecutive instances differ by small parameter changes.
Signed reviews
Editorial analysis
A structured set of objections, weighed in public.
Referee Report
Summary. The paper extends the open-source code generator CVXPYgen so that, for parameterized convex optimization problems reducible to quadratic programs, it emits custom C code for both solving the problem and differentiating the parameter-to-solution map. The differentiation method follows the standard KKT/argmin-differentiation approach of OptNet, with a regularized quasidefinite linear system solve, iterative refinement, and low-rank LDL updates for active-set changes. The authors provide three application studies: tuning elastic-net hyperparameters and winsorization levels, tuning weights of an approximate dynamic programming controller, and tuning a portfolio optimization trading engine. In each case they report convergence of the tuning procedure and compare computation times against CVXPYlayers.
Significance. If the generated derivative code is correct, the paper describes a practically useful software contribution: it is, to my knowledge, the first code generator for convex optimization that supports differentiation, and the reported gradient-only speedups of roughly one order of magnitude are meaningful for embedded and desktop tuning applications. The paper is also commendable for making the code and experiments publicly available, for clearly presenting the DPP-to-QP reduction, and for grounding the low-rank factorization updates in established references. However, the central claim that the generated code differentiates 'correctly' is not directly verified anywhere in the manuscript, and this is the main obstacle to accepting the paper in its current form.
major comments (2)
- [§4 and §2.3] The numerical experiments report tuning convergence curves and timings, but they never validate the computed gradients. Since the implementation depends on approximate active-set identification from an OSQP solution, regularization with epsilon = 1e-6, iterative refinement, and low-rank LDL updates, any one of these steps could introduce a bias or an outright error in the returned Jacobian. Tuning curves can decrease even with biased gradients, so the reported speedups do not by themselves establish that the differentiation is correct. I ask the authors to add a direct validation section: compare the generated backward pass against finite differences of the forward solution on small random LPs and QPs, including cases with active-set changes and equality constraints; compare the CVXPYgen Jacobian with the CVXPYlayers/diffcp Jacobian on the same problem instances; and report the sensitivity of the derivative to epsilon and N_refine. This is load-bearing because the paper's central contribution is correct differentiation through optimization, not merely fast solution.
- [§4.2] There is a mismatch between the stated design variable and the variable actually being optimized in the ADP example. The text says the controller is designed by omega = Z with Omega = S^n_+, but the algorithm modifies the Cholesky factor L and later recovers Z = L L^T - P_lqr. No projection onto the set of L whose recovered Z is positive semidefinite is described, and the line-search/projection step of Algorithm 4 is stated in terms of omega. If the implementation tunes L instead of Z, then the experiment solves a different optimization problem from the one stated, and the reported result does not demonstrate tuning of Z in the stated design space. Please clarify the parameterization, state the actual design space used in the code, and explain how the projection in Algorithm 4 is applied to L (or adjust the text to make L the design variable).
minor comments (5)
- [Abstract and §4] The abstract states that the approach 'increases the computation speed by about an order of magnitude in most applications,' but the full-tuning speedups in Tables 1, 2, and 4 are approximately 2.4x, 5.9x, and 2.9x. Only the gradient-only timings are near an order of magnitude. Please qualify the speedup claim as applying to the gradient computation, with full-loop speedups being smaller due to Python overhead.
- [§4.1] In the elastic net example, the text reports 'lambda approx 0.68 and gamma approx 0.80' after stating lambda = 10^mu and gamma = 10^nu. It would be clearer to report mu and nu, or to state explicitly that these are the recovered values of lambda and gamma.
- [§4.3] The phrase 'survivorship bias' should be 'survivorship bias' (or 'survivorship bias' is already the standard term; the manuscript reads 'survivership bias'). This is a typographical issue only.
- [§4] The timing comparisons do not state the hardware, compiler, or software versions used. Since the main empirical claim is a speed comparison, please report these details so the numbers are reproducible and interpretable.
- [§2.3] The sentence 'Note that we use the sign of y to determine constraint activity' is terse. The active set should be defined by primal equality A_i x = l_i or u_i; the dual sign is relevant for whether a constraint is correctly classified as active with a nonzero multiplier. Please expand this sentence so the reader knows precisely which OSQP outputs are thresholded and how ties are broken.
Circularity Check
No significant circularity: the derivation is standard argmin differentiation applied to generated QP code, and all self-citations are tooling context.
full rationale
The paper's derivation chain is not circular. Section 2.3 takes the KKT system (2) for a QP, differentiates it with respect to parameters, and solves the resulting linear system (3); this is the standard implicit-function/argmin differentiation approach, and its output formulas for ΔP, Δq, ΔAC, and ΔbC are derived algebraically from the differentiated optimality conditions, not assumed from the reported timing or tuning results. The DPP canonicalization and reverse-mode symmetry in Section 2.2 are cited from the earlier CVXPYlayers work, but that cited result is peer-reviewed and is also implemented in the open-source CVXPY codebase, so the citation is independent evidence rather than a circular load-bearing step. The numerical experiments compare the generated C code against an external baseline (CVXPYlayers) and report timings and tuning trajectories; no fitted parameter is renamed as a prediction, and no performance number is used to define the derivative formulas. The explicit caveat in Section 1.1 that nondifferentiable or nonunique solution maps are handled by using a reasonable value for the nonexistent derivative is a correctness and robustness limitation, not a circularity, because the subsequent derivation still stands on the assumed differentiable case. Therefore the central claim is self-contained with respect to the derivation, and any self-citation is merely normal tooling context.
Assumptions & free parameters
free parameters (4)
- Regularization strength epsilon =
1e-6
- Iterative refinement iterations N_refine =
3
- Line search factors beta and eta =
beta=1.2, eta=1.5
- Stopping tolerances epsilon_rel and epsilon_abs =
1e-3, 5e-3, 3e-2 across examples
assumptions (5)
- domain assumption The solution map theta to x*(theta) is locally unique and differentiable near the parameters of interest.
- domain assumption The active constraint set used to form the KKT system (2) is correctly identified from the solver output and is the right set for differentiation.
- standard math The regularized quasidefinite matrix K_C^epsilon has an LDL factorization.
- standard math The Davis-Hager rank-1 update and downdate algorithms correctly maintain the LDL factorization under row and column additions and deletions.
- domain assumption DPP canonicalization provides affine maps between user parameters, canonical parameters, and canonical solutions.
Cite this review
Pith. "Pith review of Code generation for solving and differentiating through convex optimization problems." pith.science (2026). https://pith.science/paper/XZJNGXUN
@misc{pith2026250414099,
author = {Pith},
title = {Pith review of: Code generation for solving and differentiating through convex optimization problems},
year = {2026},
howpublished = {\url{https://pith.science/paper/XZJNGXUN}},
note = {Machine review of arXiv:2504.14099}
}
read the original abstract
We introduce custom code generation for parametrized convex optimization problems that supports evaluating the derivative of the solution with respect to the parameters, i.e., differentiating through the optimization problem. We extend the open source code generator CVXPYgen, which itself extends CVXPY, a Python-embedded domain-specific language with a natural syntax for specifying convex optimization problems, following their mathematical description. Our extension of CVXPYgen adds a custom C implementation to differentiate the solution of a convex optimization problem with respect to its parameters, together with a Python wrapper for prototyping and desktop (non-embedded) applications. We give three representative application examples: Tuning hyper-parameters in machine learning; choosing the parameters in an approximate dynamic programming (ADP) controller; and adjusting the parameters in an optimization based financial trading engine via back-testing, i.e., simulation on historical data. While differentiating through convex optimization problems is not new, CVXPYgen is the first tool that generates custom C code for the task, and increases the computation speed by about an order of magnitude in most applications, compared to CVXPYlayers, a general-purpose tool for differentiating through convex optimization problems.
Figures
Figures from the paper (4 more)
Forward citations
Cited by 1 Pith paper
-
Learning to Optimize by Differentiable Programming
A tutorial survey of differentiable-programming-based first-order optimization, with dual-based PyTorch case studies and no new results.
Reference graph
Works this paper leans on
-
[1]
A. Agrawal, B. Amos, S. Barratt, S. Boyd, S. Diamond, and Z. Kolter. Differentiable convex optimization layers. In Advances in Neural Information Processing Systems (NeurIPS) , 2019
work page 2019
-
[2]
A. Agrawal, S. Barratt, S. Boyd, E. Busseti, and W. Moursi. Differentiating through a cone program. arXiv preprint arXiv:1904.09043 , 2019
arXiv 1904
-
[3]
A. Agrawal, S. Barratt, S. Boyd, and B. Stellato. Learning convex optimization control policies. In Learning for Dynamics and Control , pages 361--373. PMLR, 2020
work page 2020
- [4]
-
[5]
B. Amos and Z. Kolter. Optnet: Differentiable optimization as a layer in neural networks. In International Conference on Machine Learning , pages 136--145. PMLR, 2017
work page 2017
-
[6]
B. Anderson and J. Moore. Optimal control: linear quadratic methods . Courier Corporation, 2007
work page 2007
- [7]
-
[8]
S. Boyd and C. Barratt. Linear controller design: limits of performance , volume 78. Citeseer, 1991
work page 1991
Show all 71 references
-
[9]
Barratt and S
S. Barratt and S. Boyd. Least squares auto-tuning. Engineering Optimization , 53(5):789--810, 2021
2021
-
[10]
S. Boyd, E. Busseti, S. Diamond, R. Kahn, K. Koh, P. Nystrup, and J. Speth. Multi-period trading via convex optimization. Foundations and Trends in Optimization , 3(1):1--76, 2017
2017
-
[11]
S. Boyd, L. El Ghaoui, E. Feron, and V. Balakrishnan. Linear matrix inequalities in system and control theory . SIAM, 1994
1994
-
[12]
Bertsekas
D. Bertsekas. Linear network optimization: algorithms and codes . MIT press, 1991
1991
-
[13]
Bertsekas
P. Bertsekas. Nonlinear programming. Journal of the Operational Research Society , 48(3):334--334, 1997
1997
-
[14]
Bradbury, R
J. Bradbury, R. Frostig, P. Hawkins, M. Johnson, C. Leary, D. Maclaurin, G. Necula, A. Paszke, J. Vander P las, S. Wanderman- M ilne, and Q. Zhang. JAX : composable transformations of P ython+ N um P y programs, 2018
2018
-
[15]
Bertsekas and R
D. Bertsekas and R. Gallager. Data networks . Athena Scientific, 1992
1992
-
[16]
Brown, W
S. Brown, W. Goetzmann, R. Ibbotson, and S. Ross. Survivorship bias in performance studies. The Review of Financial Studies , 5(4):553--580, 1992
1992
-
[17]
S. Boyd, K. Johansson, R. Kahn, P. Schiele, and T. Schmelzer. Markowitz portfolio construction at seventy. arXiv preprint arXiv:2401.05080 , 2024
2024 arXiv
-
[18]
Bishop and N
C. Bishop and N. Nasrabadi. Pattern recognition and machine learning . Springer, 2006
2006
-
[19]
Bertsimas and A
D. Bertsimas and A. Thiele. A robust optimization approach to supply chain management. In Integer Programming and Combinatorial Optimization: 10th International IPCO Conference, New York, NY, USA, June 7-11, 2004. Proceedings 10 , pages 86--100. Springer, 2004
2004
-
[20]
Boyd and L
S. Boyd and L. Vandenberghe. Convex Optimization . Cambridge University Press, 2004
2004
-
[21]
Carson and N
E. Carson and N. Higham. Accelerating the solution of linear systems by iterative refinement in three precisions. SIAM Journal on Scientific Computing , 40(2):A817--A847, 2018
2018
-
[22]
Calamai and J
P. Calamai and J. Mor \'e . Projected gradient methods for linearly constrained problems. Mathematical programming , 39(1):93--116, 1987
1987
-
[23]
C. Cortes. Support-vector networks. Machine Learning , 20(3):273--297, 1995
1995
-
[24]
D. Cox. The regression analysis of binary sequences. Journal of the Royal Statistical Society Series B: Statistical Methodology , 20(2):215--232, 1958
1958
-
[25]
Diamond and S
S. Diamond and S. Boyd. CVXPY : A P ython-embedded modeling language for convex optimization. Journal of Machine Learning Research , 17(83):1--5, 2016
2016
-
[26]
Davis and W
T. Davis and W. Hager. Modifying a sparse C holesky factorization. SIAM Journal on Matrix Analysis and Applications , 20(3):606--627, 1999
1999
-
[27]
Davis and W
T. Davis and W. Hager. Row modifications of a sparse C holesky factorization. SIAM Journal on Matrix Analysis and Applications , 26(3):621--639, 2005
2005
-
[28]
Dunning, J
I. Dunning, J. Huchette, and M. Lubin. JuMP : a modeling language for mathematical optimization. SIAM Review , 59(2):295--320, 2017
2017
-
[29]
predict, then optimize
A. Elmachtoub and P. Grigas. Smart “predict, then optimize”. Management Science , 68(1):9--26, 2022
2022
-
[30]
Elton, M
E. Elton, M. Gruber, S. Brown, and W. Goetzmann. Modern portfolio theory and investment analysis . John Wiley & Sons, 2009
2009
-
[31]
A. Fu, B. Narasimhan, and S. Boyd. CVXR : an R package for disciplined convex optimization. Journal of Statistical Software , 94(14):1--34, 2020
2020
-
[32]
Grant and S
M. Grant and S. Boyd. CVX : Matlab software for disciplined convex programming, version 2.1, 2014
2014
-
[33]
Grinold and R
R. Grinold and R. Kahn. Active portfolio management . McGraw Hill New York, 2000
2000
-
[34]
Garcia, D
C. Garcia, D. Prett, and M. Morari. Model predictive control: Theory and practice -- a survey. Automatica , 25(3):335--348, 1989
1989
-
[35]
Halabian
H. Halabian. Distributed resource allocation optimization in 5g virtualized networks. IEEE Journal on Selected Areas in Communications , 37(3):627--642, 2019
2019
-
[36]
N. Higham. Iterative refinement for linear systems and lapack. IMA Journal of Numerical Analysis , 17(4):495--509, 1997
1997
-
[37]
Hoerl and R
A. Hoerl and R. Kennard. Ridge regression: Biased estimation for nonorthogonal problems. Technometrics , 12(1):55--67, 1970
1970
-
[38]
Holzmann
G. Holzmann. The power of 10: Rules for developing safety-critical code. Computer , 39(6):95--99, 2006
2006
-
[39]
Hastie, R
T. Hastie, R. Tibshirani, and J. Friedman. The elements of statistical learning: data mining, inference, and prediction , volume 2. Springer, 2009
2009
-
[40]
Keshavarz and S
A. Keshavarz and S. Boyd. Quadratic approximate dynamic programming for input-affine systems. International Journal of Robust and Nonlinear Control , 24(3):432--449, 2014
2014
-
[41]
Kouvaritakis and M
B. Kouvaritakis and M. Cannon. Model predictive control . Springer, 2016
2016
-
[42]
Kotary, V
J. Kotary, V. Di Vito, J. Cristopher, P. Van Hentenryck, and F. Fioretto. Learning joint models of prediction and optimization. arXiv preprint arXiv:2409.04898 , 2024
2024 arXiv
-
[43]
Kwakernaak and R
H. Kwakernaak and R. Sivan. Linear optimal control systems , volume 1. Wiley-interscience New York, 1972
1972
-
[44]
L\"ofberg
J. L\"ofberg. YALMIP : a toolbox for modeling and optimization in Matlab . In IEEE International Conference on Robotics and Automation (ICRA) , pages 284--289. IEEE, 2004
2004
-
[45]
Lefever, E
W. Lefever, E. Aghezzaf, and K. Hadj-Hamou. A convex optimization approach for solving the single-vehicle cyclic inventory routing problem. Computers & Operations Research , 72:97--106, 2016
2016
-
[46]
M. Lobo, M. Fazel, and S. Boyd. Portfolio optimization with linear and fixed transaction costs. Annals of Operations Research , 152:341--365, 2007
2007
-
[47]
L. Li, K. Jamieson, G. DeSalvo, A. Rostamizadeh, and A. Talwalkar. Hyperband: A novel bandit-based approach to hyperparameter optimization. Journal of Machine Learning Research , 18(185):1--52, 2018
2018
-
[48]
Ledoit and M
O. Ledoit and M. Wolf. Robust performance hypothesis testing with the sharpe ratio. Journal of Empirical Finance , 15(5):850--859, 2008
2008
-
[49]
Markowitz
H. Markowitz. Portfolio selection. Journal of Finance , 7(1):77--91, 1952
1952
-
[50]
Mattingley and S
J. Mattingley and S. Boyd. Real-time convex optimization in signal processing. IEEE Signal Processing Magazine , 27(3):50--61, 2010
2010
-
[51]
Maher, S
G. Maher, S. Boyd, M. Kochenderfer, C. Matache, D. Reuter, A. Ulitsky, S. Yukhymuk, and L. Kopman. A light-weight multi-objective asynchronous hyper-parameter optimizer. arXiv preprint arXiv:2202.07735 , 2022
2022 arXiv
-
[52]
K. Murphy. Machine learning: a probabilistic perspective . MIT press, 2012
2012
-
[53]
R. Narang. Inside the black box: a simple guide to quantitative and high-frequency trading , volume 846. John Wiley & Sons, 2013
2013
-
[54]
Nobel, E
P. Nobel, E. Cand \`e s, and S. Boyd. Tractable evaluation of stein’s unbiased risk estimate with convex regularizers. IEEE Transactions on Signal Processing , 2023
2023
-
[55]
Nobel, D
P. Nobel, D. LeJeune, and E. Cand \`e s. Randalo: Out-of-sample risk estimation in no time flat. arXiv preprint arXiv:2409.09781 , 2024
2024 arXiv
-
[56]
D. Palomar. Portfolio Optimization . Cambridge University Press, 2025
2025
-
[57]
Paszke, S
A. Paszke, S. Gross, S. Chintala, G. Chanan, E. Yang, Z. DeVito, Z. Lin, A. Desmaison, L. Antiga, and A. Lerer. Automatic differentiation in pytorch. NIPS-W , 2(3), 2017
2017
-
[58]
Pappas, A
T. Pappas, A. Laub, and N. Sandell. On the numerical solution of the discrete-time algebraic riccati equation. IEEE Transactions on Automatic Control , 25(4):631--641, 1980
1980
-
[59]
Rawlings, D
J. Rawlings, D. Mayne, M. Diehl, et al. Model predictive control: theory, computation, and design , volume 2. Nob Hill Publishing Madison, WI, 2017
2017
-
[60]
Schaller, G
M. Schaller, G. Banjac, S. Diamond, A. Agrawal, B. Stellato, and S. Boyd. Embedded code generation with CVXPY . IEEE Control Systems Letters , 6:2653--2658, 2022
2022
-
[61]
Stellato, G
B. Stellato, G. Banjac, P. Goulart, A. Bemporad, and S. Boyd. OSQP : an operator splitting solver for quadratic programs. Mathematical Programming Computation , 12(4):637--672, 2020
2020
-
[62]
J. Shao. Linear model selection by cross-validation. Journal of the American statistical Association , 88(422):486--494, 1993
1993
-
[63]
Tibshirani
R. Tibshirani. Regression shrinkage and selection via the lasso. Journal of the Royal Statistical Society Series B: Statistical Methodology , 58(1):267--288, 1996
1996
-
[64]
Tang and E
B. Tang and E. Khalil. Pyepo: A pytorch-based end-to-end predict-then-optimize library for linear and integer programming. Mathematical Programming Computation , pages 1--39, 2024
2024
-
[65]
Udell, K
M. Udell, K. Mohan, D. Zeng, J. Hong, S. Diamond, and S. Boyd. Convex optimization in J ulia. SC14 Workshop on High Performance Technical Computing in Dynamic Languages , 2014
2014
-
[66]
Vanderbei
R. Vanderbei. Symmetric quasidefinite matrices. SIAM Journal on Optimization , 5(1):100--113, 1995
1995
-
[67]
Wainwright
K. Wainwright. Fundamental methods of mathematical economics . McGraw-Hill, 2005
2005
-
[68]
Wang and S
Y. Wang and S. Boyd. Fast model predictive control using online optimization. IEEE Transactions on Control Systems Technology , 18(2):267--278, 2009
2009
-
[69]
Y. Wang, B. O'Donoghue, and S. Boyd. Approximate dynamic programming via iterated bellman inequalities. International Journal of Robust and Nonlinear Control , 25(10):1472--1496, 2015
2015
-
[70]
Zibulevsky and M
M. Zibulevsky and M. Elad. L1-L2 optimization in signal and image processing. IEEE Signal Processing Magazine , 27(3):76--88, 2010
2010
-
[71]
Zou and T
H. Zou and T. Hastie. Regularization and variable selection via the elastic net. Journal of the Royal Statistical Society Series B: Statistical Methodology , 67(2):301--320, 2005
2005
Reviewed August 16, 2026 · model on record in the stance chip above.
Discussion (0). Continue with ORCID to comment.