ITensors.jl icon indicating copy to clipboard operation
ITensors.jl copied to clipboard

[ITensors] [ENHANCEMENT] In-place contraction with symmetric tensors

Open ArtemStrashko opened this issue 2 years ago • 1 comments

Is your feature request related to a problem? Please describe.

While in-place contraction A .= B .* C is implemented for dense tensors, it seems to be missing for symmetric tensors. Using code from a manual as an example, we can construct

using ITensors
i = Index([QN(0) => 2, QN(1) => 3], "i")
j = Index([QN(0) => 2, QN(1) => 3], "j")
A = randomITensor(i, dag(j))
C = combiner(i, dag(j); tags = "c", dir = dir(i))
A * C # works
D = A * C # works
D .= A .* C # does not work
D = randomITensor(inds(A*C))
D .= A .* C # does not work
D .+= A .* C # does not work either

Here is an error I get in my use case: MethodError: no method matching contract!(::NDTensors.BlockSparseTensor{Float64, 2, Tuple{Index{Vector{Pair{QN, Int64}}}, Index{Vector{Pair{QN, Int64}}}}, NDTensors.BlockSparse{Float64, Vector{Float64}, 2}}, ::Tuple{Int64, Int64}, ::NDTensors.BlockSparseTensor{Float64, 2, Tuple{Index{Vector{Pair{QN, Int64}}}, Index{Vector{Pair{QN, Int64}}}}, NDTensors.BlockSparse{Float64, Vector{Float64}, 2}}, ::Tuple{Int64, Int64}, ::NDTensors.BlockSparseTensor{Float64, 2, Tuple{Index{Vector{Pair{QN, Int64}}}, Index{Vector{Pair{QN, Int64}}}}, NDTensors.BlockSparse{Float64, Vector{Float64}, 2}}, ::Tuple{Int64, Int64})

Describe the solution you'd like

Support of in-place contractions A .= B .* C and A .+= B .* C for symmetric (block--sparse) tensors.

ArtemStrashko avatar Jul 24 '23 16:07 ArtemStrashko

Thanks for the report @ArtemStrashko. We'll look into it. We are in the process of rewriting and simplifying a lot of the NDTensors library so it's good to keep track of issues like this to make sure we fix them during that process.

mtfishman avatar Jul 24 '23 17:07 mtfishman