Fail to apply MPO to an MPS

Hi ,when I’m trying to apply MPO to an MPS by using “apply”, the program would report MethodError. In order to locate the problem, I test it with a simple program but error too. My Itensor version is ITensors v0.2.16

using ITensors

sites = siteinds("S=1/2", 4)
psi0 = randomMPS(sites) 

ampo = AutoMPO()
for j=1:4
    add!(ampo, "Sz", j)
end

H = MPO(ampo, sites)

psi1 = apply(H, psi0)

Here’s the output

MethodError: no method matching product(::MPO, ::MPS) You may have intended to import Base.product Closest candidates are: product(!Matched::ITensors.LazyApply.Applied{typeof(prod),Tuple{Array{ITensor,1}}}, ::Any; kwargs...) at [/home/yuyihan/.julia/packages/ITensors/5sSxp/src/Ops/ops_itensor.jl:112]
product(!Matched::ITensor, ::ITensors.AbstractMPS) at [/home/yuyihan/.julia/packages/ITensors/5sSxp/src/mps/abstractmps.jl:1829]
product(!Matched::ITensor, ::ITensors.AbstractMPS, !Matched::Any; move_sites_back, apply_dag, kwargs...) at [/home/yuyihan/.julia/packages/ITensors/5sSxp/src/mps/abstractmps.jl:1829]
 ... Stacktrace: [1] top-level scope at [/home/yuyihan/itensor_HaveAtry/haveatry.ipynb:15]

I think it’s the problem of my environment. I change another computer with newer version of julia1.8.1 and ITensors v0.6.10 to run it and everything goes well. I’ll check it further, hope this helps you if you meet same trouble.

1 Like

Glad you found a solution. Please let us know if the problem persists.

Yeah, I was going to suggest upgrading to a new version of ITensors.jl.

A few other things:

  1. AutoMPO is deprecated in favor of OpSum.
  2. randomMPS is deprecated in favor of random_mps.
  3. You should start loading the package ITensorMPS if you are using MPS and MPO types and operations, such as siteinds, random_mps, OpSum, MPO, apply, etc…

Thanks for suggestions!
Wish you have a nice weekend.