# Bug in MPOs with products of operators? (Julia version)

+1 vote
edited

Hi,

I have codes in which I perform DMRG and then compute < S^2 >.
Before I updated ITensor to the latest version, these codes were giving correct results and now they are not. I know that the previous results were correct because I benchmarked with simple models for which I can do exact diagonalization.

One simple example that may help to identify this apparent bug is the following:

Model: DMRG for S=1 antiferromagnetic Heisenberg dimer.
The groundstate should be a singlet.
I compute < Sz > and I get 0. That's good.
I compute < S^2 > and I get different than 0. That's not right.

I defined the S^2 operator as follows:

function S2_op(Nsites,sites)
ampo = AutoMPO()

for i in 1:Nsites
for j in 1:Nsites
ampo += 1.,"S+",i,"S-",j
ampo += 1.,"Sz",i,"Sz",j
end
ampo += -1.,"Sz",i
end

S2 = MPO(ampo,sites)

return S2
end


I also tried to define it in a different manner: (EDIT: this is wrong)

function S2_op_other(Nsites,sites)
ampo = AutoMPO()

for i in 1:Nsites
ampo += 1.,"S+*S-",i
ampo += 1.,"Sz*Sz",i
ampo += -1.,"Sz",i
end

S2 = MPO(ampo,sites)

return S2
end


Both cases give values that are not 0. Also, they give different results, which I think is also telling. In the first case, I get 2/3. In the second case, I get 4. None of these numbers makes any physical sense.

The exact same thing happened when I tried to create an MPO of the Sz^2 operator and compute its average.

Best,
Gonçalo Catarina

commented by (44k points)
Thanks - yes I see then & it's a good way to write it.

When you say that you get "different from zero" for <S^2>, how different? I wouldn't be surprised at all if it's not numerically exactly zero. But how large is it?
commented by (260 points)
I get <S^2> = 2/3.
I also get <Sz^2> = 2/3.
You can check this out by copying the code I sent above and run it in the latest version of ITensor Julia.

In previous versions, I was obtaining values very close to 0.

If it helps, in the comments above we seem to have understood that the occurrence of this discrepancy happened in some update between June 9 and June 19.
commented by (44k points)
That does help - thanks for pointing that out again about the results changing for (apparently) the same ground state MPS. You know, I did make a pretty significant change to the AutoMPO code around that very time (it was on June 12) so it could very much be related to what you're observing. I'll look into it - I'm filing an issue right now so it doesn't get overlooked.
commented by (44k points)
Just to let you know, there's definitely a bug in AutoMPO that's responsible for part of what you're seeing. I'm working on it and will let you know when that's done.
commented by (260 points)
Thanks for the update!