Can someone point out what mistake am I doing in the below code snippet to construct a 3-site reduced density matrix (RDM) ? This method, taken from another post in this forum long time ago, works correctly when it’s a 2-site RDM that I’ve been using in several problems but not when it’s a 3-site (or 4-site) RDM… I am using this within a TEBD evolution, and noticed that the sum of RDM eigvals is > 1 and number of eigvals is \neq 2^3 (after a few time steps, if not immediately so)… I’ve printed the indices, and played around with the prime function, but haven’t succeeded in finding the issue. Perhaps it’s something silly, but let me know what’s gone wrong here.
function RDM3(ψ,A,B,C)
psi1 = deepcopy(ψ)
orthogonalize!(psi1,A)
# 3-site RDM construction for subsystem = {A} U {B} U {C}.
# A, B, C denote the sites.
psi1dag=prime(dag(psi1),linkinds(psi1))
rho_ABC = prime(psi1[A],linkinds(psi1,A-1))*prime(psi1dag[A],s[A])
for i=A+1:B-1
rho_ABC *= psi1[i]
rho_ABC *= psi1dag[i]
end
rho_ABC *= prime(psi1[B],linkinds(psi1,B))*prime(psi1dag[B],s[B])
for i=B+1:C-1
rho_ABC *= psi1[i]
rho_ABC *= psi1dag[i]
end
rho_ABC *= prime(psi1[C],linkinds(psi1,C))*prime(psi1dag[C],s[C])
DABC,UABC=eigen(rho_ABC)
@show length(diag(DABC))
cc = 0
for i=1:length(diag(DABC))
cc += real(diag(DABC))[i]
end
@show cc
return DABC
end