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

Implement Chain normalization by mixed canonization #28

Merged
merged 11 commits into from
Mar 14, 2024
12 changes: 12 additions & 0 deletions src/Ansatz/Chain.jl
Original file line number Diff line number Diff line change
Expand Up @@ -406,6 +406,18 @@ function mixed_canonize!(::Open, tn::Chain, center::Site) # TODO: center could b
return tn
end

"""
LinearAlgebra.normalize!(tn::Chain, center::Site)

Normalizes the input [`Chain`](@ref) tensor network by transforming it
to mixed-canonized form with the given center site.
"""
function LinearAlgebra.normalize!(tn::Chain, root::Site; p::Real=2)
mixed_canonize!(tn, root)
normalize!(select(Quantum(tn), :tensor, root), p)
return tn
end

"""
evolve!(qtn::Chain, gate)

Expand Down
11 changes: 11 additions & 0 deletions test/Ansatz/Chain_test.jl
Original file line number Diff line number Diff line change
Expand Up @@ -208,5 +208,16 @@
end
end

@testset "normalize" begin
odd_qtn = Chain(State(), Open(), [rand(4, 4), rand(4, 4, 4), rand(4, 4, 4), rand(4, 4, 4), rand(4, 4)])
even_qtn = Chain(State(), Open(), [rand(4, 4), rand(4, 4, 4), rand(4, 4, 4), rand(4, 4, 4), rand(4, 4, 4), rand(4, 4)])
Todorbsc marked this conversation as resolved.
Show resolved Hide resolved
qtns = [odd_qtn, even_qtn]
roots = [Site(3), Site(2)]
for (qtn, root) in zip(qtns, roots)
normalize!(qtn, root)
@test isapprox(norm(qtn), 1.0)
end
end

# TODO test `evolve!` methods
end
Loading