For an MPO representing the density matrix of an QN-preserving MPS, I would like to trace out some of the indices to be left with the reduced density matrix.
It was not obvious how to do this in the MPO’s native form, however I can get around this by first transforming the QN MPS to a dense MPS then proceeding. Below shows a simple example of this for a 3 qubit MPS where the first qubit is traced out.
However, doing this I obviously lose the computational benefit of working with QN MPS (commenting out the line ‘psi = dense(psi)’ gives an error about the indices requiring opposite directions to contract).
Is it possible to do this partial trace without first transforming to a dense MPS?
n = 3
sites = siteinds("Qubit", n; conserve_number=true)
state = [i<=2 ? "Dn" : "Up" for i=1:n]
psi = randomMPS(sites, state, linkdims=2)
psi = dense(psi)
sites_dense = siteinds(psi)
rho = outer(psi', psi)
rho[1] = rho[1]*delta(sites_dense[1],sites_dense[1]')
rho[2] *= rho[1]
rho_out = MPO(2)
for i in 1:2
rho_out[i] = rho[i+1]
end
T = ITensor(1.)
for j=1:length(rho_out)
T *= rho_out[j]
end
A = Array(T, sites_dense[2]', sites_dense[3]', sites_dense[2], sites_dense[3])
A = reshape(A, 4, 4)
display(A)
;