How to add bond dimension in my code

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:

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.

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> 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