{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "# Solvers" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "A constraint-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](https://en.wikipedia.org/wiki/Linear_programming) or [quadratic programming](https://en.wikipedia.org/wiki/Quadratic_programming) techniques. Cobrapy does not implement any algorithm to find solutions to such problems but rather creates a 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.\n", "\n", "The actual solving is instead done by tools such as the free software [glpk](https://www.gnu.org/software/glpk/) or commercial tools [gurobi](http://www.gurobi.com/) and [cplex](https://www-01.ibm.com/software/commerce/optimization/cplex-optimizer/) which are all made available as a common programmers interface via the [optlang](https://github.com/biosustain/optlang) package.\n", "\n", "When you have defined your model, you can switch solver backend by simply assigning to the `model.solver` property." ] }, { "cell_type": "code", "execution_count": 1, "metadata": {}, "outputs": [], "source": [ "from cobra.io import load_model\n", "model = load_model('textbook')" ] }, { "cell_type": "code", "execution_count": 2, "metadata": {}, "outputs": [], "source": [ "model.solver = 'glpk'\n", "# or if you have cplex installed\n", "model.solver = 'cplex'" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "For information on how to configure and tune the solver, please see the [documentation for optlang project](http://optlang.readthedocs.io) and note that `model.solver` is simply an optlang object of class `Model`." ] }, { "cell_type": "code", "execution_count": 3, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "optlang.cplex_interface.Model" ] }, "execution_count": 3, "metadata": {}, "output_type": "execute_result" } ], "source": [ "type(model.solver)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Internal solver interfaces" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "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](http://cobrapy.readthedocs.io/en/0.5.11/)." ] } ], "metadata": { "kernelspec": { "display_name": "Python 3 (ipykernel)", "language": "python", "name": "python3" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 3 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": "3.7.1" } }, "nbformat": 4, "nbformat_minor": 1 }