opencobra/cobrapy

gurobipy.Model.addConstr() DeprecationWarning

wshao1 opened this issue · 4 comments

wshao1 commented

Problem description

I am unable to load Human-GEM (or any other model) using cobrapy.

Code Sample

My code:

human1 = read_sbml_model('../raw_data/Human-GEM/model/Human-GEM.xml')

Warning/error:

DeprecationWarning                        Traceback (most recent call last)
~\anaconda3\lib\site-packages\cobra\io\sbml.py in read_sbml_model(filename, number, f_replace, **kwargs)
    457         doc = _get_doc_from_filename(filename)
--> 458         return _sbml_to_model(doc, number=number, f_replace=f_replace, **kwargs)
    459     except IOError as e:

~\anaconda3\lib\site-packages\cobra\io\sbml.py in _sbml_to_model(doc, number, f_replace, set_missing_bounds, **kwargs)
    730         ex_reactions.append(ex_reaction)
--> 731     cobra_model.add_reactions(ex_reactions)
    732 

~\anaconda3\lib\site-packages\cobra\core\model.py in add_reactions(self, reaction_list)
    755         # from cameo ...
--> 756         self._populate_solver(pruned)
    757 

~\anaconda3\lib\site-packages\cobra\core\model.py in _populate_solver(self, reaction_list, metabolite_list)
   1151 
-> 1152         self.solver.update()
   1153         for reaction in reaction_list:

~\anaconda3\lib\site-packages\optlang\gurobi_interface.py in update(self)
    670     def update(self):
--> 671         super(Model, self).update(callback=self.problem.update)
    672 

~\anaconda3\lib\site-packages\optlang\interface.py in update(self, callback)
   1473         if len(add_constr) > 0:
-> 1474             self._add_constraints(add_constr)
   1475             self._pending_modifications.add_constr = []

~\anaconda3\lib\site-packages\optlang\gurobi_interface.py in _add_constraints(self, constraints, sloppy)
    727 
--> 728                 self.problem.addConstr(lhs, sense, rhs, name=constraint.name)
    729             else:

src\gurobipy\model.pxi in gurobipy.Model.addConstr()

DeprecationWarning: Deprecated, pass a TempConstr or use Model.addLConstr

The above exception was the direct cause of the following exception:

CobraSBMLError                            Traceback (most recent call last)
~\AppData\Local\Temp\ipykernel_3852\2568799002.py in <module>
      1 ## Load generic human reconstruction
----> 2 human1 = read_sbml_model('../raw_data/Human-GEM/model/Human-GEM.xml')
      3 human1

~\anaconda3\lib\site-packages\cobra\io\sbml.py in read_sbml_model(filename, number, f_replace, **kwargs)
    470             "at https://github.com/opencobra/cobrapy/issues ."
    471         )
--> 472         raise cobra_error from original_error
    473 
    474 

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 .

Context

System Information
==================
OS         Windows
OS-release      10
Python      3.9.13

Package Versions
================
appdirs                                      1.4.4
black                                       22.6.0
bumpversion ; extra == 'development' not installed
cobra                                       0.26.2
depinfo                                      1.7.0
diskcache                                    5.4.0
future                                      0.18.2
httpx                                       0.23.3
importlib-resources                         5.12.0
isort                                        5.9.3
numpy                                       1.21.5
optlang                                      1.6.1
pandas                                       1.4.4
pip                                         22.2.2
pydantic                                    1.10.7
python-libsbml                              5.19.7
rich                                        13.3.2
ruamel.yaml                                0.17.21
scipy                                        1.9.1
setuptools                                  63.4.1
swiglpk                                      5.0.8
tox ; extra == 'development'         not installed
wheel                                       0.37.1

@wshao1 maybe try with the yaml file

Sounds like there are some deprecations in a new Gurobi version. I will investigate. However, can you attach the full error message? Because that is just a warning and should not have raised an error. So it looks like something else is going on.

wshao1 commented

@cdiener Thanks for pointing that out! The culprit was another script I was importing that was raising all warnings as errors. Removed it and it's fixed now. 🙂

Awesome, thanks. I will still add updating the Gurobi constraints in optlang to my TODO.