ITensors.jl
ITensors.jl copied to clipboard
[NDTensors] [BUG] `DiagBlockSparse * DiagBlockSparse` contraction broken
Description of bug
julia> s = [QN(0) => 1, QN(1) => 1];
julia> i, j, k = Index.((s, s, s));
julia> t1 = δ(i, dag(j));
julia> t2 = δ(j, dag(k));
julia> t1 * t2
ERROR: UndefVarError: IndsR not defined
Stacktrace:
[1] contraction_output_type(TensorT1::Type{NDTensors.DiagBlockSparseTensor{Float64, 2, Tuple{Index{Vector{Pair{QN, Int64}}}, Index{Vector{Pair{QN, Int64}}}}, NDTensors.DiagBlockSparse{Float64, Float64, 2}}}, TensorT2::Type{NDTensors.DiagBlockSparseTensor{Float64, 2, Tuple{Index{Vector{Pair{QN, Int64}}}, Index{Vector{Pair{QN, Int64}}}}, NDTensors.DiagBlockSparse{Float64, Float64, 2}}}, indsR::Tuple{Index{Vector{Pair{QN, Int64}}}, Index{Vector{Pair{QN, Int64}}}})
@ NDTensors ~/.julia/dev/ITensors/NDTensors/src/blocksparse/diagblocksparse.jl:278
[...]
This is with NDTensors v0.1.49 and is a regression caused by #1051, which means that this operation wasn't be tested properly (and should be tested in NDTensors). @kmp5VT I can look into this one.
This is a bit more involved then I expected, and ultimately would be made much easier by making BlockSparse and DiagBlockSparse more generic by sharing more code. I think we should be able to combine them into a single parametrized type, parametrized by the storage type of the blocks. So I'll leave this one open, for now people can use:
julia> @show denseblocks(t1) * denseblocks(t2);
denseblocks(t1) * denseblocks(t2) = ITensor ord=2
Dim 1: (dim=2|id=584) <Out>
1: QN(0) => 1
2: QN(1) => 1
Dim 2: (dim=2|id=9) <In>
1: QN(0) => 1
2: QN(1) => 1
NDTensors.BlockSparse{Float64, Vector{Float64}, 2}
2×2
Block(1, 1)
[1:1, 1:1]
1.0
Block(2, 2)
[2:2, 2:2]
1.0