# how to construct a gate operator with onsite interaction term at TEBD

**URL:** <https://itensor.discourse.group/t/how-to-construct-a-gate-operator-with-onsite-interaction-term-at-tebd/951>\
**Category:** ITensor Julia Questions\
**Tags:** julia\
**Created:** [June 19, 2023, 12:48pm UTC](https://itensor.discourse.group/t/how-to-construct-a-gate-operator-with-onsite-interaction-term-at-tebd/951 "2023-06-19T12:48:57Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![yang1](https://yyz2.discourse-cdn.com/free1/user_avatar/itensor.discourse.group/yang1/32/274_2.png) [@yang1](https://itensor.discourse.group/u/yang1)\
**Post date:** [June 19, 2023, 12:48pm UTC](https://itensor.discourse.group/t/how-to-construct-a-gate-operator-with-onsite-interaction-term-at-tebd/951/1 "2023-06-19T12:48:57Z")

</div>

When i want to do a naive TEBD about bose-hubbard model, I get some obstacles when i’am trying to  
make the local hj operator, the on-site term has some problem, how to construct the onsite term?

```plaintext
    for j in 1:(L - 1)
        s1 = sites[j]
        s2 = sites[j + 1]
        hj =
            0.5 * U * op("N", s1) * op("N", s1) + 
            - 0.5 * U * op("N", s1) + 
            V * op("N", s1) * op("N", s2) +
            -t * op("A", s1) * op("Adag", s2) +
            -t * op("Adag", s1) * op("A", s2)
        Gj = exp(-im * tau / 2 * hj)
        push!(gates, Gj)
    end

```

it has an error output 🙂  
ERROR: LoadError: syntax: “\*(0.5, U, op(“N”, s1), op(“N”, s1))” is not a valid function argument name around d:\Source\_Code\BaiduSyncdisk\julia\cold\_atom\BHM\1d\_BHM\_TEBD.jl:72

 ![QQ截图20230619204753](https://global.discourse-cdn.com/free1/uploads/itensor/original/1X/7f74f4b498e4afea1d6effb2b46a8d7b15d484f0.png)

---

<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:** [June 19, 2023, 3:35pm UTC](https://itensor.discourse.group/t/how-to-construct-a-gate-operator-with-onsite-interaction-term-at-tebd/951/2 "2023-06-19T15:35:08Z")

</div>

It looks like you might be getting a Julia syntax error. Please check that U is defined, that your syntax is correct, and so on. You might want to try adding one term at a time to your expression to see which one is causing the issues, and also print out each thing such as U or `op("N",s1)` separately to make sure it has the type and behavior you expect.

---

<div class="post-metadata">

**Author:** ![yang1](https://yyz2.discourse-cdn.com/free1/user_avatar/itensor.discourse.group/yang1/32/274_2.png) [@yang1](https://itensor.discourse.group/u/yang1)\
**Post date:** [June 20, 2023, 1:02am UTC](https://itensor.discourse.group/t/how-to-construct-a-gate-operator-with-onsite-interaction-term-at-tebd/951/3 "2023-06-20T01:02:44Z")

</div>

thanks for your reply, I realize my aim by `U/2 * op("N * N", s1) * op("I", s2)`, but there has anothter doubt,  
when I save the data of MPS h5 data every time evolution steps, after about 300 steps, the file size madness grew to 1.0GB a MPS state, My system is `sites = siteinds("Boson", 100; dim=3, conserve_qns=true)`, I want to ask is it normal?

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

---

<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:** [June 20, 2023, 1:17am UTC](https://itensor.discourse.group/t/how-to-construct-a-gate-operator-with-onsite-interaction-term-at-tebd/951/4 "2023-06-20T01:17:03Z")

</div>

That does seem a bit large. What is the bond dimension? Also are you adding more MPS to the same file? Or overwriting them and/or making new files each time?

---

<div class="post-metadata">

**Author:** ![yang1](https://yyz2.discourse-cdn.com/free1/user_avatar/itensor.discourse.group/yang1/32/274_2.png) [@yang1](https://itensor.discourse.group/u/yang1)\
**Post date:** [June 20, 2023, 1:43am UTC](https://itensor.discourse.group/t/how-to-construct-a-gate-operator-with-onsite-interaction-term-at-tebd/951/5 "2023-06-20T01:43:47Z")

</div>

thanks, my bond dimension for the initial wave function’s maxdim is about 250 , and it’s h5 file size is about 21MB. I have test my code for L = 10 system, I don’t see the crazy enlarge of MPS file, I don’t think I adding more MPS to the same file. this is my time loop code, is there something wrong?

```auto
for t in 0.0 : tau : t_total
        
        psi0 = apply(gates, psi0; cutoff)
        n = expect(psi0, "N"; sites=center)
        println("$t, $n")
        normalize!(psi0)
        f2 = h5open("./data/psi_t_$(round(t; digits = 4))_L_$(L)_J_$(round(J; digits = 4))_V_$(round(V; digits = 4)).h5","w")
            write(f2,"psi",psi0)
        close(f2)

        t ≈ t_total && break
    end

```

surely, I save the MPS data every time step by create a new file. The cutoff is set 1e-8.  
I think the problem is might the gates operater’s dim is enlarge to a big value to make sure the cutoff 1e-8, and lead to the wave function enlarge, is this wright?

---

<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:** [June 20, 2023, 3:08am UTC](https://itensor.discourse.group/t/how-to-construct-a-gate-operator-with-onsite-interaction-term-at-tebd/951/6 "2023-06-20T03:08:32Z")

</div>

That’s good info, but I won’t be able to know what is causing the size to get larger. One thing you can do is borrow some of the techniques (like the idea of using the `Base.summarysize` function) from this code example:  
[https://itensor.github.io/ITensors.jl/dev/examples/DMRG.html#Monitoring-the-Memory-Usage-of-DMRG](https://itensor.github.io/ITensors.jl/dev/examples/DMRG.html#Monitoring-the-Memory-Usage-of-DMRG)  
to print out the size of your MPS just before you write it to the file. If the MPS is small but the file is large, then you’ll know something is going wrong with the file.

Otherwise you’ll have to try various things like that to debug it. I hope you find the issue!
