# Dealing with Solver-Specific Parameters

## Overview

`CVXR`

1.0 has now updated how it handles its solver-specific
parameters and has diverged slightly from how `cvxpy`

handles it. It
now features five standard parameters that are the default parameters
for each solve function. Here are the five parameters

`verbose`

: A parameter that deals with the verbosity of the solver. It is a boolean variable for all solvers, but it can also take integer values for the`MOSEK`

solver, whose interface deals with an integer verbosity parameter with the default of 10. The default value of`verbose`

for`CVXR`

is set to`FALSE`

.`reltol`

: Deals with the relative tolerance of the solver.`abstol`

: Deals with the absolute tolerance of the solver.`feastol`

: Deals with feasible tolerance of the solver.`num_iter`

: A parameter that specifies the maximum number of iterations for the solver.

The users can also pass in solver-specific parameters to the `solve`

function based on the solver they specify. On the whole, the
additional parameters given by the user will override the five values
specified above.

For each solver, the tables below show how the five standard
parameters are mapped to the solver. Cells with `NA`

values indicate
no mapping and any specified value will result in a warning about
parameter being ignored.

## Solver-Specific Parameters

We will go over some examples for each solvers supported by `CVXR`

,
the available parameters for each solver, and where to find the
documentation for each solver.

### OSQP

The parameters available for `OSQP`

can be found in this
link.

Standard | OSQP | Value |
---|---|---|

verbose | verbose | FALSE |

reltol | eps_rel | 1e-05 |

abstol | eps_abs | 1e-05 |

feastol | eps_{prim/dual}_inf | 1e-04 |

num_iter | max_iter | 10000 |

The parameters can be entered individually in the arguments of the
solve function or can be passed through as a list. If the user enters
in a parameter that is not specified or accepted by `OSQP`

, then the
solver will ignore the parameter and proceed to solve the
problem. Here is an example.

```
x <- Variable(1)
obj <- Minimize(x)
prob <- Problem(obj, list(x >= 0))
# Inside Function
result <- solve(prob, solver = "OSQP", feastol = 1e-2, eps_prim_inf = 1e-5)
# Can also do it by passing in a list
more_params <- list(verbose = TRUE, feastol = 1e-2,
eps_prim_inf = 1e-5, eps_prim_inf = 1e-3)
result <- solve(prob, solver = "OSQP", verbose = FALSE, more_params)
```

In the second case that the `verbose`

in the `more_params`

list overrides
the value of `verbose`

listed earlier in the invocation.

### SCS

The parameters available for `SCS`

can be found in this
link under the
`scs_control`

function.

Standard | SCS | Value |
---|---|---|

verbose | verbose | FALSE |

reltol | NA | NA |

abstol | NA | NA |

feastol | NA | NA |

num_iter | max_iters | 2500 |

Much like `OSQP`

, the parameters can be
entered individually in the arguments of the solve function or can be
passed through as a list. If the user enters in a parameter that is
not specified or accepted by `SCS`

, then the solver will ignore the
parameter and proceed to solve the problem. Here is an example:

```
n<-3
p<-3
C <- matrix(rnorm(n^2), ncol = n)
A <- list(matrix(rnorm(n*n), nrow = n, ncol = n), matrix(rnorm(n*n), nrow = n, ncol = n), matrix(rnorm(n*n), nrow = n, ncol = n))
b <- matrix(rnorm(p), nrow = p)
X <- Variable(c(n, n), symmetric = TRUE)
constraints <- list(X >= 0)
for(i in 1:p){
constraints <- c(constraints, list(matrix_trace(A[[i]]%*%X) == b[i] ))
}
obj <- Minimize(matrix_trace(C %*% X))
prob <- Problem(obj, constraints)
result <- solve(prob, solver = "SCS", verbose = FALSE, feastol = 1e-2, cg_rate = 1.5, scale = 2)
```

```
## Warning in solve_via_data(object@solver, data, warm_start, verbose, feastol, :
## Ignoring inapplicable parameter feastol/reltol/abstol for SCS.
```

Notice how in this case a warning is thrown: the `SCS`

solver does not
support the feasible tolerance parameter, so the solver ignores it.

### ECOS/ECOS_BB

The parameters available for `ECOS`

can be found in this
link
under the `ecos.control`

function.

