# Defining two site local operators as part of a local Hamiltonian

**URL:** <https://itensor.discourse.group/t/defining-two-site-local-operators-as-part-of-a-local-hamiltonian/386>\
**Category:** ITensor Julia Questions\
**Tags:** julia, mpo\
**Created:** [September 8, 2022, 11:35pm UTC](https://itensor.discourse.group/t/defining-two-site-local-operators-as-part-of-a-local-hamiltonian/386 "2022-09-08T23:35:41Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Arnab](https://avatars.discourse-cdn.com/v4/letter/a/439d5e/32.png) [@Arnab](https://itensor.discourse.group/u/Arnab)\
**Post date:** [September 8, 2022, 11:35pm UTC](https://itensor.discourse.group/t/defining-two-site-local-operators-as-part-of-a-local-hamiltonian/386/1 "2022-09-08T23:35:41Z")

</div>

Hi!

I am trying the define a three local Hamiltonian H= \sum\_i h\_i with h\_j= X\_j \; CZ\_{j-1,j+1} but keep getting an error due to the two local CZ gate at the end. Is there an straightforward way to get around the issue?

```auto
using ITensors

    N=16 
    acc=1E-13
    bond_dim=50
    sites = siteinds("Qubit",N)
    psi0 = randomMPS(sites,bond_dim) 
    ampo = AutoMPO()

    for j=2:N-1
    # Want to define h_j= X_j CZ_{j-1,j+1}
    ampo += -2,"CZ",j-1,j+1,"σx",j; 
    end

    H = MPO(ampo,sites)
    sweeps = Sweeps(15) 
    maxdim!(sweeps,10,20,50,100,200,400,500) 
    cutoff!(sweeps,acc) 
    energy,T = dmrg(H,psi0,sweeps,outputlevel=0)
end

```

> Output: ArgumentError: Tuple contains 2 elements, must contain exactly 1 element

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:** [September 9, 2022, 2:05am UTC](https://itensor.discourse.group/t/defining-two-site-local-operators-as-part-of-a-local-hamiltonian/386/2 "2022-09-09T02:05:36Z")

</div>

It’s an interesting thing to do, and would be a good feature for us to have, but unfortunately right now the AutoMPO system (since renamed the OpSum system) doesn’t support two-site operators like “CZ” currently. Internally what it would have to do is to compute the SVD of this operator to write it as a sum of products of single-site operators, and then put these into the sum of terms (like a rewriting rule). So it’s something we could add but would take a bit of development.

As a workaround, you could work out a factorization of CZ like this for yourself, either numerically or probably by hand if you worked on it a bit. Basically you could define it as:

P\_0 \otimes I + P\_1 \otimes Z

where P\_0 projects the control site onto the 0 state and P\_1 projects the control site onto the 1 state. That sum of terms would then be something our system can read in.

---

<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:** [September 9, 2022, 2:13am UTC](https://itensor.discourse.group/t/defining-two-site-local-operators-as-part-of-a-local-hamiltonian/386/3 "2022-09-09T02:13:03Z")

</div>

Currently for the “Qubit” site type, we have the operators P\_0 and P\_1 defined as “ProjUp” and “ProjDn” respectively, but it would be good to add the aliases “Proj0” and “Proj1” so I’ll do that and it will be in the next version. For now you could use “ProjUp” and “ProjDn” or define your own custom operators.
