# Tracking the expectation value of an MPO during DMRG with DMRGObserver

**URL:** <https://itensor.discourse.group/t/tracking-the-expectation-value-of-an-mpo-during-dmrg-with-dmrgobserver/338>\
**Category:** ITensor Julia Questions\
**Tags:** julia, dmrg\
**Created:** [August 13, 2022, 9:07am UTC](https://itensor.discourse.group/t/tracking-the-expectation-value-of-an-mpo-during-dmrg-with-dmrgobserver/338 "2022-08-13T09:07:24Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![TakisAngelides](https://yyz2.discourse-cdn.com/free1/user_avatar/itensor.discourse.group/takisangelides/32/133_2.png) [@TakisAngelides](https://itensor.discourse.group/u/TakisAngelides)\
**Post date:** [August 13, 2022, 9:07am UTC](https://itensor.discourse.group/t/tracking-the-expectation-value-of-an-mpo-during-dmrg-with-dmrgobserver/338/1 "2022-08-13T09:07:24Z")

</div>

Hello,

What would be the syntax if I have an MPO and want to track its expectation value using the DMRGObserver in Julia?

The syntax that I have found so far I believe is only suitable for single site operators whereas I would like to apply a whole MPO which is more general.

Thanks in advance!

---

<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:** [August 13, 2022, 5:57pm UTC](https://itensor.discourse.group/t/tracking-the-expectation-value-of-an-mpo-during-dmrg-with-dmrgobserver/338/2 "2022-08-13T17:57:34Z")

</div>

Hi, good question. So the way I would do this is:

- when defining your custom observer type, add a data field that holds an MPO
- when constructing your observer, pass the MPO that you want to measure to your observer object so it can store it
- in the `measure!` function, the first argument passed is the observer, so you can access the MPO you want to measure and also the current wavefunction is passed through the `psi` keyword argument (as [noted in the docs here](https://itensor.github.io/ITensors.jl/stable/Observer.html#Defining-a-Custom-Observer)).
- you can then use the code `inner(psi',M,psi)` where `M` is your MPO to get the expectation value and print it
