partial trace of MPO

Hi miles,
I want to ask more details from the question :https://itensor.discourse.group/t/trace-and-partial-trace-of-mpo/79

For instance, I have a MPO rho:

n = 6
s = siteinds("S=1/2",n)
rho = randomMPO(s)

I want to get another MPO M with partial trace:

I have tried code in above link but I do not know what I can get through them.
How can I get M?

1 Like

Hi cgh, here is the code for the tr of MPO function inside of ITensor:

function tr(M::MPO; plev::Pair{Int,Int}=0 => 1, tags::Pair=ts"" => ts"")
  N = length(M)
  L = tr(M[1]; plev=plev, tags=tags)
  for j in 2:N
    L *= M[j]
    L = tr(L; plev=plev, tags=tags)
  end
  return L
end

What you could do to adapt this to your case is the following:

  1. change the range in the for loop to only go from 1:2 or 1:NL where NL is the number of tensors you want to trace over on the left
  2. multiply L into the next tensor of the MPO, so the one at location NL+1
  3. define a new MPO of length (N-NL) and assign the MPO tensors from NL+1:N to it

Do you think that will work for your case?

Yeah. I change the function and it works well. Thank you so much.

1 Like