i was trying to implement a julia version of the C++ code given at DMRG · ITensors.jl. on running the code as a .jl file it kept giving an error at line 17 in the sweep section
using ITensors
using ITensors
function main()
N = 4
sites = SpinOne(N; conserve_qns=false)
ampo = AutoMPO(sites)
for j in 1:N-1
ampo += 0.5, "S+", j, "S-", j+1
ampo += 0.5, "S-", j, "S+", j+1
ampo += "Sz", j, "Sz", j+1
end
H = toMPO(ampo)
sweeps = Sweeps(5)
sweeps.maxdim() = [10, 20, 30, 40, 50]
sweeps.cutoff() = 1E-10
psi0 = randomMPS(sites)
energy, psi = dmrg(H, psi0, sweeps, Dict("Quiet" => true))
println("\nj Sz = ")
for j in 1:N
position!(psi, j)
ket = psi[j]
bra = dag(prime(ket, "Site"))
Szjop = op(sites, "Sz", j)
szj = elt(bra * Szjop * ket)
println("$j $szj")
end
totalSdS = 0.0
println("\nj S.S = ")
for b in 1:N-1
position!(psi, b)
bondket = psi[b] * psi[b+1]
bondbra = dag(prime(bondket, "Site"))
zzop = op(sites, "Sz", b) * op(sites, "Sz", b+1)
pmop = 0.5 * op(sites, "S+", b) * op(sites, "S-", b+1)
mpop = 0.5 * op(sites, "S-", b) * op(sites, "S+", b+1)
zz = elt(bondbra * zzop * bondket)
pm = elt(bondbra * pmop * bondket)
mp = elt(bondbra * mpop * bondket)
println("$b $(zz + pm + mp)")
totalSdS += zz + pm + mp
end
println("\nSum of S.S = $totalSdS")
println("Ground state energy from DMRG = $energy")
return 0
end
main()
the code shows the following load error
ERROR: LoadError: syntax: Global method definition around /home/dennil/Desktop/Master’s thesis/four_spin.jl:17 needs to be placed at the top level, or use “eval”.
Stacktrace:
[1] top-level scope
@ ~/Desktop/Master’s thesis/four_spin.jl:3
in expression starting at /home/dennil/Desktop/Master’s thesis/four_spin.jl:3
could someone please help me resolve this error asap?