# Fail to apply MPO to an MPS

**URL:** <https://itensor.discourse.group/t/fail-to-apply-mpo-to-an-mps/1730>\
**Category:** ITensor Julia Questions\
**Created:** [May 18, 2024, 10:00am UTC](https://itensor.discourse.group/t/fail-to-apply-mpo-to-an-mps/1730 "2024-05-18T10:00:32Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Rubii115](https://yyz2.discourse-cdn.com/free1/user_avatar/itensor.discourse.group/rubii115/32/552_2.png) [@Rubii115](https://itensor.discourse.group/u/Rubii115)\
**Post date:** [May 18, 2024, 10:00am UTC](https://itensor.discourse.group/t/fail-to-apply-mpo-to-an-mps/1730/1 "2024-05-18T10:00:32Z")

</div>

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

```auto
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

```auto
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]

```

---

<div class="post-metadata">

**Author:** ![Rubii115](https://yyz2.discourse-cdn.com/free1/user_avatar/itensor.discourse.group/rubii115/32/552_2.png) [@Rubii115](https://itensor.discourse.group/u/Rubii115)\
**Post date:** [May 18, 2024, 11:59am UTC](https://itensor.discourse.group/t/fail-to-apply-mpo-to-an-mps/1730/2 "2024-05-18T11:59:30Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![miles](https://yyz2.discourse-cdn.com/free1/user_avatar/itensor.discourse.group/miles/32/6_2.png) [@miles](https://itensor.discourse.group/u/miles)\
**Post date:** [May 18, 2024, 12:29pm UTC](https://itensor.discourse.group/t/fail-to-apply-mpo-to-an-mps/1730/3 "2024-05-18T12:29:33Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![mtfishman](https://yyz2.discourse-cdn.com/free1/user_avatar/itensor.discourse.group/mtfishman/32/11_2.png) [@mtfishman](https://itensor.discourse.group/u/mtfishman)\
**Post date:** [May 18, 2024, 12:37pm UTC](https://itensor.discourse.group/t/fail-to-apply-mpo-to-an-mps/1730/4 "2024-05-18T12:37:17Z")

</div>

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…

---

<div class="post-metadata">

**Author:** ![Rubii115](https://yyz2.discourse-cdn.com/free1/user_avatar/itensor.discourse.group/rubii115/32/552_2.png) [@Rubii115](https://itensor.discourse.group/u/Rubii115)\
**Post date:** [May 18, 2024, 6:25pm UTC](https://itensor.discourse.group/t/fail-to-apply-mpo-to-an-mps/1730/5 "2024-05-18T18:25:49Z")

</div>

Thanks for suggestions!  
Wish you have a nice weekend.
