10. Solvers

A constraints-based reconstruction and analysis model for biological systems is actually just an application of a class of discrete optimization problems typically solved with linear, mixed integer or quadratic programming techniques. Cobrapy does not implement any algorithms to find solutions to such problems but rather creates an biologically motivated abstraction to these techniques to make it easier to think of how metabolic systems work without paying much attention to how that formulates to an optimization problem.

The actual solving is instead done by tools such as the free software glpk or commercial tools gurobi and cplex which are all made available as a common programmers interface via the optlang package.

When you have defined your model, you can switch solver backend by simply assigning to the model.solver property.

In [1]:
import cobra.test
model = cobra.test.create_test_model('textbook')
In [2]:
model.solver = 'glpk'
# or if you have cplex installed
model.solver = 'cplex'

For information on how to configure and tune the solver, please see the documentation for optlang project and note that model.solver is simply an object optlang of class Model.

In [3]:

10.1. Internal solver interfaces

Cobrapy also contains its own solver interfaces but these are now deprecated and will be removed completely in the near future. For documentation of how to use these, please refer to older documentation.