# apply localMPO to an Itensor

**URL:** <https://itensor.discourse.group/t/apply-localmpo-to-an-itensor/1761>\
**Category:** ITensor C++ Questions\
**Created:** [May 28, 2024, 9:38am UTC](https://itensor.discourse.group/t/apply-localmpo-to-an-itensor/1761 "2024-05-28T09:38:31Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![jacopo2012](https://yyz2.discourse-cdn.com/free1/user_avatar/itensor.discourse.group/jacopo2012/32/561_2.png) [@jacopo2012](https://itensor.discourse.group/u/jacopo2012)\
**Post date:** [May 28, 2024, 9:38am UTC](https://itensor.discourse.group/t/apply-localmpo-to-an-itensor/1761/1 "2024-05-28T09:38:31Z")

</div>

Hello,

I am trying to apply a localMPO to a local MPS Itensor. Namely

auto PH = LocalMPO(WGlobal);  
int b=1;  
int numCenter=1  
PH.numCenter(numCenter);  
PH.position(b,psi);  
phi1 = psi(b);  
phi1 = PH \* phi1;

the latter command cannot compile:

error: invalid operands to binary expression (‘LocalMPO’ and ‘ITensor’)  
phi1 = PH \* phi1;

What type of object is the local MPO then? How can I extract the corresponden ITensor and apply it to the local MPS?

Thanks a lot!

Jacopo.

---

<div class="post-metadata">

**Author:** ![ryanlevy](https://yyz2.discourse-cdn.com/free1/user_avatar/itensor.discourse.group/ryanlevy/32/150_2.png) [@ryanlevy](https://itensor.discourse.group/u/ryanlevy)\
**Post date:** [May 28, 2024, 11:08am UTC](https://itensor.discourse.group/t/apply-localmpo-to-an-itensor/1761/2 "2024-05-28T11:08:24Z")

</div>

Could you explain more about what you are trying to do? the `LocalMPO` object is really designed for a sparse projection of the MPS, where the two [main functions](https://github.com/ITensor/ITensor/blob/v3/itensor/mps/localmpo.h) are `product`/`expect` to find \langle \phi^\prime|PH|\phi\rangle or \langle \phi|PH|\phi\rangle.

Given a standard MPO, one can use the `applyMPO` function to either exactly, or approximately apply an MPO to a MPS.

---

<div class="post-metadata">

**Author:** ![jacopo2012](https://yyz2.discourse-cdn.com/free1/user_avatar/itensor.discourse.group/jacopo2012/32/561_2.png) [@jacopo2012](https://itensor.discourse.group/u/jacopo2012)\
**Post date:** [May 28, 2024, 12:39pm UTC](https://itensor.discourse.group/t/apply-localmpo-to-an-itensor/1761/3 "2024-05-28T12:39:33Z")

</div>

Hi,

thanks for your answer!  
All I am trying to do is to have an Itensor object (with 2 links indeces and sites and site’ ) giving me the 1 site effective Hamiltonian at site b (as in TDVP for example (see Fig 2 in [https://arxiv.org/pdf/1408.5056](https://arxiv.org/pdf/1408.5056))), and I want to apply it to the MPS at site b. I thought that this Itensor object is indeed given by PH, so that explains my previous attempt to code.

Thanks,  
Jacopo.

---

<div class="post-metadata">

**Author:** ![ryanlevy](https://yyz2.discourse-cdn.com/free1/user_avatar/itensor.discourse.group/ryanlevy/32/150_2.png) [@ryanlevy](https://itensor.discourse.group/u/ryanlevy)\
**Post date:** [May 28, 2024, 1:17pm UTC](https://itensor.discourse.group/t/apply-localmpo-to-an-itensor/1761/4 "2024-05-28T13:17:13Z")

</div>

Ah yes, this is the object in Fig 2b (for some number of sites). `product` is probably the function you want. Check out how things are done in the tdvp code: [TDVP/tdvp.h at master · ITensor/TDVP · GitHub](https://github.com/ITensor/TDVP/blob/master/tdvp.h)

(And an obligatory this is much nicer in the Julia version )
