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:
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
multiply L into the next tensor of the MPO, so the one at location NL+1
define a new MPO of length (N-NL) and assign the MPO tensors from NL+1:N to it