Standard | ECOS | ECOS Value | ECOS_BB | ECOS_BB Value |
---|---|---|---|---|

verbose | verbose | FALSE | verbose | FALSE |

reltol | reltol | 1e-08 | reltol | 1e-03 |

abstol | abstol | 1e-08 | abstol | 1e-06 |

feastol | feastol | 1e-08 | feastol | 1e-06 |

num_iter | maxit | 100 | mi_max_iters | 1000 |

Much like `OSQP`

, the parameters can be entered individually in the
arguments of the solve function or can be passed through as a list. If
the user enters in a parameter that is not specified or accepted by
`ECOS`

, then the solver will ignore the parameter and proceed to solve
the problem. Here is an example:

```
x <- Variable(1)
obj <- Minimize(x)
prob <- Problem(obj, list(x >= 0))
result <- solve(prob, solver = "ECOS", verbose = FALSE, feastol = 1e-2, reltol_inacc = 1e-5)
```

### CPLEX

The parameters available for `CPLEX`

can be found in this
link
under the details section for the function `Rcplex`

function on
page 3.

Standard | CPLEX | Value |
---|---|---|

verbose | trace | FALSE |

reltol | NA | NA |

abstol | NA | NA |

feastol | NA | NA |

num_iter | itlim | 10000 |

Much like `OSQP`

, the parameters can be entered individually
in the arguments of the solve function or can be passed through as a
list. If the user enters in a parameter that is not specified or
accepted by `CPLEX`

, then the solver will give the user a warning but
will proceed to solve the problem. Here is an example:

```
x <- Variable(1)
obj <- Minimize(x)
prob <- Problem(obj, list(x >= 0))
result <- solve(prob, solver = "CPLEX", verbose = FALSE, eps_abs_tol = 1e-2, epagap = 1e-5)
```

```
## Warning in Rcplex::Rcplex(cvec = q, Amat = Amat, bvec = bvec, Qmat = P, :
## Unknown CPLEX parameter eps_abs_tol. Ignoring it.
```

As you can see, `eps_abs_tol`

is not one of `CPLEX`

’s specified
parameters, so the solver threw a warning.

### MOSEK

Standard | MOSEK | Value |
---|---|---|

verbose | verbose | 0 |

reltol | NA | NA |

abstol | NA | NA |

feastol | NA | NA |

num_iter | num_iter | 10000 |

The parameters available for `MOSEK`

can be seen in this
link. As
you can see, the number of parameters is quite massive. They are also
split between three times of parameters in `Double`

, `Integer`

, and
`String`

parameters. To pass these into the solver, they must be put
in a list beforehand. Moreover, there are also general solver
parameters that do not belong in any of the three categories. These
parameters can be found in detail in the `Rmosek`

package
documentation, but here are the parameters

`verbose`

(Another important note here is while the default values of`TRUE`

and`FALSE`

work,`MOSEK`

uses integer values for verbose with the default being 10. The`TRUE`

value for verbose corresponds to 10 in the solver)`usesol`

`useparam`

`soldetail`

`getinfo`

`writebefore`

`writeafter`

These parameters are passed into the `solve`

function as normal. Here is an example:

```
x <- Variable(1)
obj <- Minimize(x)
prob <- Problem(obj, list(x >= 0))
iparam <- list()
iparam$AUTO_UPDATE_SOL_INFO <- "OFF"
iparam$BI_IGNORE_NUM_ERROR <- "OFF"
iparam$BI_MAX_ITERATIONS <- 100000
dparam <- list()
dparam$BASIS_REL_TOL_S <- 1.0e-12
dparam$BASIS_TOL_S <- 1.0e-6
result <- solve(prob, solver = "MOSEK", verbose = FALSE, soldetail = 3, dparam = dparam, iparam = iparam)
```

```
## Warning in solve_via_data(object@solver, data, warm_start, verbose, feastol, :
## Solver might not output correct answer depending on the input of the soldetail
## variable. Default is 3
```

A quick detail in this case is that the solver threw a warning about
the `soldetail`

parameter. Both the `soldetail`

and `getinfo`

parameter controls the amount of data the solve returns, and some of
them might be needed in order to invert the solution. Therefore,
proceed with caution when using these variables as they can cause the
solver to not obtain the answer.

### GUROBI

