Solvers

3rd party solver installation

Through COBRApy, StrainDesign is already shipped with the free GLPK linear programming solver. Alternatively, the more powerful commercial solvers IBM CPLEX and Gurobi can be used by both COBRApy and StrainDesign, and the free solver SCIP can be used by StrainDesign. Using one of the GLPK alternatives is preferred, in particular, when using strain design algorithms like MCS, OptKnock etc. since their support of indicator contstraints renders computations significantly more stable.

In the following, you will find installation instructions for the individual solvers.

Warning:

The free community versions of CPLEX and Gurobi can be used. However, with larger problems (100+ reactions) their problem size limitations may result in uncaught errors.

CPLEX

Together with Gurobi, CPLEX is the perfect choice for computing strain designs. Its stability and support of advanced features like indicator constraints and populating solution pools make it indispensible for genome-scale computations.

Note:

You will need an academic or commercial licence to be able to use CPLEX.

Download and install the CPLEX suite and make sure that your CPLEX and Python versions are compatible. This step will not yet install CPLEX in your Python environment. Once the installation is completed, you may link your installation to your Python/conda environment. This is the next step.

Using the command line, navigate to your CPLEX installation path and into the Python folder. The path should look similar to

C:/Program Files/CPLEX2210/python

Make sure to activate the same Python/conda environment where cobra and straindesign are installed. Then call

python setup.py install

Now CPLEX should be available for your computations.

The official instructions can be found here: https://www.ibm.com/docs/en/icos/22.1.0?topic=cplex-setting-up-python-api

Gurobi

Similar to CPLEX, Gurobi offers a fast MILP solvers with the advanced features of indicator constraints and solution pooling. The installation steps are similar to the ones of CPLEX.

Note:

You will need an academic or commercial license and install the Gurobi solver software.

Ensure that the versions of Gurobi and Python versions are compatible, install Gurobi on your system and activate your license following the steps from the Gurobi manual. In the next step you will link your Gurobi installation to your Python/conda environment.

Using the command line, navigate to your CPLEX installation path and into the Python folder. The path should look similar to

C:/gurobi950/windows64

Make sure to activate the same Python/conda environment where cobra and straindesign are installed. Then call

python setup.py install

If your gurobipy package does not work right away, additionally install the gurobi package from conda or PyPi via

conda install -c gurobi gurobi

or

python -m pip install gurobipy

Now Gurobi is available for your computations.

The official instructions can be found here: https://support.gurobi.com/hc/en-us/articles/360044290292-How-do-I-install-Gurobi-for-Python-

SCIP

Less powerful than CPLEX and Gurobi, the open source solver SCIP still offers the solution of MILPs with indicator constraints, which gives it an edge above GLPK in terms of stability. If you want to use SCIP, you may install it via conda or pip:

conda install -c conda-forge pyscipopt

or

python -m pip install pyscipopt

Warning:

If you encounter program crashes with SCIP (a dependency of pyscipopt), make sure you use a version different from 8.0.1. You can, for instance manually install version 8.0.0 through conda install -c conda-forge scip=8.0.0.

Official website: https://github.com/scipopt/PySCIPOpt

Solver selection

For any type of LP or MILP-based analysis or design method, four different sovers are supported: GLPK (which is built into COBRApy/optlang), IBM CPLEX, Gurobi and SCIP. You can query the available solvers by accessing the set straindesign.avail_solvers. For the subsequent steps we also import the cobra module and load the E. coli core model.

[1]:
import cobra
import straindesign as sd
model = cobra.io.load_model('e_coli_core')

sd.avail_solvers
Set parameter Username
Academic license - for non-commercial use only - expires 2023-07-20
[1]:
{'cplex', 'glpk', 'gurobi', 'scip'}

You may enforce the use of a specific solver by specifying the “solver”-keyword. E.g., to enforce the use of GLPK, use:

[2]:
solution = sd.fba(model, solver='glpk')

print(f"Maximum growth: {solution.objective_value}.")
Maximum growth: 0.873921506969.

By default, the automatic solver selection uses COBRApy’s selection. Therefore, StrainDesign will try to use the model’s selected solver:

[3]:
print(f"When the model\'s solver is \'{model.solver.configuration}', StrainDesign selects {sd.select_solver(None,model)}.")
When the model's solver is '<optlang.gurobi_interface.Configuration object at 0x0000014FE00DA400>', StrainDesign selects gurobi.

Otherwise COBRApy’s global configuration is used.

[4]:
print(f"COBRApy\'s solver is \'{cobra.Configuration().solver.__name__}', StrainDesign selects {sd.select_solver()}.")
COBRApy's solver is 'optlang.gurobi_interface', StrainDesign selects gurobi.
[5]:
model.solver = 'cplex'
sd.select_solver('glpk',model)
[5]:
'glpk'