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

Error in importation of linopy : MOSEK license not found #206

Closed
robingirard opened this issue Nov 21, 2023 · 7 comments
Closed

Error in importation of linopy : MOSEK license not found #206

robingirard opened this issue Nov 21, 2023 · 7 comments

Comments

@robingirard
Copy link

Dear Linopy community, I have installed version 0.3.1. I'm happy that MOSEK is now a possible solver, but when I import linopy on a computer without mosek I have the following error :

In [7]: import linopy
Traceback (most recent call last):
File "/home/rgirard/.virtualenvs/LEAP/lib/python3.10/site-packages/IPython/core/interactiveshell.py", line 3548, in run_code
exec(code_obj, self.user_global_ns, self.user_ns)
File "", line 1, in
import linopy
File "/home/rgirard/.virtualenvs/LEAP/lib/python3.10/site-packages/linopy/init.py", line 12, in
from linopy import model, remote
File "/home/rgirard/.virtualenvs/LEAP/lib/python3.10/site-packages/linopy/model.py", line 21, in
from linopy import solvers
File "/home/rgirard/.virtualenvs/LEAP/lib/python3.10/site-packages/linopy/solvers.py", line 61, in
m.optimize()
File "/home/rgirard/.virtualenvs/LEAP/lib/python3.10/site-packages/mosek/init.py", line 10781, in optimize
return self.__optimizetrm__1(*args,**kwds)
File "/home/rgirard/.virtualenvs/LEAP/lib/python3.10/site-packages/mosek/init.py", line 10770, in __optimizetrm__1
raise Error(rescode(_res_optimizetrm),_msg_optimizetrm)
mosek.Error: rescode.err_missing_license_file(1008): License cannot be located. The default search path is ':/home/rgirard/mosek/mosek.lic:'.

It should be possible to import linopy without having a mosek license ! Am I missing something ?

@fneum
Copy link
Member

fneum commented Nov 21, 2023

You're totally right! No MOSEK license should be required.

@FabianHofmann something maybe going wrong with the new context manager?

linopy/linopy/solvers.py

Lines 57 to 66 in a97febe

with contextlib.suppress(ImportError):
import mosek
with contextlib.suppress(mosek.Error):
with mosek.Env() as m:
t = m.Task()
t.optimize()
m.checkinall()
available_solvers.append("mosek")

@FabianHofmann
Copy link
Collaborator

mmh, it works for me for all combinations:

  • package uninstalled, no license
  • package installed, no license
  • package installed, with license

are you on the latest master?

@robingirard
Copy link
Author

I installed with pip.

@FabianHofmann
Copy link
Collaborator

okay, could you then update the linopy package via pip? I just released version 0.3.2

@robingirard
Copy link
Author

It works now, thanks a lot.

@FabianHofmann
Copy link
Collaborator

great!

@asre244
Copy link

asre244 commented Feb 12, 2024

Hello @FabianHofmann

I am having a similar issue where I am not able to use the MOSEK solver although I do not get any error messages. I have installed the MOSEK package in the environment but it does not show up in the list of "available_solvers" in "linopy". I tried updating "linopy" as explained above but does not seem to change anything. Interestingly, I was able to use MOSEK a couple of days ago before the weekend but when I tried to use it again, it did not show up in the list of "available_solvers". I tried to work with gurobi to check if I was missing something but I was able to use gurobi.

available_solvers
installed packages

Update:

with contextlib.suppress(ImportError):
    import mosek
    with contextlib.suppress(mosek.Error):
        with mosek.Env() as m:
            t = m.Task()
            t.optimize()
            m.checkinall()
        available_solvers.append("mosek")

When I was debugging, the code stopped at "t.optimize()" and did not reach checkinall and append.

And it seems like it is a licensing error:

raise Error(rescode(_res_optimizetrm),_msg_optimizetrm)
mosek.Error: rescode.err_license_cannot_connect(1021): MOSEK cannot connect to the license server.

But from what I understand, I should be able to use MOSEK without license. Am I right or am I missing something?

Update - Solution:

I was able to figure it out.

It seemed like the code was not able to access the license file.

I manually added this during debugging to point out the location:

os.environ["MOSEKLM_LICENSE_FILE"] = "pathtolicensefile"

and from next time on it was able to automatically locate the license file.

Please look into this issue if necessary.

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

4 participants