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 52.909901
#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 2.843947

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

Session Info

sessionInfo()
## R version 4.2.1 (2022-06-23)
## Platform: x86_64-apple-darwin21.6.0 (64-bit)
## Running under: macOS Ventura 13.0
## 
## Matrix products: default
## BLAS:   /usr/local/Cellar/openblas/0.3.21/lib/libopenblasp-r0.3.21.dylib
## LAPACK: /usr/local/Cellar/r/4.2.1_4/lib/R/lib/libRlapack.dylib
## 
## locale:
## [1] en_US.UTF-8/en_US.UTF-8/en_US.UTF-8/C/en_US.UTF-8/en_US.UTF-8
## 
## attached base packages:
## [1] stats     graphics  grDevices datasets  utils     methods   base     
## 
## other attached packages:
## [1] Matrix_1.5-1 CVXR_1.0-11 
## 
## loaded via a namespace (and not attached):
##  [1] gmp_0.6-6        Rcpp_1.0.9       bslib_0.4.0      compiler_4.2.1  
##  [5] jquerylib_0.1.4  tools_4.2.1      digest_0.6.30    bit_4.0.4       
##  [9] jsonlite_1.8.3   evaluate_0.17    lattice_0.20-45  rlang_1.0.6     
## [13] gurobi_9.5-2     cli_3.4.1        Rglpk_0.6-4      yaml_2.3.6      
## [17] blogdown_1.13    xfun_0.34        osqp_0.6.0.5     cccp_0.2-9      
## [21] fastmap_1.1.0    Rmpfr_0.8-9      stringr_1.4.1    knitr_1.40      
## [25] sass_0.4.2       bit64_4.0.5      grid_4.2.1       R6_2.5.1        
## [29] rmarkdown_2.17   bookdown_0.29    magrittr_2.0.3   rcbc_0.1.0.9001 
## [33] codetools_0.2-18 htmltools_0.5.3  assertthat_0.2.1 Rcplex_0.3-5    
## [37] stringi_1.7.8    Rmosek_10.0.25   cachem_1.0.6     slam_0.1-50

Source

R Markdown

References