ITensor / NDTensors.jl

A Julia package for n-dimensional sparse tensors.
Apache License 2.0
27 stars 7 forks source link

Drop zero blocks during uncombining #55

Open mtfishman opened 3 years ago

mtfishman commented 3 years ago

Uncombining can "generate" nonzero blocks:

using ITensors

i = Index(QN(0,2)=>2,QN(1,2)=>2; tags="i")
j = settags(i,"j")
A = emptyITensor(i,j,dag(i'))
A[1,1,1] = 1.0 
C = combiner(i, j; tags="c")
AC = A * C
Ap = AC * dag(C)

@show A
@show Ap

gives:

A = ITensor ord=3
Dim 1: (dim=4|id=251|"i") <Out>
 1: QN(0,2) => 2
 2: QN(1,2) => 2
Dim 2: (dim=4|id=251|"j") <Out>
 1: QN(0,2) => 2
 2: QN(1,2) => 2
Dim 3: (dim=4|id=251|"i")' <In>
 1: QN(0,2) => 2
 2: QN(1,2) => 2
NDTensors.BlockSparse{Float64,Array{Float64,1},3}
 4×4×4
Block: Block{3}((0x0000000000000001, 0x0000000000000001, 0x0000000000000001), 0x8324cf5639de3e67)
 [1:2, 1:2, 1:2]
[:, :, 1] =
 1.0  0.0
 0.0  0.0

[:, :, 2] =
 0.0  0.0
 0.0  0.0

Ap = ITensor ord=3
Dim 1: (dim=4|id=251|"i") <Out>
 1: QN(0,2) => 2
 2: QN(1,2) => 2
Dim 2: (dim=4|id=251|"j") <Out>
 1: QN(0,2) => 2
 2: QN(1,2) => 2
Dim 3: (dim=4|id=251|"i")' <In>
 1: QN(0,2) => 2
 2: QN(1,2) => 2
NDTensors.BlockSparse{Float64,Array{Float64,1},3}
 4×4×4
Block: Block{3}((0x0000000000000001, 0x0000000000000001, 0x0000000000000001), 0x8324cf5639de3e67)
 [1:2, 1:2, 1:2]
[:, :, 1] =
 1.0  0.0
 0.0  0.0

[:, :, 2] =
 0.0  0.0
 0.0  0.0

Block: Block{3}((0x0000000000000002, 0x0000000000000002, 0x0000000000000001), 0x8681cd10e233a627)
 [3:4, 3:4, 1:2]
[:, :, 1] =
 0.0  0.0
 0.0  0.0

[:, :, 2] =
 0.0  0.0
 0.0  0.0

We could check for zero blocks here and drop them. However, checking every block for zeros may not be a cost we want to impose every time an uncombiner is used.

Since it is inconvenient to pass tolerances to contract, we could be very strict with the tolerance there, and then provide a dropzeros[!] function for NDTensors and ITensors.