Skip to content

Commit

Permalink
Make cvxpy optional
Browse files Browse the repository at this point in the history
  • Loading branch information
pablormier committed Aug 23, 2022
1 parent bbcdf4b commit c6b0797
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 14 deletions.
31 changes: 22 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,20 @@ The library will be uploaded to pypi once the API is stable. Meanwhile, it can b

### Minimal setup

With the minimal dependencies, corneto can be used with CVXPY and the Coin-OR CBC solver:
By default, CORNETO does not include any backend nor solver, in order to avoid issues with architectures for which some of the required binaries are not available by default. To install only CORNETO with mininal dependencies, d

```bash
conda create --name corneto python=3.8
conda activate corneto
pip install corneto-0.9.0a0-py3-none-any.whl
pip install corneto-0.9.0a3-py3-none-any.whl
```

#### CVXPY backend

CVXPY supports many solvers, including the Coin-OR CBC solver through the `cylp` package. If you want to have support for solving problems both for non-commercial and commercial projects, you can use CORNETO with `cvxpy` and `cylp`:

```bash
pip install cvxpy cylp
```

To test if the solver is correctly installed, test the following command on the new environment:
Expand All @@ -26,16 +34,25 @@ conda activate corneto
python -c "import cvxpy; print(cvxpy.installed_solvers())"
```

The `CBC` solver should appear on the list.
The CBC solver should appear on the list. Please see the CVXPY documentation for more information on how to install other solvers https://www.cvxpy.org/install/. Depending on the solver and the platform, you will need to take different actions. For example, for using Gurobi, you will need to install the Gurobi solver with a valid license and then installing `gurobipy` dependency on the environment.

#### PICOS backend
If you want to use `PICOS` instead of `CVXPY` backend:

```bash
pip install PICOS
```

Check `PICOS` requirements for different solvers here: https://picos-api.gitlab.io/picos/introduction.html#features

### Complete setup

A recommended setup for testing and generating plots with corneto requires additional dependencies. A recommended environment is created with the following command:

```bash
conda create --name corneto python=3.8 matplotlib=3.5.1 networkx=2.7.1 pandas=1.4.3 jupyter=1.0.0 pydot=1.4.1 graphviz=2.50.0
conda create --name corneto python=3.8 cvxpy=1.2.1 cylp=0.91.5 matplotlib=3.5.1 networkx=2.7.1 pandas=1.4.3 jupyter=1.0.0 pydot=1.4.1 graphviz=2.50.0
conda activate corneto
pip install corneto-0.9.0a0-py3-none-any.whl
pip install corneto-0.9.0a3-py3-none-any.whl
```

Now the notebook included in the `tests` folder should be able to be run:
Expand All @@ -44,7 +61,3 @@ Now the notebook included in the `tests` folder should be able to be run:
cd corneto
jupyter nbconvert --execute --to html tests/notebooks/tutorial.ipynb
```

### Aditional solvers

Please see the CVXPY documentation for more information on how to install other solvers https://www.cvxpy.org/install/. Depending on the solver and the platform, you will need to take different actions. For example, for using Gurobi, you will need to install the Gurobi solver with a valid license and then installing `gurobipy` dependency on the environment.
2 changes: 1 addition & 1 deletion corneto/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from corneto._constants import *
from corneto.core import ReNet

__version__ = '0.9.0-alpha.2'
__version__ = '0.9.0-alpha.3'
12 changes: 8 additions & 4 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "corneto"
version = "0.9.0-alpha.2"
version = "0.9.0-alpha.3"
description = "CORNETO: CORe NETwork Optimizer, a MILP optimization library for Biochemical Networks"
authors = ["Pablo Rordriguez-Mier <[email protected]>"]
classifiers = [
Expand All @@ -19,7 +19,7 @@ include = ["LICENSE"]
[tool.poetry.dependencies]
python = ">=3.8 <3.11"
numpy = "^1.22.3"
cvxpy = "^1.2.1"
cvxpy = {version = "^1.2.1", optional = true}
cylp = {version = "^0.91.5", optional = true}
networkx = {version = "~2.7.1", optional = true}
PICOS = {version = "^2.4.1", optional = true}
Expand All @@ -37,8 +37,12 @@ mkdocs-material = "^7.2.1"
mkdocstrings = "^0.15.2"

[tool.poetry.extras]
cbc = ["cylp"]
extras = ["PICOS", "matplotlib", "networkx"]
cvxpy = ["cvxpy"]
picos = ["PICOS"]
all_backends = ["cvxpy", "PICOS"]
gurobi = ["gurobipy", "PICOS"]
cbc = ["cvxpy", "cylp"]
full = ["cvxpy", "PICOS", "matplotlib", "networkx"]

[build-system]
requires = ["poetry-core>=1.0.0"]
Expand Down

0 comments on commit c6b0797

Please sign in to comment.