Yeah I figured that was the way to go. Here is what I have been trying most of the day.
function initial(N, index)
ampo = OpSum()
for j=1:N
if j<= Int(0.5*N)
ampo += 1, "Sz", j
elseif j > Int(0.5*N)
ampo += -1, "Sz",j
end
end
return MPO(ampo, index)
end
This defines an MPO that is a sum of Sz on each site with a weight. Now suppose I want to find the commutator of this mpo with a single-site operator.
N = 2;
s = siteinds("S=1/2", N)
rho0 = initial(N, s)
O = op("Sz", s[1])
Suppose, now we want to take find the commutator on the first site.
rho = copy(rho0)
newrho = dag(prime(rho, "Site"))
newO = dag(prime(O, "Site"))
Orho = newO * rho[1]
norime!(Orho)
rho[1] = Orho
rhoO = newrho[1] * O
noprime!(rhoO)
newrho[1] = rhoO
comm = norm(rho - newrho,2)
But this still doesn't work correctly. Hmmm