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

Dia data layer #2196

Merged
merged 46 commits into from Aug 3, 2023
Merged

Dia data layer #2196

merged 46 commits into from Aug 3, 2023

Conversation

Ericgig
Copy link
Member

@Ericgig Ericgig commented Jul 14, 2023

Description
New sparse type: Dia.
Optimal for diagonal operators such as qeye, destroy. But it's quite bad for vectors ('bra', 'ket').

For a tri-diagonal matrix, it's about 25% faster than CSR for oper @ dense.
It can do an very efficient dense @ dia, while CSR is only efficient csr @ dense, not the opposite.

This include most specializations, change the default in operators, add tests.

The implementation mostly match the one in scipy.
The matrices are stored in two arrays, the diagonals offsets shape=num_offsets and the data shape=[num_offsets, ncols]. The diagonals are lined so that for each entry, the column in the data array match the matrix column.
The main differences with scipy's implementation are fixed dtype and the shape of the data array being fixed. (scipy accept longer diagonals and ignore entries outside the matrix.)

@Ericgig Ericgig marked this pull request as draft July 14, 2023 15:06
@coveralls
Copy link

coveralls commented Jul 19, 2023

Coverage Status

coverage: 84.68% (+1.5%) from 83.199% when pulling 6e00623 on Ericgig:feature.diag into 4f29ae5 on qutip:master.

@Ericgig
Copy link
Member Author

Ericgig commented Jul 20, 2023

Here are some timing:
Operators are all 100x100

Sparse matrices composed of one diagonal:

C Fortran
dia @ dense 14.2 µs 14.7 µs
dense @ dia 14.2 µs 12.8 µs
csr @ dense 49.8 µs 33.3 µs
dense @ csr 165 µs 113 µs

Here for matrices with 5 diagonals:

C Fortran
dia @ dense 67 µs 63 µs
dense @ dia 60 µs 55 µs
csr @ dense 236 µs 85 µs
dense @ csr 270 µs 218 µs

@Ericgig Ericgig marked this pull request as ready for review July 20, 2023 20:58
Copy link
Contributor

@hodgestar hodgestar left a comment

Choose a reason for hiding this comment

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

I didn't do a thorough review, but we have lots of tests for the data layer and I can see you extended them to the new dia layer.

Happy for this to be merged.

Should we add it to the QuTiP benchmarking suite?

qutip/core/_brtools.pyx Outdated Show resolved Hide resolved
Co-authored-by: Simon Cross <hodgestar+github@gmail.com>
@Ericgig
Copy link
Member Author

Ericgig commented Aug 2, 2023

Yes, let's add it to the benchmarks.

@Ericgig Ericgig merged commit 5fa0ca6 into qutip:master Aug 3, 2023
12 checks passed
@Ericgig Ericgig deleted the feature.diag branch August 3, 2023 15:48
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.

None yet

3 participants