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

Support sparse matrices in cast methods #68

Merged
merged 15 commits into from
Mar 1, 2022
Merged

Support sparse matrices in cast methods #68

merged 15 commits into from
Mar 1, 2022

Conversation

stavros11
Copy link
Member

Required to enable qibo Hamiltonian creation using sparse matrices. Sparse matrices are supported for both numba (via scipy.sparse) and cupy/cuquantum (via cupy.sparse) platforms.

@stavros11 stavros11 requested a review from scarrazza February 3, 2022 12:59
@codecov
Copy link

codecov bot commented Feb 3, 2022

Codecov Report

Merging #68 (809eb1e) into main (8a1444c) will not change coverage.
The diff coverage is 100.00%.

Impacted file tree graph

@@            Coverage Diff            @@
##              main       #68   +/-   ##
=========================================
  Coverage   100.00%   100.00%           
=========================================
  Files            9         9           
  Lines         1022      1080   +58     
=========================================
+ Hits          1022      1080   +58     
Flag Coverage Δ
unittests 100.00% <100.00%> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

Impacted Files Coverage Δ
src/qibojit/custom_operators/__init__.py 100.00% <100.00%> (ø)
src/qibojit/custom_operators/platforms.py 100.00% <100.00%> (ø)
src/qibojit/tests/test_platforms.py 100.00% <100.00%> (ø)

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 8a1444c...809eb1e. Read the comment docs.

@stavros11
Copy link
Member Author

I extended the linear algebra methods for eigenvectors to work with sparse matrices, however it seems that these methods are a bit unstable, particularly for cupy. For example the following script:

from qibo import hamiltonians
from cupy import sparse
from cupy.sparse.linalg import eigsh

h = hamiltonians.TFIM(4, h=1.0)
m = sparse.coo_matrix(h.matrix)

for _ in range(10):
    eigvals, eigvecs = eigsh(m, 6)
    print(eigvals)

gives different values for the eigenvalues of the same matrix in each iteration. This makes testing a bit hard.

Copy link
Member

@scarrazza scarrazza left a comment

Choose a reason for hiding this comment

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

Thanks, looks good to me.

@scarrazza scarrazza merged commit 38fb97c into main Mar 1, 2022
@scarrazza scarrazza deleted the sparse branch August 17, 2022 07:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants