# how to apply an operator to a MPO

**URL:** <https://itensor.discourse.group/t/how-to-apply-an-operator-to-a-mpo/2057>\
**Category:** ITensor Julia Questions\
**Tags:** mpo\
**Created:** [October 13, 2024, 4:22pm UTC](https://itensor.discourse.group/t/how-to-apply-an-operator-to-a-mpo/2057 "2024-10-13T16:22:24Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![moon6614](https://yyz2.discourse-cdn.com/free1/user_avatar/itensor.discourse.group/moon6614/32/556_2.png) [@moon6614](https://itensor.discourse.group/u/moon6614)\
**Post date:** [October 13, 2024, 4:22pm UTC](https://itensor.discourse.group/t/how-to-apply-an-operator-to-a-mpo/2057/1 "2024-10-13T16:22:24Z")

</div>

I have a density matrix MPO that generated by outer(psi,psi). Now I want to do some operation like(Z\_1 Z\_2 \rho Z\_2 Z\_1). How can i do this?

---

<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:** [October 13, 2024, 4:56pm UTC](https://itensor.discourse.group/t/how-to-apply-an-operator-to-a-mpo/2057/2 "2024-10-13T16:56:54Z")

</div>

You can use the `apply` function to apply gates to an MPO.

---

<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:** [October 13, 2024, 4:57pm UTC](https://itensor.discourse.group/t/how-to-apply-an-operator-to-a-mpo/2057/3 "2024-10-13T16:57:58Z")

</div>

Please note also that in your example, the state both before and afterward will be pure. So the MPO representation of the density matrix will be _much more expensive_ computationally than just using the pure state, MPS representation of |\psi\rangle and applying just Z\_1 Z\_2 onto |\psi\rangle.

---

<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:** [October 13, 2024, 5:00pm UTC](https://itensor.discourse.group/t/how-to-apply-an-operator-to-a-mpo/2057/4 "2024-10-13T17:00:54Z")

</div>

Also, the documentation for the relevant version of the `apply` function is under the synonym `product` and you can find it at the link below, with details about how to use it for applying ITensors to either MPS or MPO:

[product (apply) function documentation](https://itensor.github.io/ITensors.jl/dev/MPSandMPO.html#ITensors.product-Tuple%7BVector%7BITensor%7D,%20AbstractMPS%7D)

---

<div class="post-metadata">

**Author:** ![moon6614](https://yyz2.discourse-cdn.com/free1/user_avatar/itensor.discourse.group/moon6614/32/556_2.png) [@moon6614](https://itensor.discourse.group/u/moon6614)\
**Post date:** [October 13, 2024, 5:13pm UTC](https://itensor.discourse.group/t/how-to-apply-an-operator-to-a-mpo/2057/5 "2024-10-13T17:13:00Z")

</div>

thank you very much for your apply, so honorable!

---

<div class="post-metadata">

**Author:** ![system](https://global.discourse-cdn.com/free1/uploads/itensor/original/1X/d3072b13e047cd06df7f3981547c0917d940dfa4.png) [@system](https://itensor.discourse.group/u/system)\
**Post date:** [October 23, 2024, 5:13pm UTC](https://itensor.discourse.group/t/how-to-apply-an-operator-to-a-mpo/2057/6 "2024-10-23T17:13:27Z")

</div>

This topic was automatically closed 10 days after the last reply. New replies are no longer allowed.