Standard | GUROBI | Value |
---|---|---|

verbose | OutputFlag | 0 |

reltol | NA | NA |

abstol | NA | NA |

feastol | {Feasibility/Optimality}Tol | 1e-06 |

num_iter | IterationLimit | 10000 |

The parameters available for `GUROBI`

can be seen in this
link. If
an unaccepted parameter is passed into the `solve`

function, then the
function will not run to completion. The solver will also not let you
know which parameter is at fault unless the parameter is
continuous. Here is an example.

```
x <- Variable(1)
obj <- Minimize(x)
prob <- Problem(obj, list(x >= 0))
result <- solve(prob, solver = "GUROBI", verbose = FALSE, BarIterLimit = 20, Quad = 1)
```

### GLPK

Standard | GLPK | Value |
---|---|---|

verbose | verbose | 0 |

reltol | NA | NA |

abstol | NA | NA |

feastol | NA | NA |

num_iter | NA | NA |

The parameters available for `GLPK`

can be seen in this
link under
the `Details`

section in page 4. There are only four parameters in
`verbose`

, `presolve`

, `tm_limit`

, `canonicalize_status`

. Here is an
example

```
x <- Variable(1)
obj <- Minimize(x)
prob <- Problem(obj, list(x >= 0))
result <- solve(prob, solver = "GLPK", verbose = FALSE, presolve = FALSE, tm_limit = 10, canonicalize_status = TRUE)
```

### CBC

Standard | CBC | Value |
---|---|---|

verbose | verbose | 0 |

reltol | NA | NA |

abstol | NA | NA |

feastol | NA | NA |

num_iter | NA | NA |

The parameters available for `CBC`

can be seen in this
link. Much
like most of the solvers outlined above, if the user passes in a
unspecified parameter into the solver, then the solver just ignores
the parameter and proceeds to solve the problem. Here is an example

```
x <- Variable(1)
obj <- Minimize(x)
prob <- Problem(obj, list(x >= 0))
result <- solve(prob, solver = "CBC", verbose = FALSE, sec = 5, maxn = 10)
```

## Session Info

`sessionInfo()`

```
## R version 4.0.2 (2020-06-22)
## Platform: x86_64-apple-darwin19.5.0 (64-bit)
## Running under: macOS Catalina 10.15.7
##
## Matrix products: default
## BLAS/LAPACK: /usr/local/Cellar/openblas/0.3.10_1/lib/libopenblasp-r0.3.10.dylib
##
## locale:
## [1] C
##
## attached base packages:
## [1] stats graphics grDevices datasets utils methods base
##
## other attached packages:
## [1] kableExtra_1.1.0 tibble_3.0.3 CVXR_1.0-9
##
## loaded via a namespace (and not attached):
## [1] xfun_0.15 slam_0.1-47 lattice_0.20-41 Rmosek_9.2.3
## [5] colorspace_1.4-1 vctrs_0.3.2 htmltools_0.5.0 viridisLite_0.3.0
## [9] yaml_2.2.1 gmp_0.6-0 rlang_0.4.7 pillar_1.4.6
## [13] glue_1.4.1 Rmpfr_0.8-1 Rcplex_0.3-3 bit64_0.9-7
## [17] scs_1.3-3 lifecycle_0.2.0 stringr_1.4.0 munsell_0.5.0
## [21] blogdown_0.19 rvest_0.3.5 gurobi_9.0.3.1 codetools_0.2-16
## [25] evaluate_0.14 knitr_1.28 cccp_0.2-4 highr_0.8
## [29] Rcpp_1.0.5 readr_1.3.1 scales_1.1.1 osqp_0.6.0.3
## [33] webshot_0.5.2 bit_1.1-15.2 hms_0.5.3 digest_0.6.25
## [37] stringi_1.4.6 bookdown_0.19 grid_4.0.2 Rglpk_0.6-4
## [41] ECOSolveR_0.5.3 tools_4.0.2 magrittr_1.5 crayon_1.3.4
## [45] pkgconfig_2.0.3 ellipsis_0.3.1 rcbc_0.1.0.9001 Matrix_1.2-18
## [49] xml2_1.3.2 assertthat_0.2.1 rmarkdown_2.3 httr_1.4.2
## [53] rstudioapi_0.11 R6_2.4.1 compiler_4.0.2
```