Warm Starts

A new feature in 1.0 is warm starts for one of our solvers in OSQP. Having warm starts allows the user to retain data of a particular problem and change parameters of the problem without repeating any of the calculations.

Lasso Example

We will demonstrate this in a simple lasso problem:

\[ \begin{array}{ll} \underset{x, \lambda}{\mbox{minimize}} & \frac{1}{2}||Ax - b||_2^2 + \lambda ||x||_1\\ \mbox{subject to} & \lambda > 0 \end{array} \]

#Problem data
set.seed(1)
m <- 2000
n <- 1000
A <- Matrix(rnorm(m*n), nrow = m, ncol = n)
b <- rnorm(m)

#Construct problem
gamma <- Parameter(pos = TRUE)
x <- Variable(n)
obj <- Minimize(.5 * sum_squares(A%*%x - b) + gamma * norm1(x))
constraint <- list(x >= 0)
prob <- Problem(obj, constraint)

#Solve first time
value(gamma) <- 1
result <- solve(prob, solver = "OSQP", warm_start = TRUE) #warm_start = T is not necessary for the first time
cat(sprintf("First solve time is %f\n", result$solve_time))
## First solve time is 30.889156
#Solve second time
value(gamma) <- 2
result <- solve(prob, solver = "OSQP", warm_start = TRUE)
cat(sprintf("Second solve time is %f\n", result$solve_time))
## Second solve time is 1.611814

As you can see, there is a very significant speed up with warm starts than without.

Session Info

sessionInfo()
## R version 4.4.2 (2024-10-31)
## Platform: x86_64-apple-darwin20
## Running under: macOS Sequoia 15.1
## 
## Matrix products: default
## BLAS:   /Library/Frameworks/R.framework/Versions/4.4-x86_64/Resources/lib/libRblas.0.dylib 
## LAPACK: /Library/Frameworks/R.framework/Versions/4.4-x86_64/Resources/lib/libRlapack.dylib;  LAPACK version 3.12.0
## 
## locale:
## [1] en_US.UTF-8/en_US.UTF-8/en_US.UTF-8/C/en_US.UTF-8/en_US.UTF-8
## 
## time zone: America/Los_Angeles
## tzcode source: internal
## 
## attached base packages:
## [1] stats     graphics  grDevices datasets  utils     methods   base     
## 
## other attached packages:
## [1] Matrix_1.7-1 CVXR_1.0-15 
## 
## loaded via a namespace (and not attached):
##  [1] slam_0.1-54       cli_3.6.3         knitr_1.48        rlang_1.1.4      
##  [5] xfun_0.49         clarabel_0.9.0.1  gurobi_11.0-0     Rglpk_0.6-5.1    
##  [9] cccp_0.3-1        assertthat_0.2.1  jsonlite_1.8.9    bit_4.5.0        
## [13] Rcplex_0.3-6      Rmosek_10.2.0     htmltools_0.5.8.1 rcbc_0.1.0.9001  
## [17] sass_0.4.9        gmp_0.7-5         rmarkdown_2.29    grid_4.4.2       
## [21] evaluate_1.0.1    jquerylib_0.1.4   fastmap_1.2.0     yaml_2.3.10      
## [25] lifecycle_1.0.4   bookdown_0.41     compiler_4.4.2    codetools_0.2-20 
## [29] Rcpp_1.0.13-1     osqp_0.6.3.3      blogdown_1.19     lattice_0.22-6   
## [33] digest_0.6.37     R6_2.5.1          bslib_0.8.0       tools_4.4.2      
## [37] bit64_4.5.2       Rmpfr_0.9-5       cachem_1.1.0

Source

R Markdown

References