# How to add bond dimension in my code

**URL:** <https://itensor.discourse.group/t/how-to-add-bond-dimension-in-my-code/1883>\
**Category:** DMRG and Numerical Methods\
**Created:** [July 19, 2024, 1:07pm UTC](https://itensor.discourse.group/t/how-to-add-bond-dimension-in-my-code/1883 "2024-07-19T13:07:53Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![angelranhhh](https://yyz2.discourse-cdn.com/free1/user_avatar/itensor.discourse.group/angelranhhh/32/501_2.png) [@angelranhhh](https://itensor.discourse.group/u/angelranhhh)\
**Post date:** [July 19, 2024, 1:07pm UTC](https://itensor.discourse.group/t/how-to-add-bond-dimension-in-my-code/1883/1 "2024-07-19T13:07:53Z")

</div>

Hello everyone

My code takes too long time and consuming too much memory so I want to shorten the runtime by add bond simension.However, I meet a question on add bond dimension in my code.

The follow is my Julia code:

```julia
using ITensors
using ITensors.HDF5
using Distributed

N = 72
cutoff_value = 1E-8
tau = 0.02
ttotal = 7.5
h = 1
J = 1.0
V = 1.0
s = siteinds("S=1/2", N; conserve_qns = true)
hh = 1:1:10
a = 36

addprocs(2)

@everywhere begin
    using ITensors
    using ITensors.HDF5
end

@everywhere function compute_k(k, hh, s, tau, ttotal, cutoff_value, J, V, h, a, N)
    h_val = hh[k]
    gates = ITensor[]
    for j in 1:(N - 1)
        s1 = s[j]
        s2 = s[j + 1]
        hj1 = J * op("S+", s1) * op("S-", s2) +
              J * op("S-", s1) * op("S+", s2) +
              V * (op("Sz", s1) + 0.5 * op("Id", s1)) * (op("Sz", s2) + 0.5 * op("Id", s2))
        hj2 = 1 / 2 * h_val * h[j] * (op("Sz", s1) * op("Id", s2) + op("Id", s1) * op("Id", s2))
        Gj = exp(-im * tau / 2 * (hj1 + hj2))
        push!(gates, Gj)
    end
    s1 = s[N]
    s2 = s[1]
    Gj = exp(-im * tau / 4 * h_val * h[N] * (op("Sz", s1) * op("Id", s2) + op("Id", s1) * op("Id", s2)))
    append!(gates, reverse(gates))

    psi_0 = MPS(s, n -> isodd(n) ? "Up" : "Dn")
    psi_f_t = psi_0

end

```

or inline as `randomITensor(i, j)`.

I want to know how to add the bond dimension or how to shorten the running time.

---

<div class="post-metadata">

**Author:** ![kmp5](https://yyz2.discourse-cdn.com/free1/user_avatar/itensor.discourse.group/kmp5/32/251_2.png) [@kmp5](https://itensor.discourse.group/u/kmp5)\
**Post date:** [July 19, 2024, 1:54pm UTC](https://itensor.discourse.group/t/how-to-add-bond-dimension-in-my-code/1883/2 "2024-07-19T13:54:52Z")

</div>

Hello,

I think I am confused. What do you mean by `add bond dimension`? Do you have a reason for using `Distributed`. Also, can you please explain what you mean by `inline as randomITensor(i,j)`?  
When I try to call your provided code with these additional lines

```julia
julia> k = 1
julia> compute_k(k, hh, s, tau, ttotal, cutoff_value, J, V, h, a, N)

```

the function you provided fails with `ERROR: BoundsError: attempt to access Int64 at index [2]`.

As an aside, the syntax is now `random_itensor(i,j)` to construct a random ITensor as apposed to `randomITensor` constructor.

Thank,  
Karl
