Define the projection operators
using ITensors
function ITensors.op!(Op::ITensor,
::OpName"Pup",
::SiteType"S=1/2",
s::Index)
Op[s'=>1,s=>1] = 1.0
end
function ITensors.op!(Op::ITensor,
::OpName"Pdn",
::SiteType"S=1/2",
s::Index)
Op[s'=>2,s=>2] = 1.0
end
s = siteind("S=1/2")
Pup = op("Pup",s)
Pdn = op("Pdn",s)
Now if you apply the projection operators to psi with site that has expect(psi,“Sz”) that is not 0.5 or -0.5, it works as expected.
But if you apply Pdn to site with Sz=0.5, it gives psi with all entries NaN instead of flipping that spin to down.
For concrete example:
Consider
N = 100
s = siteinds("S=1/2",N)
psi_temp = MPS(s,"Up")
H1 = op("H",s[1])
psi1=apply(H1,psi_temp)
cnt12=op("CNOT", s[1:2]);
psi2=apply(cnt12,psi1);
Pup1 = op("Pup",s[1])
Pdn1 = op("Pdn",s[1])
Pup5 = op("Pup",s[5])
Pdn5 = op("Pdn",s[5])
Now,
expect(apply(Pup1,psi2),"Sz")
or expect(apply(Pdn1,psi2),"Sz")
gives correct result.
Also,
apply(Pup5,psi2)
gives correct result.
But
Pdn5 = op("Pdn",s[5])
or any site other than 1 and 2 where spins are up does not give correct result in the sense when I do psin=apply(Pdn5,psi2)
and expect(psin,"Sz")
, it returns an array with all entries Nan.
How do I fix this?