Skip to content

Conversation

lkdvos
Copy link
Contributor

@lkdvos lkdvos commented Aug 27, 2025

This PR adds support both for using TensorOperations backends within TensorAlgebra methods (i.e. TensorAlgebra.contract(StridedBLAS(), args...), as well as TensorAlgebra backends within TensorOperations (TensorOperations.tensorcontract!(args..., Matricize())).

The end result is that we can now use TensorOperations' machinery to chain together contractions, or simplify the interface when NamedDimArrays or ITensor isn't loaded.
For example, here is a twosite dmrg contraction:

using TensorOperations: @tensor
using TensorAlgebra: Matricize

D1, D2, D3 = 30, 40, 20
d1, d2 = 2, 3
A1 = rand(T, D1, d1, D2) .- 1//2
A2 = rand(T, D2, d2, D3) .- 1//2
rhoL = rand(T, D1, D1) .- 1//2
rhoR = rand(T, D3, D3) .- 1//2
H = rand(T, d1, d2, d1, d2) .- 1//2

@tensor HrA12[a, s1, s2, c] :=
    rhoL[a, a'] * A1[a', t1, b] * A2[b, t2, c'] * rhoR[c', c] * H[s1, s2, t1, t2]
@tensor backend = Matricize() HrA12′[a, s1, s2, c] :=
    rhoL[a, a'] * A1[a', t1, b] * A2[b, t2, c'] * rhoR[c', c] * H[s1, s2, t1, t2]

One interesting thing here is that, similar to #75 , there is not enough information to correctly construct the bipermutation of the output.

Additionally, since this goes both ways I also simplified some of the tests that were verifying results are consistent with TensorOperations, which can now be used through the same interface.

Copy link

codecov bot commented Aug 27, 2025

Codecov Report

❌ Patch coverage is 47.05882% with 18 lines in your changes missing coverage. Please review.
✅ Project coverage is 91.16%. Comparing base (981f5c0) to head (6c9650d).
⚠️ Report is 1 commits behind head on main.

Files with missing lines Patch % Lines
ext/TensorAlgebraTensorOperationsExt.jl 47.05% 18 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main      #78      +/-   ##
==========================================
- Coverage   94.39%   91.16%   -3.24%     
==========================================
  Files          14       15       +1     
  Lines         464      498      +34     
==========================================
+ Hits          438      454      +16     
- Misses         26       44      +18     
Flag Coverage Δ
docs 0.00% <0.00%> (ø)

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
Copy link
Member

Looks good, thanks @lkdvos. Maybe we should hold off on merging this until #75 is merged since I think the convention for the destination permutation in contract is changing in that PR.

@lkdvos
Copy link
Contributor Author

lkdvos commented Sep 2, 2025

Sounds great, I think the new convention is actually even easier to support so that should be good here

@lkdvos lkdvos force-pushed the ld-tensoroperations branch from fa81eca to 95bcd6b Compare September 3, 2025 13:36
@lkdvos lkdvos requested a review from mtfishman September 3, 2025 13:37
@mtfishman mtfishman merged commit 0a2af0c into main Sep 3, 2025
13 of 15 checks passed
@mtfishman mtfishman deleted the ld-tensoroperations branch September 3, 2025 16:30
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