Hi Matt and Mile,

I am trying to write a piece of code to compute the inner product of two MPS. Both of these MPS are for a 1-D lattice (I mean they have all parameters in common) except the number of their sites; the first one has N sites and the other one N+1 sites.

Now my main question is how can I compute the inner product between these two MPS.

I tried inner() operator but (as I expected) I got an error:

(DimensionMismatch(“inner: mismatched lengths 10 and 11”)

Thanks.

Hi,

Just as an idea to deal with this problem, may I add an extra unentangled site to the shorter lattice’s MPS, and then compute the inner product ?

If it’s possible, how could I add an extra unentangled site to a MPS?

Thanks

You should be able to just write a loop contracting the tensors of the two MPS, for example:

```
using ITensors
function partial_inner(psi1, psi2)
n1 = length(psi1)
n2 = length(psi2)
@assert n1 < n2
o = ITensor(1.0)
for j in 1:n2
if j <= n1
o = o * dag(psi1[j]) * psi2[j]
else
o = o * psi2[j]
end
end
return o
end
n = 4
s = siteinds("S=1/2", n + 1)
psi1 = randomMPS(s[1:n]; linkdims=3)
psi2 = randomMPS(s; linkdims=3)
o = partial_inner(psi1, psi2)
```

Cheers,

Matt

2 Likes

Hi Matt,

That’s really cool, so interesting code!

I’m new in ITensor and I didn’t know we can write some if/else or for loop codes for our ITensor objects.

Thank you for taking time to code my problem.

1 Like