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

Mosek license file can no longer be found after #2326 #2445

Open
apmorton opened this issue May 14, 2024 · 10 comments
Open

Mosek license file can no longer be found after #2326 #2445

apmorton opened this issue May 14, 2024 · 10 comments

Comments

@apmorton
Copy link

apmorton commented May 14, 2024

Describe the bug
Setting MOSEKLM_LICENSE_FILE in the current processes environment prior to using cvxpy no longer works.

To Reproduce

import os

from cvxpy.tests.solver_test_helpers import StandardTestLPs

os.environ['MOSEKLM_LICENSE_FILE'] = '/path/to/mosek.lic'
StandardTestLPs.test_lp_0(solver='MOSEK')

Expected behavior
I expect the code above to continue working.

Output
This now raises:

mosek.Error: rescode.err_missing_license_file(1008): License cannot be located. The default search path is ':/home/user/mosek/mosek.lic:'

See: #2326

@apmorton
Copy link
Author

For anyone looking for a workaround, the following works:

import mosek
from cvxpy.tests.solver_test_helpers import StandardTestLPs

mosek.Env(
    globalenv=True,
    licensefile='/path/to/mosek.lic',
)
StandardTestLPs.test_lp_0(solver='MOSEK')

@phschiele
Copy link
Collaborator

@apmorton which mosek and cvxpy version are you using?

@apmorton
Copy link
Author

mosek 10.1.31
cvxpy 1.5.1

@aszekMosek
Copy link
Contributor

aszekMosek commented May 17, 2024

In Mosek 10 with the global environment the path to the license file must be known before the first time Mosek is loaded. So an easier hack would be to first set the variable in os.environ and then "import mosek", or in any case set the environment before the first import of anything from mosek, cvxpy etc. that could load Mosek. I don't guarantee it works on Windows.

The only true and correct solution of course is to never change the environment inside the process but set everything before calling the process.

@phschiele
Copy link
Collaborator

Thanks @aszekMosek for the explanation, and glad that @apmorton found a workaround. Does not appear to be directly related to a change in CVXPY, so I'm going ahead and close this issue for now.

@apmorton
Copy link
Author

I'm not sure that is a fair assessment - this is the direct result of a change in cvxpy - #2326

Prior to then cvxpy wouldn't initialize mosek until the first usage, now it initializes it at import time.

This is a noticeable behavior change and broke our usage of cvxpy.

@aszekMosek is the workaround I posted above something supported by mosek?

@phschiele phschiele reopened this May 22, 2024
@phschiele
Copy link
Collaborator

@apmorton sorry about that, misread the issue to be a change in mosek behavior!

@aszekMosek
Copy link
Contributor

Both before and after #2326 CVXPY did not support any official mechanism to pass a license path to Mosek, so nothing changed in this respect. I would argue that both your solutions before and after #2326 are to some extent semi-supported hacks which one way or another try to bypass the one official mechanism applicable in this situation, which is to have MOSEKLM_LICENSE_FILE set in the initial environment of the process.

Yes, the workaround works because it is ultimately equivalent to calling the API method env.putlicensepath() on the global Mosek environment created when Mosek is first loaded. As of now it is not officially supported.

If you would like to then please contact Mosek support and we can think what else can be done about that.

@apmorton
Copy link
Author

We have been relying on the ability to set MOSEKLM_LICENSE_FILE path at runtime in production for many years.

The requirement to know this path and set an environment variable prior to process creation in all possible scenarios where mosek will be used is very tedious.

We will be reaching out to support on this matter since having the ability to set this at runtime is important to our business.

@aszekMosek
Copy link
Contributor

We have some idea for what we could change so that you get an official, supported solution, but that will be in Mosek version 10.2, ie. the current one. We can discuss it in support.

Just to summarize the other current options for how to modify the license path in the global Mosek environment:

  1. your solution with mosek.Env(globalenv=True).putlicensepath("/path/...") (works, relies on unofficial behavior)
  2. setting os.environ before the first time any mosek is loaded (Linux and OSX only, relies on unofficial behavior)
  3. using Fusion as a proxy: mosek.fusion.Model.putlicensepath("/path/...") (works, official for the Fusion API, unnatural in the context of cvxpy)

The proposed solution we have in mind goes towards cleaning up and legalizing something along the lines of 1. Until you can use that then the solution in 1. is probably best.

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

3 participants