opencobra / cobrapy

COBRApy is a package for constraint-based modeling of metabolic networks.
http://opencobra.github.io/cobrapy/
GNU General Public License v2.0
461 stars 216 forks source link

Cannot deepcopy models with gurobipy with BiGG id `st` #1072

Open sirno opened 3 years ago

sirno commented 3 years ago

For some models it is not possible to apply deepcopy, because the reaction names may match reserved names of the gurobi LP format—see gurobi docs:

Also, variable names should not be equal (case insensitive) to any of the LP file format keywords, e.g., st, bounds, min, max, binary, or end. Names must be preceded and followed by whitespace.

This happens with sulfur diffusion, see bigg reaction 🤷‍♀️

Although this problem is related to the way optlang sets the state in its gurobi interface, I suppose this is still a cobrapy issue... sort of

/path/python-3.9.1/lib/python3.9/site-packages/optlang/gurobi_interface.py in __setstate__(self, repr_dict) 
    598     def __setstate__(self, repr_dict): 
    599         with TemporaryFilename(suffix=".lp", content=repr_dict["lp"]) as tmp_file_name:
--> 600             problem = gurobipy.read(tmp_file_name)
cdiener commented 3 years ago

Yes that is definitely not perfect. I would say it's more a limitation with gurobipy though since they don't provide native serialization like cplex for example: https://groups.google.com/g/gurobi/c/fwLRrWLLJqo. Adjusting the ids in the state setter and getter would work but that would have to be done in optlang.

Midnighter commented 3 years ago

This would be another place where it'd be great to maintain the SBML IDs and use those since the R_ and M_ prefixes commonly used would avoid this problem and still allow for easy manual inspection of the LP format.

sirno commented 3 years ago

Yes indeed, I suppose one can manually turn of the replacement of those prefixes with f_replace=None when loading SBML files.