First DMRG sweep takes significantly Longer

Hello,

I have been experimenting with ITensor’s DMRG so I can have easy quantum number conservation. Previously, I was using QUIMB to do DMRG, and the DMRG algorithm used there could find the ground state significantly faster (around 2 seconds for my system). Using ITensor, the DMRG process now takes around 90 seconds with around 70 seconds being used to do just the first sweep. Is there any reason for this? Anything I am doing wrong? I am solving for an ab initio quantum chemistry Hamiltonian.

Code:

let
    N = 8
    δ = 1.0 
    g = 0.5
    t, Γ = pairing_hamiltonian(δ, g, N)
    # Convert the DataFrame to a standard Julia array
    

    sites = siteinds("Fermion",N; conserve_qns=true)

    

    os = OpSum()
    ops = Any[]
    push!(ops,E)
    for i in 1:N 
        push!(ops, "Id")
        push!(ops, i)
        os .+= Tuple(ops)
    end
    for i in 1:N, j in 1:N
        #one body terms
        if t[i,j] == 0
            continue
        end
        ops = Any[]
        push!(ops,t[i,j])
        
        push!(ops, "Cdag")
        push!(ops, i)

        push!(ops, "C")
        push!(ops, j)
        println(ops)

        os .+= Tuple(ops)
    end
    for i in 1:N, j in 1:N, k in 1:N, l in 1:N
        #two body terms
        if Γ[i,j,k,l] < 1.0e-5
            continue
        end
        ops = Any[]
        print(i)
        push!(ops,Γ[i,j,k,l]*(1/4))

        push!(ops, "Cdag")
        push!(ops, i)
        
        push!(ops, "Cdag")
        push!(ops, j)

        push!(ops, "C") 
        push!(ops, l)

        push!(ops, "C")
        push!(ops, k)
        
        println(ops)
        os .+= Tuple(ops)
    
    end

    println("done")
    H = cuMPO(os,sites)
    println("MPO made, starting DMRG")

    
    println(totalqn(H))

    nsweeps = 5 # number of sweeps is 5
    maxdim = [10,10,20,30,40] # gradually increase states kept
    mindim = [1,2,2,2,2]
    cutoff = [1E-6,1E-8,1E-10,1E-12,1E-14] # desired truncation error
    noise = [1E-7, 1E-8, 1E-10,1E-12,0]

    state = ["1","1","1","1","0","0","0","0"]
    psi0 = cuMPS(sites,state)
     energy,psi =  dmrg(H,psi0;nsweeps,maxdim,mindim,noise)

  return
end

Output:

After sweep 1 energy=1.4167742892881572  maxlinkdim=8 maxerr=1.39E-16 time=74.167
After sweep 2 energy=1.4167742843511046  maxlinkdim=8 maxerr=7.74E-18 time=0.159
After sweep 3 energy=1.4167742843511038  maxlinkdim=8 maxerr=7.68E-19 time=0.089
After sweep 4 energy=1.416774284351104  maxlinkdim=8 maxerr=2.46E-18 time=0.022
After sweep 5 energy=1.416774284351103  maxlinkdim=4 maxerr=0.00E+00 time=19.825

You may be seeing Julia compilation for the first sweep. I’d recommend to run your code a second time to see the true time for that first step

For example, with a S=1 dmrg:

# first call
After sweep 1 energy=-12.738482439983922  maxlinkdim=9 maxerr=4.41E-16 time=4.114
After sweep 2 energy=-12.869295938881859  maxlinkdim=20 maxerr=2.63E-06 time=0.022
After sweep 3 energy=-12.89374880597547  maxlinkdim=76 maxerr=9.40E-11 time=0.051

# second call
After sweep 1 energy=-12.791718425042001  maxlinkdim=9 maxerr=1.64E-16 time=0.017
After sweep 2 energy=-12.874738045267401  maxlinkdim=20 maxerr=4.17E-06 time=0.017
After sweep 3 energy=-12.894101351242497  maxlinkdim=72 maxerr=9.31E-11 time=0.048

(numerical differences are because I am not seeding a random initial state)

Hello,

I’ve run this code many times with the same results just using Julia (filename).jl. however, I am new to Julia and could be making a mistake.

When you first run julia filename.jl it has to compile all the code which is why you see that large time. For the second sweep, it has been compiled so its much faster
If you want to run something again once it has been compiled, you’d need to use the Julia REPL, or perform more advanced techniques to reduce that time (SnoopCompiler/etc)

However you aren’t doing anything wrong – just know that sometimes the code will need to compile so direct comparisons to (for example) python can be difficult

This topic was automatically closed 10 days after the last reply. New replies are no longer allowed.