summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRĂ©mi Flamary <remi.flamary@gmail.com>2023-05-05 13:53:16 +0200
committerGitHub <noreply@github.com>2023-05-05 13:53:16 +0200
commit5693a88bc3a8c36f8ac4fdacc419ff2574d1b7bb (patch)
treec959d95b66563a7b28e3155d52674c186f17bd5e
parent7e0ea27ad9cad31cfc2181430d837c0a77a61568 (diff)
[MRG] Add github action test cuda (#473)
* add workflow cuda * try with conda * try again conda * and now? * proper python version * cleanup * try to use proper python * again? * cleanup stuff and use python3.10 * remove dr test * remove docstrng tetss for stoc methods * add condition for cuda tests * remove unused files * upate release file * debug workflow
-rw-r--r--.github/workflows/build_tests_cuda.yml25
-rw-r--r--RELEASES.md2
-rw-r--r--ot/stochastic.py194
3 files changed, 27 insertions, 194 deletions
diff --git a/.github/workflows/build_tests_cuda.yml b/.github/workflows/build_tests_cuda.yml
new file mode 100644
index 0000000..f1c2962
--- /dev/null
+++ b/.github/workflows/build_tests_cuda.yml
@@ -0,0 +1,25 @@
+name: Tests CUDA
+
+on:
+ workflow_dispatch:
+ pull_request_review:
+ types: [submitted]
+ push:
+ branches:
+ - 'master' # Set a branch to run CI tests on
+
+jobs:
+ linux-cuda:
+
+ runs-on: pc-cuda
+ if: github.event.review.state == 'approved' || github.event_name == 'workflow_dispatch' || (github.event_name == 'push' && github.event.branch == 'master')
+
+ steps:
+ - uses: actions/checkout@v1
+ - name: Install POT
+ run: |
+ python3.10 -m pip install --ignore-installed -e .
+ - name: Run tests
+ run: |
+ python3.10 -m pytest --durations=20 -v test/ ot/ --doctest-modules --color=yes --ignore=test/test_dr.py --ignore=ot.dr --ignore=ot.plot
+
diff --git a/RELEASES.md b/RELEASES.md
index f393883..02fddad 100644
--- a/RELEASES.md
+++ b/RELEASES.md
@@ -5,6 +5,8 @@
#### New features
- Make alpha parameter in Fused Gromov Wasserstein differentiable (PR #463)
- Added the sparsity-constrained OT solver to `ot.smooth` and added ` projection_sparse_simplex` to `ot.utils` (PR #459)
+- Add tests on GPU for master branch and approved PR (PR #473)
+
#### Closed issues
- Fix circleci-redirector action and codecov (PR #460)
diff --git a/ot/stochastic.py b/ot/stochastic.py
index 61be9bb..319d006 100644
--- a/ot/stochastic.py
+++ b/ot/stochastic.py
@@ -58,27 +58,6 @@ def coordinate_grad_semi_dual(b, M, reg, beta, i):
-------
coordinate gradient : ndarray, shape (nt,)
- Examples
- --------
- >>> import ot
- >>> np.random.seed(0)
- >>> n_source = 7
- >>> n_target = 4
- >>> a = ot.utils.unif(n_source)
- >>> b = ot.utils.unif(n_target)
- >>> X_source = np.random.randn(n_source, 2)
- >>> Y_target = np.random.randn(n_target, 2)
- >>> M = ot.dist(X_source, Y_target)
- >>> ot.stochastic.solve_semi_dual_entropic(a, b, M, reg=1, method="ASGD", numItermax=300000)
- array([[2.53942342e-02, 9.98640673e-02, 1.75945647e-02, 4.27664307e-06],
- [1.21556999e-01, 1.26350515e-02, 1.30491795e-03, 7.36017394e-03],
- [3.54070702e-03, 7.63581358e-02, 6.29581672e-02, 1.32812798e-07],
- [2.60578198e-02, 3.35916645e-02, 8.28023223e-02, 4.05336238e-04],
- [9.86808864e-03, 7.59774324e-04, 1.08702729e-02, 1.21359007e-01],
- [2.17218856e-02, 9.12931802e-04, 1.87962526e-03, 1.18342700e-01],
- [4.14237512e-02, 2.67487857e-02, 7.23016955e-02, 2.38291052e-03]])
-
-
.. _references-coordinate-grad-semi-dual:
References
----------
@@ -137,27 +116,6 @@ def sag_entropic_transport(a, b, M, reg, numItermax=10000, lr=None):
v : ndarray, shape (`nt`,)
Dual variable.
- Examples
- --------
- >>> import ot
- >>> np.random.seed(0)
- >>> n_source = 7
- >>> n_target = 4
- >>> a = ot.utils.unif(n_source)
- >>> b = ot.utils.unif(n_target)
- >>> X_source = np.random.randn(n_source, 2)
- >>> Y_target = np.random.randn(n_target, 2)
- >>> M = ot.dist(X_source, Y_target)
- >>> ot.stochastic.solve_semi_dual_entropic(a, b, M, reg=1, method="ASGD", numItermax=300000)
- array([[2.53942342e-02, 9.98640673e-02, 1.75945647e-02, 4.27664307e-06],
- [1.21556999e-01, 1.26350515e-02, 1.30491795e-03, 7.36017394e-03],
- [3.54070702e-03, 7.63581358e-02, 6.29581672e-02, 1.32812798e-07],
- [2.60578198e-02, 3.35916645e-02, 8.28023223e-02, 4.05336238e-04],
- [9.86808864e-03, 7.59774324e-04, 1.08702729e-02, 1.21359007e-01],
- [2.17218856e-02, 9.12931802e-04, 1.87962526e-03, 1.18342700e-01],
- [4.14237512e-02, 2.67487857e-02, 7.23016955e-02, 2.38291052e-03]])
-
-
.. _references-sag-entropic-transport:
References
----------
@@ -225,27 +183,6 @@ def averaged_sgd_entropic_transport(a, b, M, reg, numItermax=300000, lr=None):
ave_v : ndarray, shape (`nt`,)
dual variable
- Examples
- --------
- >>> import ot
- >>> np.random.seed(0)
- >>> n_source = 7
- >>> n_target = 4
- >>> a = ot.utils.unif(n_source)
- >>> b = ot.utils.unif(n_target)
- >>> X_source = np.random.randn(n_source, 2)
- >>> Y_target = np.random.randn(n_target, 2)
- >>> M = ot.dist(X_source, Y_target)
- >>> ot.stochastic.solve_semi_dual_entropic(a, b, M, reg=1, method="ASGD", numItermax=300000)
- array([[2.53942342e-02, 9.98640673e-02, 1.75945647e-02, 4.27664307e-06],
- [1.21556999e-01, 1.26350515e-02, 1.30491795e-03, 7.36017394e-03],
- [3.54070702e-03, 7.63581358e-02, 6.29581672e-02, 1.32812798e-07],
- [2.60578198e-02, 3.35916645e-02, 8.28023223e-02, 4.05336238e-04],
- [9.86808864e-03, 7.59774324e-04, 1.08702729e-02, 1.21359007e-01],
- [2.17218856e-02, 9.12931802e-04, 1.87962526e-03, 1.18342700e-01],
- [4.14237512e-02, 2.67487857e-02, 7.23016955e-02, 2.38291052e-03]])
-
-
.. _references-averaged-sgd-entropic-transport:
References
----------
@@ -304,27 +241,6 @@ def c_transform_entropic(b, M, reg, beta):
u : ndarray, shape (`ns`,)
Dual variable.
- Examples
- --------
- >>> import ot
- >>> np.random.seed(0)
- >>> n_source = 7
- >>> n_target = 4
- >>> a = ot.utils.unif(n_source)
- >>> b = ot.utils.unif(n_target)
- >>> X_source = np.random.randn(n_source, 2)
- >>> Y_target = np.random.randn(n_target, 2)
- >>> M = ot.dist(X_source, Y_target)
- >>> ot.stochastic.solve_semi_dual_entropic(a, b, M, reg=1, method="ASGD", numItermax=300000)
- array([[2.53942342e-02, 9.98640673e-02, 1.75945647e-02, 4.27664307e-06],
- [1.21556999e-01, 1.26350515e-02, 1.30491795e-03, 7.36017394e-03],
- [3.54070702e-03, 7.63581358e-02, 6.29581672e-02, 1.32812798e-07],
- [2.60578198e-02, 3.35916645e-02, 8.28023223e-02, 4.05336238e-04],
- [9.86808864e-03, 7.59774324e-04, 1.08702729e-02, 1.21359007e-01],
- [2.17218856e-02, 9.12931802e-04, 1.87962526e-03, 1.18342700e-01],
- [4.14237512e-02, 2.67487857e-02, 7.23016955e-02, 2.38291052e-03]])
-
-
.. _references-c-transform-entropic:
References
----------
@@ -399,27 +315,6 @@ def solve_semi_dual_entropic(a, b, M, reg, method, numItermax=10000, lr=None,
log : dict
log dictionary return only if log==True in parameters
- Examples
- --------
- >>> import ot
- >>> np.random.seed(0)
- >>> n_source = 7
- >>> n_target = 4
- >>> a = ot.utils.unif(n_source)
- >>> b = ot.utils.unif(n_target)
- >>> X_source = np.random.randn(n_source, 2)
- >>> Y_target = np.random.randn(n_target, 2)
- >>> M = ot.dist(X_source, Y_target)
- >>> ot.stochastic.solve_semi_dual_entropic(a, b, M, reg=1, method="ASGD", numItermax=300000)
- array([[2.53942342e-02, 9.98640673e-02, 1.75945647e-02, 4.27664307e-06],
- [1.21556999e-01, 1.26350515e-02, 1.30491795e-03, 7.36017394e-03],
- [3.54070702e-03, 7.63581358e-02, 6.29581672e-02, 1.32812798e-07],
- [2.60578198e-02, 3.35916645e-02, 8.28023223e-02, 4.05336238e-04],
- [9.86808864e-03, 7.59774324e-04, 1.08702729e-02, 1.21359007e-01],
- [2.17218856e-02, 9.12931802e-04, 1.87962526e-03, 1.18342700e-01],
- [4.14237512e-02, 2.67487857e-02, 7.23016955e-02, 2.38291052e-03]])
-
-
.. _references-solve-semi-dual-entropic:
References
----------
@@ -509,33 +404,6 @@ def batch_grad_dual(a, b, M, reg, alpha, beta, batch_size, batch_alpha,
grad : ndarray, shape (`ns`,)
partial grad F
- Examples
- --------
- >>> import ot
- >>> np.random.seed(0)
- >>> n_source = 7
- >>> n_target = 4
- >>> a = ot.utils.unif(n_source)
- >>> b = ot.utils.unif(n_target)
- >>> X_source = np.random.randn(n_source, 2)
- >>> Y_target = np.random.randn(n_target, 2)
- >>> M = ot.dist(X_source, Y_target)
- >>> sgd_dual_pi, log = ot.stochastic.solve_dual_entropic(a, b, M, reg=1, batch_size=3, numItermax=30000, lr=0.1, log=True)
- >>> log['alpha']
- array([0.71759102, 1.57057384, 0.85576566, 0.1208211 , 0.59190466,
- 1.197148 , 0.17805133])
- >>> log['beta']
- array([0.49741367, 0.57478564, 1.40075528, 2.75890102])
- >>> sgd_dual_pi
- array([[2.09730063e-02, 8.38169324e-02, 7.50365455e-03, 8.72731415e-09],
- [5.58432437e-03, 5.89881299e-04, 3.09558411e-05, 8.35469849e-07],
- [3.26489515e-03, 7.15536035e-02, 2.99778211e-02, 3.02601593e-10],
- [4.05390622e-02, 5.31085068e-02, 6.65191787e-02, 1.55812785e-06],
- [7.82299812e-02, 6.12099102e-03, 4.44989098e-02, 2.37719187e-03],
- [5.06266486e-02, 2.16230494e-03, 2.26215141e-03, 6.81514609e-04],
- [6.06713990e-02, 3.98139808e-02, 5.46829338e-02, 8.62371424e-06]])
-
-
.. _references-batch-grad-dual:
References
----------
@@ -600,37 +468,6 @@ def sgd_entropic_regularization(a, b, M, reg, batch_size, numItermax, lr):
beta : ndarray, shape (nt,)
dual variable
- Examples
- --------
- >>> import ot
- >>> n_source = 7
- >>> n_target = 4
- >>> reg = 1
- >>> numItermax = 20000
- >>> lr = 0.1
- >>> batch_size = 3
- >>> log = True
- >>> a = ot.utils.unif(n_source)
- >>> b = ot.utils.unif(n_target)
- >>> rng = np.random.RandomState(0)
- >>> X_source = rng.randn(n_source, 2)
- >>> Y_target = rng.randn(n_target, 2)
- >>> M = ot.dist(X_source, Y_target)
- >>> sgd_dual_pi, log = ot.stochastic.solve_dual_entropic(a, b, M, reg, batch_size, numItermax, lr, log)
- >>> log['alpha']
- array([0.64171798, 1.27932201, 0.78132257, 0.15638935, 0.54888354,
- 1.03663469, 0.20595781])
- >>> log['beta']
- array([0.51207194, 0.58033189, 1.28922676, 2.26859736])
- >>> sgd_dual_pi
- array([[1.97276541e-02, 7.81248547e-02, 6.22136048e-03, 4.95442423e-09],
- [4.23494310e-03, 4.43286263e-04, 2.06927079e-05, 3.82389139e-07],
- [3.07542414e-03, 6.67897769e-02, 2.48904999e-02, 1.72030247e-10],
- [4.26271990e-02, 5.53375455e-02, 6.16535024e-02, 9.88812650e-07],
- [7.60423265e-02, 5.89585256e-03, 3.81267087e-02, 1.39458256e-03],
- [4.37557504e-02, 1.85189176e-03, 1.72335760e-03, 3.55491279e-04],
- [6.33096109e-02, 4.11683954e-02, 5.02962051e-02, 5.43097516e-06]])
-
References
----------
.. [19] Seguy, V., Bhushan Damodaran, B., Flamary, R., Courty, N., Rolet, A.& Blondel, M. Large-scale Optimal Transport and Mapping Estimation. International Conference on Learning Representation (2018)
@@ -702,37 +539,6 @@ def solve_dual_entropic(a, b, M, reg, batch_size, numItermax=10000, lr=1,
log : dict
log dictionary return only if log==True in parameters
- Examples
- --------
- >>> import ot
- >>> n_source = 7
- >>> n_target = 4
- >>> reg = 1
- >>> numItermax = 20000
- >>> lr = 0.1
- >>> batch_size = 3
- >>> log = True
- >>> a = ot.utils.unif(n_source)
- >>> b = ot.utils.unif(n_target)
- >>> rng = np.random.RandomState(0)
- >>> X_source = rng.randn(n_source, 2)
- >>> Y_target = rng.randn(n_target, 2)
- >>> M = ot.dist(X_source, Y_target)
- >>> sgd_dual_pi, log = ot.stochastic.solve_dual_entropic(a, b, M, reg, batch_size, numItermax, lr, log)
- >>> log['alpha']
- array([0.64057733, 1.2683513 , 0.75610161, 0.16024284, 0.54926534,
- 1.0514201 , 0.19958936])
- >>> log['beta']
- array([0.51372571, 0.58843489, 1.27993921, 2.24344807])
- >>> sgd_dual_pi
- array([[1.97377795e-02, 7.86706853e-02, 6.15682001e-03, 4.82586997e-09],
- [4.19566963e-03, 4.42016865e-04, 2.02777272e-05, 3.68823708e-07],
- [3.00379244e-03, 6.56562018e-02, 2.40462171e-02, 1.63579656e-10],
- [4.28626062e-02, 5.60031599e-02, 6.13193826e-02, 9.67977735e-07],
- [7.61972739e-02, 5.94609051e-03, 3.77886693e-02, 1.36046648e-03],
- [4.44810042e-02, 1.89476742e-03, 1.73285847e-03, 3.51826036e-04],
- [6.30118293e-02, 4.12398660e-02, 4.95148998e-02, 5.26247246e-06]])
-
References
----------
.. [19] Seguy, V., Bhushan Damodaran, B., Flamary, R., Courty, N., Rolet, A.& Blondel, M. Large-scale Optimal Transport and Mapping Estimation. International Conference on Learning Representation (2018)