Abstract
The osqp package provides R bindings to the OSQP solver, a numerical optimization package designed for solving convex quadratic programs. Written in C and based on the Alternating Direction Method of Multipliers (ADMM), OSQP is optimized for speed and robustness in large-scale applications. For technical details, see arXiv:1711.08013.
Introduction
Quadratic Programming (QP) is a cornerstone of modern computational science, essential for tasks ranging from financial portfolio optimization to robotic trajectory planning. However, researchers often face a trade-off between "heavyweight" interior-point solvers, which are accurate but computationally expensive, and simpler methods that may struggle with complex constraints. The osqp package addresses this by providing a high-performance R interface to the Operator Splitting Quadratic Program (OSQP) solver, specifically targeting large-scale problems with sparse matrices and frequent parameter updates.
Methodology
The package acts as a bridge, via Rcpp, to the underlying OSQP C library. Its core algorithm utilizes the Alternating Direction Method of Multipliers (ADMM), a first-order splitting method. Unlike second-order methods that require solving expensive linear systems involving the Hessian at every step, ADMM uses simpler updates that are computationally lighter per iteration.
Sparse Matrix and Vector Support
osqp integrates deeply with R’s Matrix package. By supporting sparse matrices (specifically of class dgCMatrix), the solver ensures that only non-zero elements are processed, which is critical for high-dimensional data efficiency.
Stateful Optimization and Warm Starting
Utilizing the S7 functional object-oriented system, osqp allows for stateful optimization. When a model is initialized, it returns an object that maintains the solver's state. This enables "warm starting": users can update specific vectors, such as the linear objective $q$ or constraint bounds $l$ and $u$, and re-solve from the previous solution. This feature is particularly valuable in fields like Model Predictive Control (MPC), where a sequence of nearly identical problems must be solved rapidly.
Key Insights and Fine-Grained Control
The package provides extensive control over the optimization process through the osqpSettings function. This allows users to adjust hyperparameters to suit the specific geometry of their optimization problem.
Key settings include the ADMM step size (rho), the relaxation parameter (alpha), and various convergence tolerances (eps_abs, eps_rel). Additionally, the solver is designed to provide certificates of primal and dual infeasibility, helping users diagnose why a specific problem may be unsolvable.
Performance and Results
osqp offers two main entry points: solve_osqp() for simple, one-off calculations, and the osqp() constructor for complex, stateful workflows. The C-based backend ensures near-native performance while remaining accessible within the R environment. The solver returns a detailed output list containing the primal solution ($x$), the dual solution ($y$), and performance metadata such as iteration counts and setup/solve times.
Limitations
As a first-order method, OSQP is exceptionally fast at reaching a "good" solution but may require more iterations than an interior-point solver to reach extremely high levels of numerical precision (e.g., $10^{-12}$). Users should consider this trade-off based on the precision requirements of their specific application.
Summary updated