MOSEK / Tutorials

A collection of tutorials for the MOSEK package
107 stars 31 forks source link

Same hashes for different mosek parameters #5

Closed EmJay276 closed 1 year ago

EmJay276 commented 1 year ago

I am using cvxpy with the python mosek package. When I try to pass mosek.dparam.intpnt_tol_dfeas and mosek.iparam.intpnt_solve_form as keys to a python dict it results in dict with just one entry. The hases of mosek.dparam.intpnt_tol_dfeas and mosek.iparam.intpnt_solve_form are the same!

mosek_params={mosek.dparam.intpnt_tol_dfeas: (1.0e-8 / length.max()), 
              mosek.iparam.intpnt_solve_form: mosek.solveform.dual}

Result

>>> mosek_params
{intpnt_tol_dfeas: dual}

Hashes

>>> hash(mosek.dparam.intpnt_tol_dfeas)
28
>>> hash(mosek.iparam.intpnt_solve_form)
28
erling-d-andersen commented 1 year ago

But

mosek.dparam.intpnt_tol_dfeas

and

mosek.iparam.intpnt_solve_form

most likely has the same value and that is legal. I am not a cvxpy expert but to me it seems you do something wrong. Maybe you should quote the keys.

I think you can do

mosek_params = {'MSK_DPAR_INTPNT_TOL_DFEAS': 1.0e-8, 'MSK_IPAR_INNTPNT_SOLVE_FORM' : 'MSK_SOLVE_DUAL' }

Cvxpy documentation :

'mosek_params' A dictionary of MOSEK parameters. Refer to MOSEK’s Python or C API for details. Note that if parameters are given as string-value pairs, parameter names must be of the form 'MSK_DPAR_BASIS_TOL_X' as in the C API. Alternatively, Python enum options like 'mosek.dparam.basis_tol_x' are also supported.

EmJay276 commented 1 year ago

Thanks for the for response and advide, I solved it by using the string version for the keys.

mosek_params = {'MSK_DPAR_INTPNT_TOL_DFEAS': 1.0e-8,
                'MSK_IPAR_INTPNT_SOLVE_FORM': mosek.solveform.dual}

most likely has the same value and that is legal. I am not a cvxpy expert but to me it seems you do something wrong. Maybe you should quote the keys.

The hash values are probably unique (I haven't checked all) within mosek.iparam and mosek.dparam but not across them.

The parameter keys (eg. mosek.dparam.intpnt_tol_dfeas) are directly passed to back to mosek within cvxpy (source) , so I don't think it is a cvxpy issue.

Of course it could be fixed / work arounded within cvxpy by supplying different dicts for iparam and dparam, but I more likely think the values in the mosek package should be unique, not only within each of iparam and dparam but also across them.

erling-d-andersen commented 1 year ago

I will have our cvxpy expert to look into this and report back to cvxpy developers if their implementation is broken.

Personally I would use string version since this should be rock solid.

EmJay276 commented 1 year ago

@erling-d-andersen @phschiele determined the source of the issue https://github.com/cvxpy/cvxpy/issues/2023#issuecomment-1405814496 . It is due to the use of a custom Enum class instead of the build in class.

aszekMosek commented 1 year ago

I will close this here because it is not an issue in Mosek. The discussion about how to best fix cvxpy can take place in the cvxpy issue.