Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Need better handling of GUROBI solver error #104

Open
klin333 opened this issue Nov 19, 2021 · 0 comments
Open

Need better handling of GUROBI solver error #104

klin333 opened this issue Nov 19, 2021 · 0 comments

Comments

@klin333
Copy link

klin333 commented Nov 19, 2021

Describe the bug
Trycatch of solver error for GUROBI is not done well, resulting is cryptic error message shown to users of CVXR when the solver fails.

To Reproduce

library(CVXR)

x <- Variable(1)
d <- NA_real_

prob <- Problem(Minimize(x/d), list(x >= 0))
res <- solve(prob, solver = 'GUROBI')

Expected behavior
We expect a SOLVER_ERROR status. Note that running gurobi::gurobi directly on the model will show an error message of "Error: model$obj contains NA". However for CVXR, simple indication of SOLVER_ERROR is fine.

Output
Error in if (status == 2 || status == "OPTIMAL") OPTIMAL else if (status == :
missing value where TRUE/FALSE needed

Version
R version 3.6.3 (2020-02-29)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows 10 x64 (build 19043)

Matrix products: default

locale:
[1] LC_COLLATE=English_Australia.1252 LC_CTYPE=English_Australia.1252 LC_MONETARY=English_Australia.1252
[4] LC_NUMERIC=C LC_TIME=English_Australia.1252

attached base packages:
[1] graphics grDevices utils methods base

other attached packages:
[1] CVXR_1.0-9

loaded via a namespace (and not attached):
[1] Rcpp_1.0.4.6 gurobi_9.5-0 lattice_0.20-38 packrat_0.5.0 gmp_0.6-2 slam_0.1-48
[7] grid_3.6.3 R6_2.4.1 modules_0.8.0 Rmpfr_0.8-1 renv_0.13.2 Matrix_1.2-18
[13] tools_3.6.3 bit64_0.9-7 glue_1.4.1 bit_1.1-15.2 rsconnect_0.8.16 compiler_3.6.3
[19] stats_3.6.3 BiocManager_1.30.10

Additional context

The problem is likely due to qp_solvers.R, in the setMethod("solve_via_data", "GUROBI_QP").

results_dict <- list()
  tryCatch({
    results_dict$solution <- gurobi::gurobi(model, params)   # Solve.
  }, error = function(e) {   # Error in the solution.
    results_dict$status <- 'SOLVER_ERROR'
  })

When solver fails, $solution is NULL. However, in setMethod("invert", signature(object = "GUROBI_QP",..), it tries to do status_map(object, solution$status), causing the above cryptic error message.

Same thing with conic_solvers.R

Maybe change it to results_dict$solution$status <- 'SOLVER_ERROR'

@klin333 klin333 changed the title Need better handling of solver error Need better handling of GUROBI solver error Nov 19, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant