Setting tolerances for mosek in CVX

I am trying to solve a LP on a rolling basis and run into infeasible solns. on some instances.
I have the following settings in my optimizer:

``````cvx_precision low
cvx_solver_settings('MSK_DPAR_INTPNT_CO_TOL_REL_GAP', 1e-5)
``````

and am wondering if there are other tolerances that I can add/control for my case below? I don’t case about the accuracy from the 100’s term and lower.

Here is the output of a feasible problem:

``````Calling Mosek 8.0.0.60: 60773 variables, 23605 equality constraints
For improved efficiency, Mosek is solving the dual problem.
------------------------------------------------------------
NOTE: custom settings have been set for this solver.
------------------------------------------------------------

MOSEK Version 8.0.0.60 (Build date: 2017-3-1 13:09:33)
Copyright (c) MOSEK ApS, Denmark. WWW: mosek.com
Platform: Windows/64-X86

Problem
Name                   :
Objective sense        : min
Type                   : CONIC (conic optimization problem)
Constraints            : 23605
Cones                  : 18547
Scalar variables       : 60773
Matrix variables       : 0
Integer variables      : 0

Optimizer started.
Conic interior-point optimizer started.
Presolve started.
Linear dependency checker started.
Linear dependency checker terminated.
Eliminator started.
Freed constraints in eliminator : 3373
Eliminator terminated.
Eliminator - tries                  : 1                 time                   : 0.00
Lin. dep.  - tries                  : 1                 time                   : 0.00
Lin. dep.  - number                 : 0
Presolve terminated. Time: 0.05
Optimizer  - solved problem         : the primal
Optimizer  - Constraints            : 20231
Optimizer  - Cones                  : 18547
Optimizer  - Scalar variables       : 57400             conic                  : 54026
Optimizer  - Semi-definite variables: 0                 scalarized             : 0
Factor     - setup time             : 0.14              dense det. time        : 0.00
Factor     - ML order time          : 0.02              GP order time          : 0.00
Factor     - nonzeros before factor : 1.97e+005         after factor           : 6.01e+005
Factor     - dense dim.             : 71                flops                  : 4.68e+007
ITE PFEAS    DFEAS    GFEAS    PRSTATUS   POBJ              DOBJ              MU       TIME
0   1.5e+000 3.9e+005 3.9e+005 0.00e+000  6.416504224e+009  1.564099246e+007  1.0e+000 0.22
1   4.1e-001 1.1e+005 5.6e+004 -1.00e+000 6.414217523e+009  1.562857217e+007  2.7e-001 0.30
2   1.0e-001 2.7e+004 7.1e+003 -9.99e-001 6.404582721e+009  1.556580049e+007  6.9e-002 0.34
3   3.3e-002 8.7e+003 1.3e+003 -9.96e-001 6.375242412e+009  1.536613260e+007  2.2e-002 0.39
4   9.1e-003 2.4e+003 1.9e+002 -9.86e-001 6.257904133e+009  1.458447363e+007  6.1e-003 0.44
5   2.4e-003 6.2e+002 2.7e+001 -9.50e-001 5.838827811e+009  1.189262268e+007  1.6e-003 0.48
6   5.7e-004 1.5e+002 3.8e+000 -8.23e-001 4.521543310e+009  3.722387101e+006  3.8e-004 0.53
7   1.4e-004 3.7e+001 8.7e-001 -4.14e-001 2.377836021e+009  -9.030469796e+006 9.6e-005 0.56
8   2.9e-005 7.7e+000 3.3e-001 3.03e-001  6.312464149e+008  -1.768561643e+007 2.0e-005 0.61
9   8.7e-006 2.3e+000 2.9e-001 1.28e+000  1.275436212e+008  -1.369178577e+007 5.8e-006 0.66
10  1.6e-006 4.2e-001 1.5e-001 2.14e+000  6.757146502e+006  -7.550900666e+006 1.1e-006 0.70
11  2.4e-007 6.2e-002 6.1e-002 1.12e+000  -4.103955629e+006 -6.080254238e+006 1.6e-007 0.75
12  4.4e-008 1.1e-002 3.1e-002 1.08e+000  -3.631419460e+006 -3.973389390e+006 2.9e-008 0.80
13  1.0e-008 2.7e-003 1.9e-002 1.19e+000  -1.459945630e+006 -1.531507141e+006 6.9e-009 0.83
14  8.2e-009 2.1e-003 1.7e-002 1.11e+000  -1.026719937e+006 -1.083326261e+006 5.4e-009 0.88
15  4.8e-009 1.3e-003 1.3e-002 1.04e+000  -3.830980021e+005 -4.172662801e+005 3.2e-009 0.92
16  3.6e-009 9.4e-004 1.1e-002 9.18e-001  -1.402827167e+005 -1.666501804e+005 2.4e-009 0.97
17  2.9e-009 7.5e-004 9.3e-003 8.33e-001  9.973788067e+003  -1.200208703e+004 1.9e-009 1.01
18  2.6e-009 6.7e-004 8.7e-003 7.72e-001  7.967928588e+004  5.949420147e+004  1.7e-009 1.06
19  2.5e-009 6.4e-004 8.4e-003 7.49e-001  1.096491331e+005  9.021655514e+004  1.6e-009 1.11
20  1.8e-009 4.7e-004 6.8e-003 7.34e-001  2.828544366e+005  2.675783314e+005  1.2e-009 1.14
21  1.5e-009 4.0e-004 6.1e-003 7.06e-001  3.575170844e+005  3.440682334e+005  1.0e-009 1.19
22  8.8e-010 2.3e-004 4.2e-003 6.72e-001  5.861238271e+005  5.773417968e+005  5.9e-010 1.23
23  5.6e-010 1.5e-004 3.0e-003 5.72e-001  7.556985751e+005  7.492953782e+005  3.7e-010 1.28
24  4.4e-010 1.1e-004 2.5e-003 5.28e-001  8.353204662e+005  8.298869190e+005  2.9e-010 1.33
25  2.8e-010 7.2e-005 1.7e-003 4.81e-001  9.742746298e+005  9.702427669e+005  1.8e-010 1.38
26  1.9e-010 4.6e-005 1.2e-003 4.51e-001  1.094781349e+006  1.091766272e+006  1.2e-010 1.42
27  1.6e-010 4.1e-005 1.1e-003 4.50e-001  1.123557540e+006  1.120765025e+006  1.0e-010 1.47
28  1.5e-010 3.8e-005 1.1e-003 4.86e-001  1.134054479e+006  1.131455395e+006  9.8e-011 1.50
29  1.4e-010 2.0e-005 6.6e-004 4.62e-001  1.262552716e+006  1.260866661e+006  5.2e-011 1.56
30  6.9e-011 1.0e-005 3.8e-004 5.04e-001  1.380267434e+006  1.379275127e+006  2.6e-011 1.59
31  5.2e-011 7.6e-006 3.1e-004 5.91e-001  1.414480471e+006  1.413681112e+006  1.9e-011 1.72
32  2.9e-011 4.2e-006 2.1e-004 6.60e-001  1.470582700e+006  1.470090577e+006  1.1e-011 1.84
33  1.3e-011 1.8e-006 1.2e-004 7.37e-001  1.519239938e+006  1.519004588e+006  4.7e-012 1.97
34  1.1e-010 6.4e-007 7.0e-005 9.50e-001  1.549923146e+006  1.549840016e+006  1.7e-012 2.08
Interior-point optimizer terminated. Time: 2.08.

