# Load error at sweep line

**URL:** <https://itensor.discourse.group/t/load-error-at-sweep-line/1523>\
**Category:** ITensor Julia Questions\
**Tags:** julia, dmrg, mps, mpo\
**Created:** [March 6, 2024, 5:55am UTC](https://itensor.discourse.group/t/load-error-at-sweep-line/1523 "2024-03-06T05:55:52Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![dennil](https://avatars.discourse-cdn.com/v4/letter/d/cdc98d/32.png) [@dennil](https://itensor.discourse.group/u/dennil)\
**Post date:** [March 6, 2024, 5:55am UTC](https://itensor.discourse.group/t/load-error-at-sweep-line/1523/1 "2024-03-06T05:55:52Z")

</div>

i was trying to implement a julia version of the C++ code given at [DMRG · ITensors.jl](https://itensor.github.io/ITensors.jl/dev/tutorials/DMRG.html). on running the code as a .jl file it kept giving an error at line 17 in the sweep section

```julia
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?

---

<div class="post-metadata">

**Author:** ![ryanlevy](https://yyz2.discourse-cdn.com/free1/user_avatar/itensor.discourse.group/ryanlevy/32/150_2.png) [@ryanlevy](https://itensor.discourse.group/u/ryanlevy)\
**Post date:** [March 6, 2024, 12:10pm UTC](https://itensor.discourse.group/t/load-error-at-sweep-line/1523/2 "2024-03-06T12:10:10Z")

</div>

The problem is the syntax you’ve used for the sweeps object. In Julia, to modify something there is generally a `!` in the function, and here to change the sweep parameters you can do

```julia
sweeps = Sweeps(5)
setmaxdim!(sweeps,10, 20, 30, 40, 50)
setcutoff!(sweeps,1E-10)

```

Checkout the documentation for more: [Sweeps · ITensors.jl](https://itensor.github.io/ITensors.jl/stable/Sweeps.html)

---

<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:** [March 6, 2024, 11:30pm UTC](https://itensor.discourse.group/t/load-error-at-sweep-line/1523/3 "2024-03-06T23:30:06Z")

</div>

Also, I wanted to note that we encourage users not to use the Sweeps object any more. While it is still supported for a short time longer, we encourage you to use the new array-based interface.

I noticed that the code at the link you provided, @dennil, already uses this newer interface. Is there a reason you were trying to use the older one?

Lastly, there’s no `Dict("Quiet" => true)` input recognized by our Julia DMRG code. Please see the [documentation of the dmrg function](https://itensor.github.io/ITensors.jl/dev/DMRG.html#ITensors.dmrg) to see which arguments are accepted. The one closest to that one would be the `outputlevel` keyword argument which is an integer controlling the amount of output printed.
