# How to build an MPO using 2-sites local operators?

**URL:** <https://itensor.discourse.group/t/how-to-build-an-mpo-using-2-sites-local-operators/2445>\
**Category:** DMRG and Numerical Methods\
**Created:** [July 17, 2025, 9:19pm UTC](https://itensor.discourse.group/t/how-to-build-an-mpo-using-2-sites-local-operators/2445 "2025-07-17T21:19:31Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Joacop16](https://yyz2.discourse-cdn.com/free1/user_avatar/itensor.discourse.group/joacop16/32/560_2.png) [@Joacop16](https://itensor.discourse.group/u/Joacop16)\
**Post date:** [July 17, 2025, 9:19pm UTC](https://itensor.discourse.group/t/how-to-build-an-mpo-using-2-sites-local-operators/2445/1 "2025-07-17T21:19:31Z")

</div>

Hi, ITensor Teams！

For a work on Lindblad Equations I need to build an MPO adding non-local terms. Without entering in so much details please consider the following example:

H = \sum\_{i = 1}^{N-1}\sigma\_{x}\sigma\_{x+1}

As this is very simple, I can do:

```julia
using ITensors
using ITensorMPS

N = 4
sites = siteinds("S=1/2", N)
σx = [0 1; 1 0]

os = OpSum() 
for i=1:N-1
os += 1, "σx", i, "σx",i+1
end
H = MPO(os, sites)

```

However, **for my personal code, I cannot write the 2-site operator as a product of two local operators**. I just have the operator as a 4x4 matrix, I need to do something like:

```julia
A = kron(σx,σx) #Example of 2-site operator

os = OpSum() 

for i=1:N-1
os += 1, A, i,i+1 #Maybe something like this? 
end
H = MPO(os, sites)

```

Clearly I got an error: MethodError: no method matching +(::Sum{Scaled{ComplexF64, Prod{Op}}}, ::Matrix{Int64})

**Basically, I want to add a 2-site operator to the OpSum().** Is there a way to do something like that?

---

<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:** [July 17, 2025, 10:39pm UTC](https://itensor.discourse.group/t/how-to-build-an-mpo-using-2-sites-local-operators/2445/2 "2025-07-17T22:39:56Z")

</div>

> [@MPO construction from multi-site OpSum](https://itensor.discourse.group/t/mpo-construction-from-multi-site-opsum/1338):
>
> I am interested in creating Hamiltonians built from multi-site terms which are not easily expressed as sums of (tensor products of) single-site basis operators. OpSum() supports multisite operators, but I am not sure about how to turn the resulting OpSum into an MPO, as the naive method—as in the following code—fails: sites = siteinds("Qubit",2) opsum = OpSum() add!(opsum,"CNOT",1,2) H = MPO(opsum,sites) with the last line producing an error. What is the correct syntax here?

It’s not directly supported, try to expand your operator into sums of local terms (Pauli/etc)

An example of the CNOT gate:

> [@Question on creating an MPO](https://itensor.discourse.group/t/question-on-creating-an-mpo/1519/4):
>
> A very convenient way to make a controlled gate like CNOT as an MPO using ITensor is to use our “OpSum” system. Here’s an example: n = 10 # 10 qubits, no problem to do more s = siteinds("Qubit",n) i = 3 # i will be the "control" site j = 7 # j will be the site where the gate acts cnot = OpSum() cnot += "Proj0",i,"Id",j cnot += "Proj1",i,"X",j CNOT = MPO(cnot,s) The above is using the following way of writing the CNOT gate: CNOT\_{i,j} = \ket{0}\_i \bra{0}\_i \otimes I\_j + \ket…