Optimizer terminated. Time: 2.11

Interior-point solution summary
Problem status  : PRIMAL_AND_DUAL_FEASIBLE
Solution status : OPTIMAL
Primal.  obj: 1.5499231460e+006   nrm: 9e+004   Viol.  con: 5e-004   var: 1e-006   cones: 0e+000
Dual.    obj: 1.5498398096e+006   nrm: 3e+009   Viol.  con: 0e+000   var: 7e-001   cones: 0e+000
Optimizer summary
Optimizer                 -                        time: 2.11
Interior-point          - iterations : 34        time: 2.08
Basis identification  -                        time: 0.00
Primal              - iterations : 0         time: 0.00
Dual                - iterations : 0         time: 0.00
Clean primal        - iterations : 0         time: 0.00
Clean dual          - iterations : 0         time: 0.00
Simplex                 -                        time: 0.00
Primal simplex        - iterations : 0         time: 0.00
Dual simplex          - iterations : 0         time: 0.00
Mixed integer           - relaxations: 0         time: 0.00

------------------------------------------------------------
Status: Solved
Optimal value (cvx_optval): -1.79088e+07

cvx_slvtol =

1.2207e-04
``````

Below is the output of the infeasible soln. at another instance:

``````Calling Mosek 8.0.0.60: 60773 variables, 23605 equality constraints
For improved efficiency, Mosek is solving the dual problem.
------------------------------------------------------------
NOTE: custom settings have been set for this solver.
------------------------------------------------------------

MOSEK Version 8.0.0.60 (Build date: 2017-3-1 13:09:33)
Copyright (c) MOSEK ApS, Denmark. WWW: mosek.com
Platform: Windows/64-X86

