Skip to content
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

[ITensors] Fix bugs in QN directsum and fermionic SVD #1178

Merged
merged 6 commits into from
Aug 12, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions src/tensor_operations/tensor_algebra.jl
Original file line number Diff line number Diff line change
Expand Up @@ -267,11 +267,11 @@ end
function directsum_itensors(i::Index, j::Index, ij::Index)
S1 = zeros(dim(i), dim(ij))
for ii in 1:dim(i)
S1[ii, ii] = 1
S1[ii, ii] = true
end
S2 = zeros(dim(j), dim(ij))
for jj in 1:dim(j)
S2[jj, dim(i) + jj] = 1
S2[jj, dim(i) + jj] = true
end
D1 = itensor(S1, dag(i), ij)
D2 = itensor(S2, dag(j), ij)
Expand Down Expand Up @@ -316,13 +316,17 @@ function _directsum(
(N != length(J)) &&
error("In directsum(::ITensor, ::ITensor, ...), must sum equal number of indices")
check_directsum_inds(A, I, B, J)
I = collect(I)
J = collect(J)
IJ = Vector{Base.promote_eltype(I, J)}(undef, N)
for n in 1:N
In = I[n]
Jn = J[n]
In = dir(A, In) != dir(In) ? dag(In) : In
Jn = dir(B, Jn) != dir(Jn) ? dag(Jn) : Jn
IJn = directsum(In, Jn; tags=tags[n])
I[n] = In
J[n] = Jn
IJ[n] = IJn
end
return _directsum(IJ, A, I, B, J)
Expand Down
15 changes: 9 additions & 6 deletions test/base/test_itensor.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1676,12 +1676,15 @@ end
@test allhastags(A, "x")
end

@testset "directsum" begin
x = Index(2, "x")
i1 = Index(3, "i1")
j1 = Index(4, "j1")
i2 = Index(5, "i2")
j2 = Index(6, "j2")
@testset "directsum" for space in (
identity,
d -> [QN(0) => d, QN(1) => d],
)
mtfishman marked this conversation as resolved.
Show resolved Hide resolved
x = Index(space(2), "x")
i1 = Index(space(3), "i1")
j1 = Index(space(4), "j1")
i2 = Index(space(5), "i2")
j2 = Index(space(6), "j2")

A1 = randomITensor(i1, x, j1)
A2 = randomITensor(x, j2, i2)
Expand Down
Loading