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
14 changes: 14 additions & 0 deletions src/Ansatz/Chain.jl
Original file line number Diff line number Diff line change
Expand Up @@ -406,6 +406,20 @@ function mixed_canonize!(::Open, tn::Chain, center::Site) # TODO: center could b
return tn
end

"""
normalize_by_mixed_canonization(tn::Chain)

Normalizes the input [`Chain`](@ref) tensor network by transforming it
to a mixed-canonized form.
"""
function normalize_by_mixed_canonization(tn::Chain)
centersite = Site(((Quantum(tn) |> nsites) + 1) ÷ 2)
canonized = mixed_canonize(tn, centersite)
normalize!(select(Quantum(canonized), :tensor, centersite))

return canonized
end

Todorbsc marked this conversation as resolved.
Show resolved Hide resolved
"""
evolve!(qtn::Chain, gate)

Expand Down
2 changes: 1 addition & 1 deletion src/Qrochet.jl
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ export Chain
export MPS, pMPS, MPO, pMPO
export leftindex, rightindex, isleftcanonical, isrightcanonical
export canonize_site, canonize_site!, truncate!
export canonize, canonize!, mixed_canonize, mixed_canonize!
export canonize, canonize!, mixed_canonize, mixed_canonize!, normalize_by_mixed_canonization
export observe

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

@testset "Normalization" begin
Todorbsc marked this conversation as resolved.
Show resolved Hide resolved
@testset "normalize_by_mixed_canonization" 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)])
qtns = [odd_qtn, even_qtn]
for qtn in qtns
norm_canonized = normalize_by_mixed_canonization(qtn)

@test isapprox(norm(norm_canonized), 1.0)
end
end
end

# TODO test `evolve!` methods
end
Loading