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

[BUG] Difficulties setting up Gurobi within COBRApy #1419

Open
1 task done
ivanmm25 opened this issue Dec 9, 2024 · 4 comments
Open
1 task done

[BUG] Difficulties setting up Gurobi within COBRApy #1419

ivanmm25 opened this issue Dec 9, 2024 · 4 comments
Labels

Comments

@ivanmm25
Copy link

ivanmm25 commented Dec 9, 2024

Is there an existing issue for this?

  • I have searched the existing issues

Problem description

Hi! I was trying to set up the Gurobi solver within COBRApy, within a Python application container.

I followed the installation instructions for Gurobi in a Python-based docker container, either with a Gurobi-based image or with a Python-based image and simply installing gurobipy during build (this is working).

I requested a free academic WLS license and made it available within the container according to the indicated specifications. Finally, I tested the license with a couple of optimization examples (not involving COBRApy) and it was working.

However, when I was trying to execute COBRApy with the gurobi solver, I got an error while reading a VALID (XML format) model with cobra.io.read_sbml_model. This error is

CobraSBMLError: Something went wrong reading the SBML model. Most likely the SBML model is not valid. Please check that your model is valid using the `cobra.io.sbml.validate_sbml_model` function or via the online validator at https://sbml.org/validator_servlet/ . 	(model, errors) = validate_sbml_model(filename)` If the model is valid and cannot be read please open an issue at https://github.com/opencobra/cobrapy/issues. 

When executing (model, errors) = cobra.io.validate_sbml_model(modelpath), other than warnings there is a ‘COBRA_FATAL’ entry indicating ['addConstr() takes at most 3 positional arguments (4 given)'], which is unfamiliar to me.

Regarding my system, I am using python:3.12-slim as base image for the container, creating and executing a Python environment (version 3.12 again) within the container and installing libraries (cobra==0.29.0, gurobipy==12.0.0) within this environment.

Note that available solvers are displayed when I execute cobra.core.configuration.SOLVERS ('gurobi': <module 'optlang.gurobi_interface' from '/opt/intvenv/lib/python3.12/site-packages/optlang/gurobi_interface.py'>), and that a connection is established (a token is created) when my code tries to access my Gurobi WLS license.

Set parameter WLSAccessID  
Set parameter WLSSecret  
Set parameter LicenseID to value ... 
[client] info : [...] 
[client] info : Validate token ... 
[client] info : *** Academic license ... - for non-commercial use only - registered to [email address]  
[client] info: Token is valid 

Could you please help me? Also do not hesitate to ask for additional information in case I forgot to provide it. Thank you very much!

Environment

### Package Information
Package Version
cobra 0.29.0

Dependency Information

Package Version
appdirs 1.4.4
black missing
bumpversion missing
depinfo 2.2.0
diskcache 5.6.3
future 1.0.0
httpx 0.28.1
importlib-resources 6.4.5
isort missing
numpy 2.1.1
optlang 1.8.2
pandas 2.2.2
pydantic 2.10.3
python-libsbml 5.20.4
rich 13.9.4
ruamel.yaml 0.18.6
scipy 1.14.1
swiglpk 5.0.12
tox missing

Build Tools Information

Package Version
pip 24.3.1
setuptools 75.6.0

Platform Information

Linux 6.8.0-49-generic-x86_64
CPython 3.12.8
@ivanmm25 ivanmm25 added the bug label Dec 9, 2024
@cambordas
Copy link

This problem originates from optlang opencobra/optlang#273 . I managed to overcome this for the time being using gurobipy version 11.0.3

@ivanmm25
Copy link
Author

Okay, thank you very much! By any chance, do you know if we can expect the bug to be fixed to update gurobipy to the latest version at some point?

@cdiener
Copy link
Member

cdiener commented Dec 11, 2024

As @cambordas said this was due to an incompatibility in optlang. It is already fixed there and will be part of the next release. Downgrading gurobi will work for now.

@ivanmm25
Copy link
Author

All clear, thank you, @cdiener!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants