Skip to content

Add optional install options with pip #627

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 11 commits into from
Jun 21, 2024
Merged
2 changes: 1 addition & 1 deletion .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ jobs:
command: |
python -m pip install --user --upgrade --progress-bar off pip
python -m pip install --user -e .
python -m pip install --user --upgrade --no-cache-dir --progress-bar off -r requirements.txt
python -m pip install --user --upgrade --no-cache-dir --progress-bar off -r requirements_all.txt
python -m pip install --user --upgrade --progress-bar off -r docs/requirements.txt
python -m pip install --user --upgrade --progress-bar off ipython sphinx-gallery memory_profiler
# python -m pip install --user --upgrade --progress-bar off ipython "https://api.github.com/repos/sphinx-gallery/sphinx-gallery/zipball/master" memory_profiler
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/build_doc.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ jobs:
- name: Get Python running
run: |
python -m pip install --user --upgrade --progress-bar off pip
python -m pip install --user --upgrade --progress-bar off -r requirements.txt
python -m pip install --user --upgrade --progress-bar off -r requirements_all.txt
python -m pip install --user --upgrade --progress-bar off -r docs/requirements.txt
python -m pip install --user --upgrade --progress-bar off ipython "https://api.github.com/repos/sphinx-gallery/sphinx-gallery/zipball/master" memory_profiler
python -m pip install --user -e .
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/build_tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ jobs:
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install -r requirements.txt
pip install -r requirements_all.txt
pip install pytest pytest-cov
- name: Run tests
run: |
Expand Down Expand Up @@ -108,7 +108,7 @@ jobs:
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install -r requirements.txt
pip install -r requirements_all.txt
pip install pytest
- name: Run tests
run: |
Expand Down
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,12 @@ or get the very latest version by running:
pip install -U https://github.com/PythonOT/POT/archive/master.zip # with --user for user install (no root)
```

Optional dependencies may be installed with
```console
pip install POT[all]
```
Note that this installs `cvxopt`, which is licensed under GPL 3.0. Alternatively, if you cannot use GPL-licensed software, the specific optional dependencies may be installed individually, or per-submodule. The available optional installations are `backend-jax, backend-tf, backend-torch, cvxopt, dr, gnn, all`.

#### Anaconda installation with conda-forge

If you use the Anaconda python distribution, POT is available in [conda-forge](https://conda-forge.org). To install it and the required dependencies:
Expand Down
1 change: 1 addition & 0 deletions RELEASES.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
+ New general unbalanced solvers for `ot.solve` and BFGS solver and illustrative example (PR #620)
+ Add gradient computation with envelope theorem to sinkhorn solver of `ot.solve` with `grad='envelope'` (PR #605).
+ Added support for [Low rank Gromov-Wasserstein](https://proceedings.mlr.press/v162/scetbon22b/scetbon22b.pdf) with `ot.gromov.lowrank_gromov_wasserstein_samples` (PR #614)
+ Optional dependencies may now be installed with `pip install POT[all]` The specific backends or submodules' dependencies may also be installed individually. The pip options are: `backend-jax, backend-tf, backend-torch, cvxopt, dr, gnn, all`. The installation of the `cupy` backend should be done with conda.

#### Closed issues
- Fix gpu compatibility of sr(F)GW solvers when `G0 is not None`(PR #596)
Expand Down
6 changes: 4 additions & 2 deletions ot/da.py
Original file line number Diff line number Diff line change
Expand Up @@ -376,8 +376,10 @@
elif sim == 'knn':
if sim_param is None:
sim_param = 3

from sklearn.neighbors import kneighbors_graph
try:
from sklearn.neighbors import kneighbors_graph
except ImportError:
raise ValueError('scikit-learn must be installed to use knn similarity. Install with `$pip install scikit-learn`.')

Check warning on line 382 in ot/da.py

View check run for this annotation

Codecov / codecov/patch

ot/da.py#L381-L382

Added lines #L381 - L382 were not covered by tests

sS = nx.from_numpy(kneighbors_graph(
X=nx.to_numpy(xs), n_neighbors=int(sim_param)
Expand Down
15 changes: 9 additions & 6 deletions ot/dr.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,15 @@
# License: MIT License

from scipy import linalg
import autograd.numpy as np
from sklearn.decomposition import PCA

import pymanopt
import pymanopt.manifolds
import pymanopt.optimizers
try:
import autograd.numpy as np
from sklearn.decomposition import PCA

import pymanopt
import pymanopt.manifolds
import pymanopt.optimizers
except ImportError:
raise ImportError("Missing dependency for ot.dr. Requires autograd, pymanopt, scikit-learn. You can install with install with 'pip install POT[dr]', or 'conda install autograd pymanopt scikit-learn'")

from .bregman import sinkhorn as sinkhorn_bregman
from .utils import dist as dist_utils, check_random_state
Expand Down
File renamed without changes.
14 changes: 14 additions & 0 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,9 @@
sdk_path = subprocess.check_output(['xcrun', '--show-sdk-path'])
os.environ['CFLAGS'] = '-isysroot "{}"'.format(sdk_path.rstrip().decode("utf-8"))

with open('requirements_all.txt') as f:
optional_requirements = f.read().splitlines()

Check warning on line 50 in setup.py

View check run for this annotation

Codecov / codecov/patch

setup.py#L49-L50

Added lines #L49 - L50 were not covered by tests

setup(
name='POT',
version=__version__,
Expand All @@ -70,6 +73,17 @@
scripts=[],
data_files=[],
install_requires=["numpy>=1.16", "scipy>=1.6"],
extras_require={
'backend-numpy': [], # in requirements.
'backend-jax': ['jax<=0.4.24', 'jaxlib<=0.4.24'],
'backend-cupy': [], # should be installed with conda, not pip, or figure out what CUDA version above.
'backend-tf': ['tensorflow'],
'backend-torch': ['torch'],
'cvxopt': ['cvxopt'], # on it's own to prevent accidental GPL violations
'dr': ['scikit-learn', 'pymanopt', 'autograd'],
'gnn': ['torch', 'torch_geometric'],
'all': optional_requirements
},
python_requires=">=3.7",
classifiers=[
'Development Status :: 5 - Production/Stable',
Expand Down
Loading