Automatic Generation of Explicit Quadratic Programming Solvers

Maximilian Schaller, Daniel Arnström, Alberto Bemporad, Stephen BoydarXiv 2025 · DOI

TL;DR

This paper introduces a method to automatically generate extremely fast, custom C code for explicitly solving parametrized Quadratic Programs (QPs). By integrating the PDAQP explicit solver into the CVXPYgen framework, the authors allow users to define optimization problems in high-level Python and compile them into "lookup table" style solvers. This approach yields online solve times in the sub-microsecond range (up to three orders of magnitude faster than iterative solvers) and is highly reliable for real-time embedded systems.

What Problem Does This Paper Address?

Convex optimization is heavily used in fields like control systems, signal processing, and finance. Often, practitioners need to solve the exact same structure of an optimization problem repeatedly, with only the data (parameters) changing—this is known as a parametrized QP.

Standard iterative solvers parse the problem and compute the solution from scratch every single time. For embedded applications with hard real-time constraints (like landing a rocket or managing a battery), iterative solvers can be too slow, and their execution time can vary unpredictably.

"Explicit" solvers solve this by pre-computing all possible solutions offline. However, manually translating a high-level optimization problem into the strict mathematical format required by an explicit solver is tedious and error-prone. This paper bridges that gap, providing a tool that takes a user-friendly CVXPY model and automatically generates a highly optimized, deployable explicit solver in C.

Methods

The core approach relies on Multiparametric Programming and Code Generation:

  1. Explicit Parametric QPs: The mathematical solution to a parametrized QP is a "piecewise affine function." This means the parameter space is divided into distinct polyhedral regions (based on which constraints are active). Within each region, the optimal solution is just a simple linear function of the parameters.
  2. Offline vs. Online:
    • Offline: The solver computes all these regions and their corresponding linear functions in advance.
  3. Online: When a new parameter arrives, the solver simply searches a pre-computed binary tree to find which region the parameter falls into, and evaluates the corresponding linear function.
  4. CVXPYgen Integration: The authors extended CVXPYgen (a code generator for CVXPY). It takes a problem written in Disciplined Parametrized Programming (DPP), caches the canonicalization (the translation from user variables to standard math forms), and generates C code that interfaces with PDAQP, a high-performance explicit QP solver.

Datasets

The authors do not use traditional static machine learning datasets. Instead, they evaluate their generated solvers on synthetically generated problem instances across four practical domains:

  • Monotone Regression: Randomly sampled parameters.
  • Power Management: Simulated residential building with solar/battery, using randomly sampled loads, solar availability, and grid prices.
  • Model Predictive Control (MPC): A linear dynamical system with random initial states.
  • Portfolio Optimization: Uses real-world stock data (top 7 market cap stocks from 2017-2018 to estimate covariance, and 2019 data for returns) to generate instances.

Key Insights and Ideas

  • Division-Free Online Solving: Because the online phase only involves finding a region and evaluating an affine function (matrix multiplication and addition), it requires zero division operations. This completely eliminates the risk of divide-by-zero exceptions, making the code provably safe for critical embedded systems.
  • Deterministic Execution Time: With an explicit solver, you can calculate the exact maximum number of floating-point operations (FLOPS) required for any input. There is no "waiting for convergence" like in iterative solvers.
  • Lower Precision Potential: Because there is no division or iterative error accumulation, the explicit solver's coefficients can potentially be stored and computed in lower precision formats (like 16-bit floating-point), saving memory on cheap microcontrollers.
  • Parser-Solvers are Inefficient for Repeated Tasks: Repeatedly parsing a static problem structure in Python is a massive waste of compute. Compiling the canonicalization directly into C saves significant overhead.

Key Results

The generated explicit solvers achieved staggering speedups compared to standard CVXPY and even generated iterative solvers (OSQP):

  • Monotone Regression: Explicit C solve time was 0.0004 ms (vs. 0.1257 ms for generated OSQP).
  • Power Management: Explicit C solve time was 0.0001 ms (100 nanoseconds).
  • Model Predictive Control: Explicit C solve time was 0.001 ms.
  • Portfolio Optimization: Explicit C solve time was 0.0005 ms.
  • Memory Footprint: The compiled binary sizes for these explicit solvers are tiny, ranging from 10 KB to 234 KB, making them perfect for edge devices.

Limitations and Future Work

  • Exponential Scaling: The fatal flaw of explicit solvers is that the number of polyhedral regions can grow exponentially with the number of constraints ($2^m$ in the worst case).
  • Strict Size Limits: Because of this exponential growth, the underlying PDAQP solver hard-limits the number of inequality constraints to $m \le 1024$ (so regions can be efficiently represented as bit strings).
  • Only for Small Problems: If the problem size is too large, the offline generation phase will run out of memory or take too long, and the tool will terminate with a warning. This tool is strictly for small-to-moderate sized problems where extreme online speed is required.
  • Future Work: While not explicitly detailed as a separate section, the authors hint at the potential for deploying these generated solvers on low-cost electronic boards using reduced precision arithmetic, leveraging the division-free nature of the generated code.

Summary updated

BibTeX
@misc{schaller2025automatic,
  author = {Maximilian Schaller and Daniel Arnström and Alberto Bemporad and Stephen Boyd},
  title = {{Automatic Generation of Explicit Quadratic Programming Solvers}},
  year = {2025},
  eprint = {2506.11513},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/2506.11513},
  howpublished = {arXiv},
}
Figure