From b5ebf57423a26234505841ea21a33976b91a5702 Mon Sep 17 00:00:00 2001 From: MrRobot2211 Date: Mon, 30 Aug 2021 13:02:17 -0300 Subject: [PATCH 1/6] add cupy ndarray creator --- src/qutip_cupy/__init__.py | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/src/qutip_cupy/__init__.py b/src/qutip_cupy/__init__.py index ccdce21..7ce9d19 100644 --- a/src/qutip_cupy/__init__.py +++ b/src/qutip_cupy/__init__.py @@ -6,7 +6,7 @@ import warnings try: - __import__("cupy") + import cupy as cp except ModuleNotFoundError: raise RuntimeError( "qutip_cupy requires cupy to be installed, please install cupy by following " @@ -36,14 +36,18 @@ (data.Dense, CuPyDense, cd.dense_from_cupydense), ] ) -data.to.register_aliases(["cupyd"], CuPyDense) +data.to.register_aliases(["cupyd", "CuPyDense"], CuPyDense) def is_cupydense(data): return isinstance(data, CuPyDense) -data.create.add_creators([(is_cupydense, CuPyDense, 80)]) +def is_cupy(data): + return isinstance(data, cp.ndarray) # noqa: F821 + + +data.create.add_creators([(is_cupydense, CuPyDense, 80), (is_cupy, CuPyDense, 81)]) data.adjoint.add_specialisations([(CuPyDense, CuPyDense, cd.adjoint_cupydense)]) @@ -92,5 +96,6 @@ def is_cupydense(data): # We must register the functions to the data layer but do not want # the data layer or qutip_cupy.dense to be accessible from qutip_cupy +del cp del data del cd From b9f34a0ce6c966b440ae47d006b68852d38498ed Mon Sep 17 00:00:00 2001 From: MrRobot2211 Date: Fri, 10 Sep 2021 19:11:55 -0300 Subject: [PATCH 2/6] Drop is_cupydense creator --- src/qutip_cupy/__init__.py | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/src/qutip_cupy/__init__.py b/src/qutip_cupy/__init__.py index 7ce9d19..0414974 100644 --- a/src/qutip_cupy/__init__.py +++ b/src/qutip_cupy/__init__.py @@ -39,15 +39,11 @@ data.to.register_aliases(["cupyd", "CuPyDense"], CuPyDense) -def is_cupydense(data): - return isinstance(data, CuPyDense) - - def is_cupy(data): return isinstance(data, cp.ndarray) # noqa: F821 -data.create.add_creators([(is_cupydense, CuPyDense, 80), (is_cupy, CuPyDense, 81)]) +data.create.add_creators([(is_cupy, CuPyDense, 80)]) data.adjoint.add_specialisations([(CuPyDense, CuPyDense, cd.adjoint_cupydense)]) From 8c305d6f6f55c8f1377fc1550aa4feee36fd559c Mon Sep 17 00:00:00 2001 From: MrRobot2211 Date: Wed, 27 Oct 2021 01:50:41 -0300 Subject: [PATCH 3/6] fix tests --- tests/test_dense.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/tests/test_dense.py b/tests/test_dense.py index 1f30f90..bc1a2d1 100644 --- a/tests/test_dense.py +++ b/tests/test_dense.py @@ -71,7 +71,7 @@ def test_true_div(shape): cup_arr = CuPyDense(array) cpdense_over_2 = cup_arr / 2.0 - qtpdense_over_2 = data.Dense(array) / 2.0 + qtpdense_over_2 = data.Dense(array).__truediv__(2.0) np.testing.assert_array_equal(cpdense_over_2.to_array(), qtpdense_over_2.to_array()) @@ -81,7 +81,7 @@ def test_itrue_div(shape): array = np.random.uniform(size=shape) + 1.0j * np.random.uniform(size=shape) cpd_array = CuPyDense(array) - cpd_array /= 2 + cpd_array.__itruediv__(2.0) qtpdense = data.Dense(array / 2) np.testing.assert_array_equal(cpd_array.to_array(), qtpdense.to_array()) @@ -92,7 +92,7 @@ def test_mul(shape): array = np.random.uniform(size=shape) + 1.0j * np.random.uniform(size=shape) cpdense_mul = CuPyDense(array) * (2.0 + 1.0j) - qtpdense_mul = data.Dense(array) * (2.0 + 1.0j) + qtpdense_mul = data.Dense(array).__mul__(2.0 + 1.0j) np.testing.assert_array_equal(cpdense_mul.to_array(), qtpdense_mul.to_array()) From 6cf37613a425b4d22339d702aeea00fd02e0a06e Mon Sep 17 00:00:00 2001 From: MrRobot2211 Date: Wed, 27 Oct 2021 01:51:00 -0300 Subject: [PATCH 4/6] adds cupy import in is_cupy --- src/qutip_cupy/__init__.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/qutip_cupy/__init__.py b/src/qutip_cupy/__init__.py index 0414974..a6cc17a 100644 --- a/src/qutip_cupy/__init__.py +++ b/src/qutip_cupy/__init__.py @@ -40,6 +40,8 @@ def is_cupy(data): + import cupy as cp + return isinstance(data, cp.ndarray) # noqa: F821 From 93d127daea9645cbbff778f88758f1cb79d5fbde Mon Sep 17 00:00:00 2001 From: MrRobot2211 Date: Thu, 20 Jan 2022 14:28:52 -0300 Subject: [PATCH 5/6] removed extra noqa --- src/qutip_cupy/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/qutip_cupy/__init__.py b/src/qutip_cupy/__init__.py index a6cc17a..c035b31 100644 --- a/src/qutip_cupy/__init__.py +++ b/src/qutip_cupy/__init__.py @@ -42,7 +42,7 @@ def is_cupy(data): import cupy as cp - return isinstance(data, cp.ndarray) # noqa: F821 + return isinstance(data, cp.ndarray) data.create.add_creators([(is_cupy, CuPyDense, 80)]) From 783a4f47a587ee4cc65afb1a5ac73f6ec3294179 Mon Sep 17 00:00:00 2001 From: MrRobot2211 Date: Thu, 20 Jan 2022 16:10:53 -0300 Subject: [PATCH 6/6] pinning qutip version for tests to pass --- .github/workflows/docs-gpu.yml | 4 +++- .github/workflows/tests-gpu.yml | 14 +++++++------- 2 files changed, 10 insertions(+), 8 deletions(-) diff --git a/.github/workflows/docs-gpu.yml b/.github/workflows/docs-gpu.yml index f2ebe3b..8124fff 100644 --- a/.github/workflows/docs-gpu.yml +++ b/.github/workflows/docs-gpu.yml @@ -39,8 +39,10 @@ jobs: python -mpip install -r doc/requirements.txt - name: Install QuTiP from GitHub + # temporally pinning qutip version + # should be restored to dev.major run: | - python -mpip install git+https://github.com/qutip/qutip.git@dev.major + python -mpip install git+https://github.com/qutip/qutip.git@c6d68c04a02c4fbeed14e0e07d44ab6021d53c8d python -c 'import qutip; qutip.about()' - name: Install qutip-cupy from GitHub diff --git a/.github/workflows/tests-gpu.yml b/.github/workflows/tests-gpu.yml index dbd2485..6eacdd6 100644 --- a/.github/workflows/tests-gpu.yml +++ b/.github/workflows/tests-gpu.yml @@ -24,7 +24,6 @@ defaults: # things much simpler. shell: bash -l {0} - jobs: validate: runs-on: ubuntu-latest @@ -37,8 +36,11 @@ jobs: python-version: "3.8" miniconda-version: "latest" - name: Install QuTiP from GitHub + # temporally pinning qutip version + # should be restored to dev.major run: | - python -mpip install git+https://github.com/qutip/qutip.git@dev.major + python -mpip install git+https://github.com/qutip/qutip.git@c6d68c04a02c4fbeed14e0e07d44ab6021d53c8d + - name: Install cupy and dependencies run: | conda install cudatoolkit=10.1 @@ -54,7 +56,6 @@ jobs: run: | black --check --diff doc src tests setup.py - cases: name: ${{ matrix.os }}, ${{ matrix.case-name }} needs: validate @@ -86,9 +87,9 @@ jobs: # Install in editable mode so Coveralls detects the tree structure # relative to the git repository root as well. run: | - conda install -c conda-forge cupy - python -mpip install -e .[full] - python -mpip install pytest-cov coveralls + conda install -c conda-forge cupy + python -mpip install -e .[full] + python -mpip install pytest-cov coveralls - name: Package information run: | @@ -123,7 +124,6 @@ jobs: COVERALLS_PARALLEL: true run: coveralls --service=github - finalise: name: Finalise coverage reporting needs: cases