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

Rename backend.issparse as backend.is_sparse #185

Merged
merged 2 commits into from
Aug 2, 2024
Merged
Show file tree
Hide file tree
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
10 changes: 5 additions & 5 deletions src/qibojit/backends/gpu.py
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ def to_numpy(self, x):
return x.toarray()
return np.array(x, copy=False)

def issparse(self, x):
def is_sparse(self, x):
return self.sparse.issparse(x) or self.npsparse.issparse(x)

def zero_state(self, nqubits):
Expand Down Expand Up @@ -474,7 +474,7 @@ def calculate_expectation_density_matrix(self, matrix, state, normalize):
return ev

def calculate_eigenvalues(self, matrix, k=6):
if self.issparse(matrix):
if self.is_sparse(matrix):
log.warning(
"Calculating sparse matrix eigenvectors because "
"sparse modules do not provide ``eigvals`` method."
Expand All @@ -483,7 +483,7 @@ def calculate_eigenvalues(self, matrix, k=6):
return self.cp.linalg.eigvalsh(matrix)

def calculate_eigenvectors(self, matrix, k=6):
if self.issparse(matrix):
if self.is_sparse(matrix):
if k < matrix.shape[0]:
# Fallback to numpy because cupy's ``sparse.eigh`` does not support 'SA'
from scipy.sparse.linalg import eigsh # pylint: disable=import-error
Expand All @@ -499,8 +499,8 @@ def calculate_eigenvectors(self, matrix, k=6):
return self.cp.linalg.eigh(matrix)

def calculate_matrix_exp(self, a, matrix, eigenvectors=None, eigenvalues=None):
if eigenvectors is None or self.issparse(matrix):
if self.issparse(matrix):
if eigenvectors is None or self.is_sparse(matrix):
if self.is_sparse(matrix):
from scipy.sparse.linalg import expm

return self.cast(expm(-1j * a * matrix.get()))
Expand Down
4 changes: 2 additions & 2 deletions src/qibojit/tests/test_backends.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,13 +35,13 @@ def test_sparse_cast(backend, array_type, format):
from scipy import sparse

sptarget = sparse.rand(512, 512, dtype=array_type, format=format)
assert backend.issparse(sptarget)
assert backend.is_sparse(sptarget)
final = backend.to_numpy(backend.cast(sptarget))
target = sptarget.toarray()
backend.assert_allclose(final, target)
if backend.platform != "numba": # pragma: no cover
sptarget = getattr(backend.sparse, sptarget.__class__.__name__)(sptarget)
assert backend.issparse(sptarget)
assert backend.is_sparse(sptarget)
final = backend.to_numpy(backend.cast(sptarget))
backend.assert_allclose(final, target)

Expand Down
Loading