Skip to content

Catch more cases of sparse matmul involving adjoints #60

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

Merged
merged 2 commits into from
Jun 6, 2025

Conversation

mtfishman
Copy link
Member

@mtfishman mtfishman commented Jun 6, 2025

This is a bit hacky, but it fixes ITensor/BlockSparseArrays.jl#24.

It was caused by a subtle confluence of issues:

  1. blocks(A)' where A is a BlockSparseMatrix isn't a subtype of AnyAbstractSparseArray, since the element type of the Adjoint wrapper is the Adjoint of the element type of blocks(a), i.e. the type is something like Adjoint{Adjoint{Float64,Matrix{Float64}},SparseMatrixDOK{Matrix{Float64}}}. That's true of adjoints of matrices of matrices in general, so is a limitation of the AnyAbstractSparseArray union type, which is based on the Adapt.WrappedArray wrapper union.
  2. AnyAbstractSparseArray is used to catch objects that act as sparse arrays to give them a sparse array memory layout and interface, so they get forwarded to sparse implementations of matrix multiplication. Because of 1., that wasn't happening for adjoints of sparse matrices of matrices.

This is a hacky solution to catch a few cases that are missed by the current design, but ideally we would have a more systematic fix. One would be to make AnyAbstractSparseArray more general so that it doesn't have that type constraint between the wrapper element type and parent element type, since that's probably an issue for other wrapper types as well. Refactors like ITensor/DerivableInterfaces.jl#28 and #39 would also help make it easier to catch and fix this kind of issue since it was a bit tough to hunt down, since some of these definitions are implicitly derived using DerivableInterfaces.jl.

Copy link

codecov bot commented Jun 6, 2025

Codecov Report

Attention: Patch coverage is 80.00000% with 2 lines in your changes missing coverage. Please review.

Project coverage is 76.03%. Comparing base (5e42270) to head (1d24cff).
Report is 1 commits behind head on main.

Files with missing lines Patch % Lines
src/abstractsparsearray.jl 80.00% 2 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main      #60      +/-   ##
==========================================
+ Coverage   75.96%   76.03%   +0.06%     
==========================================
  Files           8        8              
  Lines         570      580      +10     
==========================================
+ Hits          433      441       +8     
- Misses        137      139       +2     
Flag Coverage Δ
docs 34.60% <40.00%> (+0.09%) ⬆️

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

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@mtfishman mtfishman merged commit dfe4fd8 into main Jun 6, 2025
16 checks passed
@mtfishman mtfishman deleted the mf/mul_adjoint branch June 6, 2025 21:19
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.

[BUG] Matrix multiplication with lazy transpose/adjoint fills all blocks
1 participant