micom-dev / micom

Python package to study microbial communities using metabolic modeling.
https://micom-dev.github.io/micom
Apache License 2.0
89 stars 18 forks source link

Verbose messages from gurobi when loading community model #2

Closed mmundy42 closed 6 years ago

mmundy42 commented 6 years ago

I created a simple community model with two species, set the solver to gurobi, and saved the community model using to_pickle(). When I load the community model, gurobi logs several messages which makes loading the community model slow. Is this just the way gurobi works or are there some attributes or settings I should be using to make loading a model with gurobi as the solver efficient?

Here's how I created the community model:

>>> import micom
>>> import pandas as pd
>>> tax = pd.DataFrame({'id': ['a', 'b'], 'file': ['Clostridium_hathewayi_DSM_13479.xml', 'Eubacterium_siraeum_DSM_15702.xml']})
com = micom.Community(tax, id='test', progress=False)
>>> com.solver = 'gurobi'                                
>>> com.optimize()                                       
<CommunitySolution 31.217 at 0x7f713cad3198>             
>>> com.to_pickle('gurobitest.pickle')

Then, in a new Python session, I loaded the community model with these commands:

>>> import micom
>>> com = micom.load_pickle('gurobitest.pickle')
Academic license - for non-commercial use only
Changed value of parameter Method to 0
   Prev: -1  Min: -1  Max: 5  Default: -1
Changed value of parameter Presolve to 0
   Prev: -1  Min: -1  Max: 2  Default: -1
>>> com.solver
<optlang.gurobi_interface.Model object at 0x7fb02f8c2470>
>>> com.optimize()
<CommunitySolution 31.217 at 0x7fb036450a20>
cdiener commented 6 years ago

Hi, yes I also observed that. This seems to be a bug in gurobi which ignores its own OutputFlag parameter. You can verify that output is turned of with com.solver.problem.Params.OutputFlag == 0. However that output is generated on the C level and should not really affect speed too much. I have also observed that unpickling gurobi objects is slow which is due to the fact that between the 3 interfaces (glpk, cplex and gurobi) gurobi creates by far the largest objects. So unpickling will be slower.

One tip: micom.Community has a solver argument to which you can pass the solver used during construction. This will be much faster than changing the solver afterwards.

mmundy42 commented 6 years ago

Thanks the tip. I didn't realize that gurobi created large objects and that explains the performance issue I found.

cdiener commented 6 years ago

Yeah. For larger models (50+ species) cplex worked best for me. For smaller ones GLPK has good performance actually.