0

I am using CVXR to solve an optimization problem in R using the MOSEK solver. CVXR has found the MOSEK SOLVER through ANACONDA and is working fine. However, I do not manage to generate the MOSEK feasibility report when the model is infeasible. This is normally switched on with MSK_IPAR_INFEAS_REPORT_AUTO = "ON" (at least in GAMS, where I have used MOSEK before) and very useful to identify problems in model design, data, etc. The standard command gives me an error. Then I tried the Python interface, which tells me to use: task.putintparam(iparam.infeas_report_auto, onoffkey.on). This seems to be accepted by my solve command but still does not spit out the feasibility report. Below a reproducible example. What am I doing wrong?


# Check solvers
installed_solvers()

# Main variable
x <- Variable(1)

# Objective function
objective <- x

# Constraint
constraint <- list(x >0, x-1>0)

# Solve
problem <- CVXR::Problem(Maximize(objective), c(constraint))
sol <- psolve(problem, solver = "MOSEK", verbose = TRUE, task.putintparam(iparam.infeas_report_auto, onoffkey.on))

Gives only the standard output:

Problem Name :
Objective sense : min
Type : LO (linear optimization problem) Constraints : 2
Cones : 0
Scalar variables : 1
Matrix variables : 0
Integer variables : 0

Optimizer started. Presolve started. Eliminator started. Freed constraints in eliminator : 0 Eliminator terminated. Eliminator started. Freed constraints in eliminator : 0 Eliminator terminated. Eliminator - tries : 2 time : 0.00
Lin. dep. - tries : 0 time : 0.00
Lin. dep. - number : 0
Presolve terminated. Time: 0.00
Optimizer terminated. Time: 0.01

Interior-point solution summary Problem status : DUAL_INFEASIBLE Solution status : DUAL_INFEASIBLE_CER Primal. obj: -1.0000000000e+00 nrm: 1e+00 Viol. con: 0e+00 var: 0e+00

Basic solution summary Problem status : DUAL_INFEASIBLE Solution status : DUAL_INFEASIBLE_CER Primal. obj: -1.0000000000e+00 nrm: 1e+00 Viol. con: 0e+00 var: 0e+00

  • This looks very unlikely to be the right syntax to set MOSEK parameters through CVXR, although to be honest I don't know the correct one. Did you find it documented somewhere? – Michal Adamaszek Nov 26 '19 at 06:27

1 Answers1

0

I looked through the code. The correct syntax should in principle be the same as in CVXPY, that is:

sol <- psolve(problem, solver = "MOSEK", verbose = TRUE, 
       mosek_params=list("MSK_IPAR_INFEAS_REPORT_AUTO" = 1) )

However this will not work because of a bug in

https://github.com/cvxgrp/CVXR/blob/master/inst/python/mosekglue.py#L36

There is an excessive self, probably copied from CVXPY without testing. OK, so you can go to the same file in your CVXR installation, remove self., and not it almost works, except that 1 is a double in R, and not an integer, so MOSEK will not take it as a value.

So, eventually: you have to 1) make the fix in line 36 mentioned above and change it to just

_handle_mosek_params(task, solver_opts["mosek_params"])

(remove self. at the beginning) and then 2) write the more cumbersome

sol <- psolve(problem, solver="MOSEK", verbose="TRUE", 
       mosek_params=list('MSK_IPAR_INFEAS_REPORT_AUTO' = as.integer(1)))

Similar tricks apply to all parameter settings. Unfortunately a string MSK_ON will not be accepted as a value, again mostly because in CVXPY this was not necessary (there are Python enumerations).

  • I commented out: self._handle_mosek_params(task, solver_opts["mosek_params"]) in the modesglue.py file and tried your suggested code ```sol <- psolve(problem, solver="MOSEK", verbose="TRUE", mosek_params=list('MSK_IPAR_INFEAS_REPORT_AUTO' = as.integer(1)))``` but it still does not generate the feasibility report. Can you point out what exactly needs to be changed in the python code? Perhaps this was not the correct approach. It would be nice if the authors of the package could fix this bug. – Michiel van Dijk Nov 26 '19 at 09:18
  • @MichielvanDijk Don't comment out the whole line, just remove ``self.`` (leave the rest of the function call) – Michal Adamaszek Nov 26 '19 at 09:25
  • @MichielvanDijk Time permitting I will make a pull request in CVXR fixing this and maybe improving parameter handling a bit to make it look more like in R or as you wrote in GAMS. – Michal Adamaszek Nov 26 '19 at 09:28