# practical way to add the product of MANY local site operators in OpSum

**URL:** <https://itensor.discourse.group/t/practical-way-to-add-the-product-of-many-local-site-operators-in-opsum/443>\
**Category:** DMRG and Numerical Methods\
**Tags:** mpo\
**Created:** [October 2, 2022, 2:48pm UTC](https://itensor.discourse.group/t/practical-way-to-add-the-product-of-many-local-site-operators-in-opsum/443 "2022-10-02T14:48:24Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![phyjswang](https://avatars.discourse-cdn.com/v4/letter/p/f9ae1b/32.png) [@phyjswang](https://itensor.discourse.group/u/phyjswang)\
**Post date:** [October 2, 2022, 2:48pm UTC](https://itensor.discourse.group/t/practical-way-to-add-the-product-of-many-local-site-operators-in-opsum/443/1 "2022-10-02T14:48:24Z")

</div>

Dear all,

If a spin Hamiltonian contains a term which is the product of ALL local site operators, say \prod\_i \sigma^z\_i, how to use `OpSum` to add this term into the Hamiltonian MPO? Since it becomes impractical to write down this term in the usual way as other local terms…

Is it possible to construct such term into an MPO manually in ITensor, and then add it into the Hamiltonian MPO which is constructed separately. Can someone elaborate on this in details.

Best,  
Junsen

---

<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 2, 2022, 4:42pm UTC](https://itensor.discourse.group/t/practical-way-to-add-the-product-of-many-local-site-operators-in-opsum/443/2 "2022-10-02T16:42:57Z")

</div>

Hi Junsen,  
Here is an approach you can use:

```auto
s = siteinds("S=1/2",N)
pSz = MPO(s,"Sz")
os = OpSum()
for j=1:N-1
  # add terms to OpSum
end
H = MPO(os,s)

#...

energy,psi = dmrg([H,pSz],psi0; nsweeps, maxdim, cutoff)

```

where the key points are:

- you can make a product of all “Sz” operators by calling `MPO(s,"Sz")`
- you can pass two or more MPOs to DMRG in a vector like `[H,pSz]` and DMRG will treat them as if they are summed for the purpose of the ground state calculation. It will not actually sum them, but loop over them internally in an efficient way when doing each core step of the DMRG algorithm.

For more information:

- [https://itensor.github.io/ITensors.jl/dev/DMRG.html#ITensors.dmrg](https://itensor.github.io/ITensors.jl/dev/DMRG.html#ITensors.dmrg)
- [https://itensor.github.io/ITensors.jl/dev/MPSandMPO.html#ITensors.MPO-Tuple{Type{\<:Number},%20Vector{\<:Index},%20String}](https://itensor.github.io/ITensors.jl/dev/MPSandMPO.html#ITensors.MPO-Tuple%7BType%7B%3C:Number%7D,%20Vector%7B%3C:Index%7D,%20String%7D)
