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

Commit

Permalink
Fix mixed_canonize function (#49)
Browse files Browse the repository at this point in the history
* Add missing svd step in mixed_canonize! function

* Update and enhance tests for mixed_canonize function

* update docstring

* Fix normalize! function

* Format code
  • Loading branch information
jofrevalles authored Jun 20, 2024
1 parent 837642c commit fa0d561
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 3 deletions.
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

0 comments on commit fa0d561

Please sign in to comment.