Problem
Name                   :
Objective sense        : min
Type                   : CONIC (conic optimization problem)
Constraints            : 23605
Cones                  : 18547
Scalar variables       : 60773
Matrix variables       : 0
Integer variables      : 0

Optimizer started.
Conic interior-point optimizer started.
Presolve started.
Linear dependency checker started.
Linear dependency checker terminated.
Eliminator started.
Freed constraints in eliminator : 3373
Eliminator terminated.
Eliminator - tries                  : 1                 time                   : 0.00
Lin. dep.  - tries                  : 1                 time                   : 0.02
Lin. dep.  - number                 : 0
Presolve terminated. Time: 0.05
Optimizer  - solved problem         : the primal
Optimizer  - Constraints            : 20231
Optimizer  - Cones                  : 18547
Optimizer  - Scalar variables       : 57400             conic                  : 54026
Optimizer  - Semi-definite variables: 0                 scalarized             : 0
Factor     - setup time             : 0.11              dense det. time        : 0.00
Factor     - ML order time          : 0.00              GP order time          : 0.00
Factor     - nonzeros before factor : 1.97e+005         after factor           : 6.01e+005
Factor     - dense dim.             : 71                flops                  : 4.68e+007
ITE PFEAS    DFEAS    GFEAS    PRSTATUS   POBJ              DOBJ              MU       TIME
0   1.5e+000 3.9e+005 3.9e+005 0.00e+000  6.451078621e+009  5.021538870e+007  1.0e+000 0.20
1   4.1e-001 1.1e+005 5.6e+004 -1.00e+000 6.448780107e+009  5.019079931e+007  2.7e-001 0.27
2   1.0e-001 2.6e+004 6.9e+003 -9.99e-001 6.438809384e+009  5.007394463e+007  6.7e-002 0.31
3   3.4e-002 8.9e+003 1.3e+003 -9.96e-001 6.410449293e+009  4.973308855e+007  2.3e-002 0.36
4   9.3e-003 2.4e+003 2.0e+002 -9.87e-001 6.295363157e+009  4.836393549e+007  6.2e-003 0.41
5   2.5e-003 6.4e+002 2.8e+001 -9.52e-001 5.887955815e+009  4.361539188e+007  1.6e-003 0.45
6   7.0e-004 1.8e+002 5.0e+000 -8.28e-001 4.812323204e+009  3.129855102e+007  4.6e-004 0.50
7   1.8e-004 4.7e+001 1.1e+000 -4.97e-001 2.767876314e+009  8.184102411e+006  1.2e-004 0.55
8   3.7e-005 9.6e+000 3.6e-001 1.70e-001  7.916571161e+008  -1.285301426e+007 2.4e-005 0.59
9   1.0e-005 2.6e+000 2.9e-001 1.12e+000  1.647061739e+008  -1.373332629e+007 6.8e-006 0.63
10  2.3e-006 5.9e-001 2.0e-001 2.14e+000  1.329574279e+007  -7.877815395e+006 1.5e-006 0.67
11  2.8e-007 7.4e-002 7.7e-002 1.22e+000  -4.015970031e+006 -6.384864728e+006 1.9e-007 0.72
Interior-point optimizer terminated. Time: 0.73.

MOSEK DUAL INFEASIBILITY REPORT.

Problem status: The problem is dual infeasible
Optimizer terminated. Time: 0.77

Interior-point solution summary
Problem status  : DUAL_INFEASIBLE
Solution status : DUAL_INFEASIBLE_CER
Primal.  obj: -2.7510744688e+004  nrm: 7e+000   Viol.  con: 4e-004   var: 3e-004   cones: 2e-004
Optimizer summary
Optimizer                 -                        time: 0.77
Interior-point          - iterations : 11        time: 0.73
Basis identification  -                        time: 0.00
Primal              - iterations : 0         time: 0.00
Dual                - iterations : 0         time: 0.00
Clean primal        - iterations : 0         time: 0.00
Clean dual          - iterations : 0         time: 0.00
Simplex                 -                        time: 0.00
Primal simplex        - iterations : 0         time: 0.00
Dual simplex          - iterations : 0         time: 0.00
Mixed integer           - relaxations: 0         time: 0.00

------------------------------------------------------------
Status: Infeasible
Optimal value (cvx_optval): +Inf

cvx_slvtol =

1.2207e-04``````

Your problem has large objective value and very large dual solution. That will continue leading to numerical issues most likely.

BTW try Mosek 9 also.

