micom-dev / micom

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

Why is cooperative_tradeoff with "fluxes=True" not feasible sometimes? #11

Closed cymee95 closed 3 years ago

cymee95 commented 3 years ago

Hi. I have a question about cooperative_tradeoff. (micom 0.16.1, cplex 12.10.0) I used medium condition from VMH database and manually added some components to make my community model(over 50 members) could grow.

What I want to look at is exchange reactions of each member. It worked when I run this code with the community model,

com.cooperative_tradeoff(min_growth=0,fraction=0.4, fluxes=False, pfba=True)

But cooperative_tradeoff with fluxes=True returned this result. com.cooperative_tradeoff(min_growth=0,fraction=0.4, fluxes=True, pfba=True)

2020-07-18 03:23:17.495 | WARNING  | micom.solution:solve:222 - solver encountered an error infeasible

Traceback (most recent call last):
  File "C:/Users/user/PycharmProjects/MicomEdit/trash.py", line 74, in <module>
    a=com.cooperative_tradeoff(min_growth=0,fraction=0.4,fluxes=True, pfba=True)
  File "C:\Users\user\AppData\Roaming\Python\Python37\site-packages\micom\community.py", line 693, in cooperative_tradeoff
    return cooperative_tradeoff(self, min_growth, fraction, fluxes, pfba)
  File "C:\Users\user\AppData\Roaming\Python\Python37\site-packages\micom\problems.py", line 98, in cooperative_tradeoff
    sol = crossover(com, sol, fluxes=fluxes, pfba=pfba)
  File "C:\Users\user\AppData\Roaming\Python\Python37\site-packages\micom\solution.py", line 282, in crossover
    % community.solver.status
cobra.exceptions.OptimizationError: crossover could not converge (status = infeasible).

Process finished with exit code 1

Also, I found that if I run with another samples (with different members of microbial community) it sometimes worked with fluxes=True.

I'm trying to find the medium condition which I can apply to multiple samples before I compare exchange fluxes. And this issue keeps occuring and wondering why "fluxes" parameter matters and how to solve it. Thank you!

cdiener commented 3 years ago

Just to confirm: that only occurs with pfba=True, right? This is related to numerical accuracy issues when changing from QP to LP problems and back. I should allow setting the tolerances for the pFBA solution to stabilize that. One workaround is to set the minimal medium and resolving with pfba=False this is faster and usually still gives a parsimonious solution.

cymee95 commented 3 years ago

Just to confirm: that only occurs with pfba=True, right? --> Yes, you're right.

I tested again with fluxes=True ,pfba=False and it worked well. Thank you!

cdiener commented 3 years ago

PFBA now uses the solver tolerance and allows setting tolerances as well which should help work around that.