Skip to content

Commit c2e1dc0

Browse files
authored
Merge pull request #142 from hariszaf/new_docker
Codespace for tutorial based on Dockerfile
2 parents cd1617a + 303e57b commit c2e1dc0

25 files changed

Lines changed: 1579 additions & 671 deletions

.devcontainer/devcontainer.json

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
{
2+
"name": "Codespace for dingo tutorial",
3+
"build": {
4+
"dockerfile": "../Dockerfile",
5+
"context": ".."
6+
},
7+
"customizations": {
8+
"vscode": {
9+
"extensions": [
10+
"ms-python.python",
11+
"ms-toolsai.jupyter",
12+
"james-yu.latex-workshop"
13+
]
14+
}
15+
},
16+
"features": {},
17+
"postCreateCommand": "bash .devcontainer/post_create.sh"
18+
}

.devcontainer/post_create.sh

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
#!/bin/bash
2+
set -e # stop on any error
3+
4+
apt-get update
5+
apt-get install -y \
6+
libnss3 \
7+
libatk-bridge2.0-0 \
8+
libcups2 \
9+
libxcomposite1 \
10+
libxdamage1 \
11+
libxfixes3 \
12+
libxrandr2 \
13+
libgbm1 \
14+
libxkbcommon0 \
15+
libpango-1.0-0 \
16+
libcairo2 \
17+
libasound2
18+
19+
pip install --upgrade nbformat kaleido
20+
echo y | plotly_get_chrome

.gitignore

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,5 +11,4 @@ volestipy.egg-info
1111
.vscode
1212
venv
1313
lp_solve_5.5/
14-
.devcontainer/
1514
.github/dependabot.yml

Dockerfile

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
# Use the Gurobi Docker image as a base
2+
FROM gurobi/python
3+
4+
# Install any additional dependencies for dingo
5+
RUN apt-get update && apt-get install -y \
6+
cmake \
7+
lp-solve \
8+
git \
9+
wget \
10+
vim \
11+
bzip2 \
12+
g++ \
13+
&& rm -rf /var/lib/apt/lists/*
14+
15+
# Install dependencies
16+
RUN apt-get update && apt-get install -y libsuitesparse-dev
17+
RUN pip install sparseqr \
18+
Cython \
19+
cobra \
20+
kaleido
21+
22+
# Get PySQR
23+
RUN apt-get install libsuitesparse-dev
24+
25+
# Install Python dependencies
26+
RUN pip install matplotlib \
27+
plotly \
28+
networkx \
29+
pyoptinterface[highs]
30+
31+
# Get dingo
32+
WORKDIR /workspaces/dingo
33+
COPY . .
34+
35+
# Get submodules
36+
RUN git submodule update --init
37+
38+
# Get lp-solve
39+
RUN wget https://sourceforge.net/projects/lpsolve/files/lpsolve/5.5.2.11/lp_solve_5.5.2.11_source.tar.gz &&\
40+
tar xzvf lp_solve_5.5.2.11_source.tar.gz &&\
41+
rm lp_solve_5.5.2.11_source.tar.gz
42+
43+
# Get boost library
44+
RUN wget -O boost_1_76_0.tar.bz2 https://archives.boost.io/release/1.76.0/source/boost_1_76_0.tar.bz2 &&\
45+
tar xjf boost_1_76_0.tar.bz2 &&\
46+
rm boost_1_76_0.tar.bz2
47+
48+
# Set environmental variable gurobi license path
49+
ENV GRB_LICENSE_FILE=/opt/gurobi/gurobi.lic
50+
51+
# Install dingo
52+
RUN ["python", "setup.py", "install", "--user"]

README.md

Lines changed: 119 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -11,44 +11,80 @@ metabolic network, namely Flux Balance Analysis and Flux Variability Analysis.
1111

1212
`dingo` is part of [GeomScale](https://geomscale.github.io/) project.
1313

14-
[![unit-tests](https://github.com/GeomScale/dingo/workflows/dingo-ubuntu/badge.svg)](https://github.com/GeomScale/dingo/actions?query=workflow%3Adingo-ubuntu)
15-
[![Tutorial In Colab](https://colab.research.google.com/assets/colab-badge.svg)](https://colab.research.google.com/github/GeomScale/dingo/blob/develop/tutorials/dingo_tutorial.ipynb)
16-
[![Chat](https://badges.gitter.im/geomscale.png)](https://gitter.im/GeomScale/community?utm_source=share-link&utm_medium=link&utm_campaign=share-link)
14+
<a href="https://github.com/GeomScale/dingo/actions?query=workflow%3Adingo-ubuntu">
15+
<img src="https://github.com/GeomScale/dingo/workflows/dingo-ubuntu/badge.svg" height="20">
16+
</a>
17+
<a href="https://codespaces.new/GeomScale/dingo?quickstart=1">
18+
<img src="https://github.com/codespaces/badge.svg" height="20">
19+
</a>
20+
<a href="https://gitter.im/GeomScale/community?utm_source=share-link&utm_medium=link&utm_campaign=share-link">
21+
<img src="https://badges.gitter.im/geomscale.png" height="20">
22+
</a>
1723

1824

19-
## Installation
25+
## Installation
26+
27+
### LP solver (optional, probably better performance)
28+
29+
`dingo` makes use of [`pyoptinterface`](https://metab0t.github.io/PyOptInterface/) to interface with a range of linear programming solvers.
30+
31+
The default solver is [`highs`](https://highs.dev/#get-started).
32+
33+
However, one may switch to other solvers that `pyoptinterface` supports, for example the commonly used [`gurobi`](https://www.gurobi.com/).
34+
Yet, in that case a Gurobi license is required.
35+
36+
> **Get a Gurobi license**
37+
>
38+
> If you are affiliated in an academic insitute, you can generate a **free academic license**.
39+
>
40+
> First, register and/or login to your [Gurobi account](https://portal.gurobi.com/iam/login/), and
41+
>
42+
> * if you are about to use `dingo` as a container, get a [**Web License Service (WLS) academic license**](https://support.gurobi.com/hc/en-us/articles/13210193318033-What-is-an-Academic-WLS-license)
43+
> * otherwise, you should go for the typical [**free academic license**](https://www.gurobi.com/academics)
44+
>
45+
> 🔴 In both cases, make sure you are connected to the internet of an academic institution.
46+
47+
48+
### Installation (on Linux)
2049

2150
**Note:** Python version should be 3.8.x. You can check this by running the following command in your terminal:
2251
```bash
2352
python --version
2453
```
25-
If you have a different version of Python installed, you'll need to install it ([start here](https://linuxize.com/post/how-to-install-python-3-8-on-ubuntu-18-04/)) and update-alternatives ([start here](https://linuxhint.com/update_alternatives_ubuntu/))
2654

27-
**Note:** If you are using `GitHub Codespaces`. Start [here](https://docs.github.com/en/codespaces/setting-up-your-project-for-codespaces/adding-a-dev-container-configuration/setting-up-your-python-project-for-codespaces) to set the python version. Once your Python version is `3.8.x` you can start following the below instructions.
55+
If you have a different version of Python installed, you'll need to install it ([start here](https://linuxize.com/post/how-to-install-python-3-8-on-ubuntu-18-04/))
56+
and update-alternatives ([start here](https://linuxhint.com/update_alternatives_ubuntu/)).
57+
58+
Clone the `dingo` repo by
2859

60+
```
61+
git clone https://github.com/GeomScale/dingo.git
62+
```
2963

3064

31-
To load the submodules that dingo uses, run
65+
and load the submodules that `dingo` uses:
3266

3367
````bash
68+
cd dingo
3469
git submodule update --init
3570
````
3671

37-
You will need to download and unzip the Boost library:
72+
You will then need to download and unzip the [Boost C++](https://www.boost.org/) library:
3873
```
3974
wget -O boost_1_76_0.tar.bz2 https://archives.boost.io/release/1.76.0/source/boost_1_76_0.tar.bz2
4075
tar xjf boost_1_76_0.tar.bz2
4176
rm boost_1_76_0.tar.bz2
4277
```
4378

44-
You will also need to download and unzip the lpsolve library:
79+
You will also need to download and unzip the [`lpsolve`](https://lpsolve.sourceforge.net/5.5/) library:
4580
```
4681
wget https://sourceforge.net/projects/lpsolve/files/lpsolve/5.5.2.11/lp_solve_5.5.2.11_source.tar.gz
4782
tar xzvf lp_solve_5.5.2.11_source.tar.gz
4883
rm lp_solve_5.5.2.11_source.tar.gz
4984
```
5085

51-
Then, you need to install the dependencies for the PySPQR library; for Debian/Ubuntu Linux, run
86+
Then, you need to install the dependencies for the [PySPQR](https://github.com/yig/PySPQR) library;
87+
for this, you will most likely need `sudo` rights:
5288

5389
```bash
5490
sudo apt-get update -y
@@ -57,48 +93,97 @@ sudo apt-get install -y libsuitesparse-dev
5793

5894
To install the Python dependencies, `dingo` is using [Poetry](https://python-poetry.org/),
5995
```
60-
curl -sSL https://install.python-poetry.org | python3 - --version 1.3.2
96+
curl -sSL https://install.python-poetry.org | python - --version 1.3.2
6197
poetry shell
6298
poetry install
6399
```
64100

65-
You can install the [Gurobi solver](https://www.gurobi.com/) for faster linear programming optimization. Run
101+
otherwise, you may try:
102+
103+
```
104+
python setup.py install --user
105+
```
106+
107+
108+
Last, in case you are about to use Gurobi, remember to install the Python interface of Gurobi, [`gurobipy`](https://www.gurobi.com/resources/faq/gurobipy):
109+
110+
```
111+
pip install -i https://pypi.gurobi.com gurobipy
112+
```
113+
114+
115+
116+
## Using `dingo` as a Docker container
117+
118+
To use `dingo` as a container, you need to [install Docker](https://docs.docker.com/engine/install/),
119+
or [Docker desktop](https://docs.docker.com/desktop/), first.
120+
121+
Then you can clone the `dingo` repo and build its Docker image:
122+
123+
```
124+
git clone https://github.com/GeomScale/dingo.git
125+
cd dingo
126+
docker build -f Dockerfile -t dingo .
127+
```
128+
129+
Once the image is built, you may run:
66130

67131
```
68-
pip3 install -i https://pypi.gurobi.com gurobipy
132+
docker run --rm -it -v <path_to_your_model>:/data dingo
69133
```
70134

71-
Then, you will need a [license](https://www.gurobi.com/downloads/end-user-license-agreement-academic/). For more information, we refer to the Gurobi [download center](https://www.gurobi.com/downloads/).
135+
or, if you are using Gurobi, you may run:
136+
137+
```
138+
docker run --rm -it -v <path_to_WLS_license>:/opt/gurobi/gurobi.lic -v <path_to_your_model>:/data dingo
139+
```
72140

141+
> **Remember!** in this case, where `dingo` is run in a containerized environment and Gurobi is used as the solver, a standard node-locked Gurobi license would not work; a WLS license is typically required instead.
142+
>
143+
> This would look something like this:
144+
>
145+
> ```
146+
> # Gurobi WLS license file
147+
> # Your credentials are private and should not be shared or copied to public repositories.
148+
> # Visit https://license.gurobi.com/manager/doc/overview for more information.
149+
> WLSACCESSID=d5419c87-0d36-4a93-9385-773f5483b3c1
150+
> WLSSECRET=afa5d95f-ad0b-4a38-9550-a8913aacb7c0
151+
> LICENSEID=000000
152+
>```
73153
74154
75155
76156
## Unit tests
77157
78158
Now, you can run the unit tests by the following commands (with the default solver `highs`):
79159
```
80-
python3 tests/fba.py
81-
python3 tests/full_dimensional.py
82-
python3 tests/max_ball.py
83-
python3 tests/scaling.py
84-
python3 tests/rounding.py
85-
python3 tests/sampling.py
160+
python tests/fba.py
161+
python tests/full_dimensional.py
162+
python tests/max_ball.py
163+
python tests/scaling.py
164+
python tests/rounding.py
165+
python tests/sampling.py
86166
```
87167
88-
If you have installed Gurobi successfully, then run
168+
Or, assuming you have installed Gurobi successfully, or an other `pyoptinterface`-supported solver, you may run:
89169
```
90-
python3 tests/fba.py gurobi
91-
python3 tests/full_dimensional.py gurobi
92-
python3 tests/max_ball.py gurobi
93-
python3 tests/scaling.py gurobi
94-
python3 tests/rounding.py gurobi
95-
python3 tests/sampling.py gurobi
170+
python tests/fba.py gurobi
171+
python tests/full_dimensional.py gurobi
172+
python tests/max_ball.py gurobi
173+
python tests/scaling.py gurobi
174+
python tests/rounding.py gurobi
175+
python tests/sampling.py gurobi
96176
```
97177
98178
## Tutorial
99179
100-
You can have a look at our [Google Colab notebook](https://colab.research.google.com/github/GeomScale/dingo/blob/develop/tutorials/dingo_tutorial.ipynb)
101-
on how to use `dingo`.
180+
You may check out `dingo`'s main features through a GitHub codespace.
181+
To do this, you may click [here](https://github.com/codespaces/new?repo=GeomScale/dingo&ref=main) and fire a new codespace
182+
by clicking on the "Create codespace" button.
183+
184+
This will take a few minutes (~5').
185+
186+
Once the codespace is ready, you may try to follow the [`dingo_tutorial`](./tutorials/dingo_tutorial.ipynb) Jupyter notebook.
102187
103188
104189
## Documentation
@@ -191,14 +276,17 @@ The MCMC methods that dingo (through `volesti` library) provides are the followi
191276

192277
#### Switch the linear programming solver
193278

194-
We use `pyoptinterface` to interface with the linear programming solvers. To switch the solver that `dingo` uses, you can use the `set_default_solver` function. The default solver is `highs` and you can switch to `gurobi` by running,
279+
We use `pyoptinterface` to interface with the linear programming solvers.
280+
To switch the solver that `dingo` uses, you can use the `set_default_solver` function.
281+
The default solver is `highs` and you can switch to `gurobi` by running:
195282

196283
```python
197284
from dingo import set_default_solver
198285
set_default_solver("gurobi")
199286
```
200287

201-
You can also switch to other solvers that `pyoptinterface` supports, but we recommend using `highs` or `gurobi`. If you have issues with the solver, you can check the `pyoptinterface` [documentation](https://metab0t.github.io/PyOptInterface/getting_started.html).
288+
You can also switch to other solvers that `pyoptinterface` supports, but we recommend using `highs` or `gurobi`.
289+
If you have issues with the solver, you can check the `pyoptinterface` [documentation](https://metab0t.github.io/PyOptInterface/getting_started.html).
202290

203291
### Apply FBA and FVA methods
204292

dingo/illustrations.py

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
import plotly.figure_factory as ff
1515
from scipy.cluster import hierarchy
1616

17-
def plot_copula(data_flux1, data_flux2, n = 5, width = 900 , height = 600, export_format = "svg"):
17+
def plot_copula(data_flux1, data_flux2, n = 5, width = 900 , height = 600, save = True, export_format = "svg"):
1818
"""A Python function to plot the copula between two fluxes
1919
2020
Keyword arguments:
@@ -59,17 +59,21 @@ def plot_copula(data_flux1, data_flux2, n = 5, width = 900 , height = 600, expor
5959
)
6060

6161
fig.update_layout(scene_camera=camera)
62-
fig.to_image(format = export_format, engine="kaleido")
63-
pio.write_image(fig, fig_name, scale=2)
62+
63+
if save:
64+
fig.to_image(format = export_format, engine="kaleido")
65+
pio.write_image(fig, fig_name, scale=2)
6466

6567

66-
def plot_histogram(reaction_fluxes, reaction, n_bins=40):
68+
def plot_histogram(reaction_fluxes, reaction, n_bins = 40, save = False, export_format = "png"):
6769
"""A Python function to plot the histogram of a certain reaction flux.
6870
6971
Keyword arguments:
7072
reaction_fluxes -- a vector that contains sampled fluxes of a reaction
7173
reaction -- a string with the name of the reacion
7274
n_bins -- the number of bins for the histogram
75+
save -- save plot to a file
76+
export_format -- file format to save the plot
7377
"""
7478

7579
plt.figure(figsize=(7, 7))
@@ -84,10 +88,14 @@ def plot_histogram(reaction_fluxes, reaction, n_bins=40):
8488
plt.title("Reaction: " + reaction, fontweight="bold", fontsize=18)
8589
plt.axis([np.amin(reaction_fluxes), np.amax(reaction_fluxes), 0, np.amax(n) * 1.2])
8690

91+
if save:
92+
plt.savefig(reaction + "." + export_format, dpi = 150, bbox_inches = "tight", format = export_format)
93+
8794
plt.show()
8895

8996

9097

98+
9199
def plot_corr_matrix(corr_matrix, reactions, removed_reactions=[], format="svg"):
92100
"""A Python function to plot the heatmap of a model's pearson correlation matrix.
93101

doc/logo/geomscale.png

88.1 KB
Loading
112 KB
Binary file not shown.

0 commit comments

Comments
 (0)