Thank you for getting back. If I care for accuracy from the thousands digits and before/bigger terms, then, which of these tolerances do you suggest I use? E.g., if an optimal soln in the decision variable is 14,560,785.85975, then, I just require this to be rounded to 14,561,000.00

In this case can I remove (since the second one just specifies the tolerance of the duality gap)

cvx_precision low
cvx_solver_settings(‘MSK_DPAR_INTPNT_CO_TOL_REL_GAP’, 1e-5)

and specify my tols using the table you provided. A simple example would be highly appreciated

Regarding using Mosek 9 (current version 9.1.2) rather than 8.0.0.60, see my post How can I make changes in cvx solver setting for Mosek? .

Thank you, unfortunately I can just use 8.0.0.60.
Is there an example you can provide where I can adjust the tolerance to get accurate solutions till the thousands place?

Also, when I set `cvx_precision low` from http://cvxr.com/cvx/doc/solver.html, then, does this not automatically adjust mosek’s accuracy downstream?

I suppose it does. But if you read the linked manual page, you will see that the termination criteria are more complicated than just the number of significant digits, they depend on various norms etc. So you would have to experiment. But wouldn’t it be better to rescale the problem so that the variables and solution are measured in 1/1000 of the previous units? Taming the numerics is a good step to a faster and more reliable solution.

I think, but am not sure, that `cvx_solver_settings` overrides `cvx_precision`.

Thank you! So, in order to re-scale, do you suggest that I divide my term by 1000 before optimizing and then convert back by multiplying the solution with 1000?

Thank you. Is the machine level epsilon defined in cvx solvers used for mosek’s tolerance for the primal, dual, cost solutions as well?

I think so, except that `cvx_solver_settings` overrides that.

Thank you and sorry again for the bother. I tried using

cvx_solver_settings(‘eps’, 1e-6);

but get the error:

*** Error(1200): param.eps Return code - 1200 [MSK_RES_ERR_IN_ARGUMENT] [A function argument is incorrect.]

Status: Error
Optimal value (cvx_optval): NaN

Would appreciate any advice to get around this. Thank you.

You need to use the full parameter name as listed in the Mosek documentation, .as for instance in your first post of this thread.

Thank you again. One final Q re: that mosek seems to solve the dual problem:

``````Calling Mosek 8.0.0.60: 60917 variables, 23661 equality constraints
For improved efficiency, Mosek is solving the dual problem.
------------------------------------------------------------
``````

But, read in this post – Is cvx solving the Primal or the Dual Problem?
that cvx automatically extracts the original, primal solution from mosek’s dual solution. I do want the primal solution, but, is there a way for me to get access to both solutions? Not sure if there is some documentation on this?

However, was just concerned since the above had said Mosek was solving the dual problem.

You get the primal solution from CVX regardless of whether CVX sends the primal or dual to the solver.

For dual variable values, see http://cvxr.com/cvx/doc/basics.html#dual-variables and http://cvxr.com/cvx/doc/advanced.html#indexed-dual-variables .

So, even if mosek is solving the dual problem, as in output above, cvx still gets the primal solution? Does this not need to be output – something like “Mosek is solving the primal problem.”?
Ideally, I would have like to say that if an optimal or near optimal soln isn’t found, then, mosek should switch to solve the primal problem. Any suggestions on what I can do to overcome infeasible solutions would be much appreciated.

For instance, in Pyfusion https://docs.mosek.com/9.0/pythonfusion/parameters.html one can specify “MSK_IPAR_INTPNT_SOLVE_FORM” to control if either the primal or dual is solved. However, I would get an error when I specified this in cvx_solver_settings

Yes, as I wrote in my previous post.

I’ll defer to Johan who is helping you at https://groups.google.com/forum/?fromgroups#!topic/yalmip/coMpN8agFTo .

I have a somewhat related question. I am using mosek within cvx
cvx_begin quiet
cvx_solver mosek
cvx_solver_settings(‘MSK_IPAR_OPTIMIZER’,4)
etc…
Can I get the optimal BASIS from this, i.e. the optimal basis for this simplex method solution? I do get a basis but if it is degenerate then I cannot accurately get the basis matrix.

I will defer to the Mosek people to answer, but will note that you shouldn’t have `cvx_begin quiet` when you want to know what the solver is doing.

I do not think anyone at Mosek knows which solution type Cvx returns since we did not build Cvx.

But since you force the usage of the simplex optimizer then only a basic solution is available and hence you must get that.

If you use Mosek optimization toolbox directly you will get some status keys that tell you whether a variable is in the basis, on its lower bound, and so forth. I doubt you can get those status keys in Cvx. The documentation may provide an answer.

I would be using Mosek directly in your case.