Skip to content
This repository has been archived by the owner on Jul 7, 2024. It is now read-only.

Fix mixed_canonize function #49

Merged
merged 5 commits into from
Jun 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
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
7 changes: 5 additions & 2 deletions src/Ansatz/Chain.jl
Original file line number Diff line number Diff line change
Expand Up @@ -500,7 +500,7 @@ mixed_canonize!(tn::Chain, args...; kwargs...) = mixed_canonize!(boundary(tn), t
mixed_canonize!(boundary::Boundary, tn::Chain, center::Site)

Transform a `Chain` tensor network into the mixed-canonical form, that is,
for i < center the tensors are left-canonical and for i > center the tensors are right-canonical,
for i < center the tensors are left-canonical and for i >= center the tensors are right-canonical,
and in the center there is a matrix with singular values.
"""
function mixed_canonize!(::Open, tn::Chain, center::Site) # TODO: center could be a range of sites
Expand All @@ -514,6 +514,9 @@ function mixed_canonize!(::Open, tn::Chain, center::Site) # TODO: center could b
canonize_site!(tn, Site(i); direction = :left, method = :qr)
end

# center SVD sweep to get singular values
canonize_site!(tn, center; direction = :left, method = :svd)

return tn
end

Expand All @@ -525,7 +528,7 @@ to mixed-canonized form with the given center site.
"""
function LinearAlgebra.normalize!(tn::Chain, root::Site; p::Real = 2)
mixed_canonize!(tn, root)
normalize!(tensors(Quantum(tn); at = root), p)
normalize!(tensors(tn; between = (Site(id(root) - 1), root)), p)
return tn
end

Expand Down
4 changes: 3 additions & 1 deletion test/Ansatz/Chain_test.jl
Original file line number Diff line number Diff line change
Expand Up @@ -359,9 +359,11 @@
qtn = Chain(State(), Open(), [rand(4, 4), rand(4, 4, 4), rand(4, 4, 4), rand(4, 4, 4), rand(4, 4)])
canonized = mixed_canonize(qtn, Site(3))

@test length(tensors(canonized)) == length(tensors(qtn)) + 1

@test isleftcanonical(canonized, Site(1))
@test isleftcanonical(canonized, Site(2))
@test !isleftcanonical(canonized, Site(3)) && !isrightcanonical(canonized, Site(3))
@test isrightcanonical(canonized, Site(3))
@test isrightcanonical(canonized, Site(4))
@test isrightcanonical(canonized, Site(5))

Expand Down
Loading