# MPO for an exponential operator

**URL:** <https://itensor.discourse.group/t/mpo-for-an-exponential-operator/1458>\
**Category:** ITensor Julia Questions\
**Tags:** mpo\
**Created:** [February 1, 2024, 8:30pm UTC](https://itensor.discourse.group/t/mpo-for-an-exponential-operator/1458 "2024-02-01T20:30:50Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Hareesh2708](https://avatars.discourse-cdn.com/v4/letter/h/a698b9/32.png) [@Hareesh2708](https://itensor.discourse.group/u/Hareesh2708)\
**Post date:** [February 1, 2024, 8:30pm UTC](https://itensor.discourse.group/t/mpo-for-an-exponential-operator/1458/1 "2024-02-01T20:30:50Z")

</div>

I am trying to define the MPO for the operator exp(i theta n\_j) for the Anyon Hubbard model(mapped to an interacting boson model). I have tried to define an operator using the op function for the matrix of exp(i theta n\_j) and then use it in the operator sum for the Hamiltonian but am recieving a method error in trying to do so.

![image](https://global.discourse-cdn.com/free1/uploads/itensor/original/1X/558669f56e80aa7a26565faa0063b34050c8c907.png)

(ImageSource:DOI: 10.1038/ncomms1353)

```auto
function Ham(θ,N,d)
    s = siteind("Qudit",dim=d)
    function expnmat(θ, d)
        return [(i == j) ? exp(1im*θ*(i-1)) : 0.0 for i in 1:d, j in 1:d]
    end
    
    statphase = op(expnmat(θ,d), s)
    
    
    sites = siteinds("Qudit",N,conserve_qns=true,dim=d)
    os = OpSum()
    for j=1:N-1
    os += ("adag",j,"a",j+1,"statphase",j)
    os += ("statphase",j,"adag",j+1,"a",j)
    os += 1/2,"n",j, "n",j
    os -= 1/2,"n",j    
    end
    H = MPO(os,sites)
    return H 
end

```

---

<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:** [February 2, 2024, 3:22am UTC](https://itensor.discourse.group/t/mpo-for-an-exponential-operator/1458/2 "2024-02-02T03:22:44Z")

</div>

To make a new operator definition that `OpSum` will recognize, you will need to make a new overload of the `ITensors.op` method. Please see the code examples and walkthrough in the documentation here:  
[https://itensor.github.io/ITensors.jl/dev/examples/Physics.html#custom\_op](https://itensor.github.io/ITensors.jl/dev/examples/Physics.html#custom_op)

And let us know if you have any questions about that process.

---

<div class="post-metadata">

**Author:** ![Ashinxinl](https://yyz2.discourse-cdn.com/free1/user_avatar/itensor.discourse.group/ashinxinl/32/265_2.png) [@Ashinxinl](https://itensor.discourse.group/u/Ashinxinl)\
**Post date:** [September 3, 2024, 8:23am UTC](https://itensor.discourse.group/t/mpo-for-an-exponential-operator/1458/3 "2024-09-03T08:23:02Z")

</div>

I am also experiencing this problem. Has it been resolved? My computer skills are quite low

---

<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 3, 2024, 2:47pm UTC](https://itensor.discourse.group/t/mpo-for-an-exponential-operator/1458/4 "2024-09-03T14:47:13Z")

</div>

Hi, [Ashinxinl](https://itensor.discourse.group/u/Ashinxinl) could you please start a new topic with details about what problem you are encountering (the original post above was pretty vague about what the error was), and also share what error message or incorrect output you are getting? Thanks –
