Infeasibility when optimizing large COBRApy community models

8 views
Skip to first unread message

Nicholas Y

unread,
Apr 12, 2026, 4:01:28 PM (6 days ago) Apr 12
to cobra pie
Hi,

I am trying to use COBRApy to simulate large community models of microbes using the CPLEX solver. As part of my pipeline I repeatedly maximize and minimize internal exchange reactions between microbes under certain constraints.

I am running into an issue where, when I try to minimize an IEX reaction, it minimizes fine, but when I try to maximize that same reaction immediately afterwards, the problem returns status infeasible. I am not changing the constraints or problem itself between minimization and maximization, and I am minimizing and maximizing the same reaction.

I have attempted multiple methods of resolving this. I have tried using the `flux_variability_analysis` function with `fraction_of_optimum` set to 0 and the reaction list of the reactions I want to maximize and minimize, but even that function errors due to infeasibilities. I have also tried resetting the solver state if a problem returns infeasible by changing the solver to something else and then changing it back to CPLEX (e.g.

```python
model.solver = 'glpk'
model.solver = 'cplex'
```

) but I still run into infeasibilities even when I do this. I have also tried using context managers (i.e., `with model:`) for the minimization and maximization.

I believe this is a numerical issue rather than an issue with my model formulation since when I load the same model with the same constraints in a separate Jupyter notebook and only maximize and minimize the reaction that causes infeasibility in isolation, it works fine. Both max and min are feasible. It is only in the context of the full pipeline, when I max and min all the reactions, that when it has this issue. Furthermore, the minimization works but the maximization is infeasible, which in theory should not happen since I am not changing any constraints of the problem between minimization and maximization.

I was wondering if you are aware of any similar issues, or have any idea what might cause this. Or any ideas of things I could try to prevent this from happening. Any advice or suggestions would be much appreciated. If you would like me to provide more details, please let me know and I would be happy to do so. Thank you!

Best regards,
Nicholas
Reply all
Reply to author
Forward
0 new messages