Skip to content

Commit 1797c80

Browse files
committed
Fix normalize!(::Canonical, ::AbstractMPO) when bond kwarg is set
1 parent 4176bcb commit 1797c80

File tree

1 file changed

+26
-3
lines changed

1 file changed

+26
-3
lines changed

src/MPS.jl

+26-3
Original file line numberDiff line numberDiff line change
@@ -730,9 +730,32 @@ end
730730
# this method just normalizes the Λ tensors
731731
function LinearAlgebra.normalize!(::Canonical, ψ::AbstractMPO; bond=nothing)
732732
if !isnothing(bond)
733-
# Λ = tensors(ψ; bond)
734-
# normalize!(Λ)
735-
error("Forced normalization of just one bond is not implemented yet")
733+
# when setting `bond`, we are just normalizing one Λ tensor and its neighbor Γ tensors
734+
Λab = tensors(ψ; bond)
735+
normalize!(Λ)
736+
737+
a, b = bond
738+
Γa, Γb = tensors(ψ; at=a), tensors(ψ; at=b)
739+
740+
# γ are Γ tensors with neighbor Λ tensors contracted => γ = Λ Γ Λ
741+
# i.e. it's half reduced density matrix for the site, so it's norm is the total norm too
742+
γa, γb = contract(Γa, Λab; dims=Symbol[]), contract(Γb, Λab; dims=Symbol[])
743+
744+
# open boundary conditions
745+
if a != lane"1"
746+
Λa = tensors(ψ; bond=(Lane(id(a - 1)), a))
747+
γa = contract(γa, Λa; dims=Symbol[])
748+
end
749+
750+
if b != Lane(nlanes(ψ))
751+
Λb = tensors(ψ; bond=(b, Lane(id(b + 1))))
752+
γb = contract(γb, Λb; dims=Symbol[])
753+
end
754+
755+
Za, Zb = norm(γa), norm(γb)
756+
757+
Γa ./= Za
758+
Γb ./= Zb
736759
end
737760

738761
# normalize the Λ tensors

0 commit comments

Comments
 (0)