Skip to content
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

creates cupydense in the data layer to be available as a Qobj #41

Open
wants to merge 7 commits into
base: main
Choose a base branch
from
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 8 additions & 3 deletions src/qutip_cupy/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 "
Expand Down Expand Up @@ -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
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is the noqa really needed now that we import cupy as cp at the top?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The thing is that as the import is inside a try it fails to detect it

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you double check?

When I do:

$ cat  foo.py
try:
    import math
except ImportError:
    raise


def f():
    print(math.pi)
$ flake8 foo.py

It doesn't print an error and in the code in this PR it doesn't print an error for del cp either.



data.create.add_creators([(is_cupydense, CuPyDense, 80), (is_cupy, CuPyDense, 81)])
hodgestar marked this conversation as resolved.
Show resolved Hide resolved


data.adjoint.add_specialisations([(CuPyDense, CuPyDense, cd.adjoint_cupydense)])
Expand Down Expand Up @@ -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