I am trying to run a calculation for non-interacting (spinful) fermions to check something, so I installed iTensor to check it out. This is the first time I’ve used the Julia version (and I don’t really know any Julia). I am getting an error that I can’t work out how to fix. My code is:
using ITensors
let
N = 100
sites = siteinds("Electron", N; conserve_qns=true)
op = OpSum()
t=1.0
for j=1:N-1
op += -t,"Cdagup",j,"Cup",j+1
op += -t,"Cdagup",j+1,"Cup",j
op += -t,"Cdagdn",j,"Cdn",j+1
op += -t,"Cdagdn",j+1,"Cdn",j
end
H = MPO(op,sites)
nsweeps = 30
maxdim = [2,2,3,4,6,8,12,16,23,32,46,64,91,128,181,256,362,511,600,600,600,600,600,600,600,600,600,600,600,600] # gradually increase states kept
cutoff = [1E-14] # desired truncation error
noise = [0.0]
states = [isodd(n) ? "Up" : "Dn" for n in 1:N]
print(states)
psi0 = randomMPS(sites,states)
print(psi0)
energy,psi = dmrg(H,psi0; nsweeps, maxdim, cutoff, noise)
return
end
But this gives an error:
ERROR: LoadError: ArgumentError: initial vector should not have norm zero
Stacktrace:
[1] initialize(iter::KrylovKit.LanczosIterator{ProjMPO, ITensor, KrylovKit.ModifiedGramSchmidt2}; verbosity::Int64)
@ KrylovKit ~/.julia/packages/KrylovKit/r8GLV/src/factorizations/lanczos.jl:171
[2] initialize
@ ~/.julia/packages/KrylovKit/r8GLV/src/factorizations/lanczos.jl:167 [inlined]
[3] eigsolve(A::ProjMPO, x₀::ITensor, howmany::Int64, which::Symbol, alg::KrylovKit.Lanczos{KrylovKit.ModifiedGramSchmidt2, Float64})
@ KrylovKit ~/.julia/packages/KrylovKit/r8GLV/src/eigsolve/lanczos.jl:11
[4] #eigsolve#38
@ ~/.julia/packages/KrylovKit/r8GLV/src/eigsolve/eigsolve.jl:200 [inlined]
[5] eigsolve
@ ~/.julia/packages/KrylovKit/r8GLV/src/eigsolve/eigsolve.jl:182 [inlined]
[6] macro expansion
@ ~/.julia/packages/ITensors/WMeVS/src/mps/dmrg.jl:237 [inlined]
[7] macro expansion
@ ~/.julia/packages/TimerOutputs/RsWnF/src/TimerOutput.jl:253 [inlined]
[8] macro expansion
@ ~/.julia/packages/ITensors/WMeVS/src/mps/dmrg.jl:236 [inlined]
[9] macro expansion
@ ./timing.jl:395 [inlined]
[10]
@ ITensors ~/.julia/packages/ITensors/WMeVS/src/mps/dmrg.jl:204
[11] dmrg
@ ~/.julia/packages/ITensors/WMeVS/src/mps/dmrg.jl:156 [inlined]
[12] #dmrg#1059
@ ~/.julia/packages/ITensors/WMeVS/src/mps/dmrg.jl:27 [inlined]
[13] dmrg
@ ~/.julia/packages/ITensors/WMeVS/src/mps/dmrg.jl:20 [inlined]
[14] #dmrg#1065
@ ~/.julia/packages/ITensors/WMeVS/src/mps/dmrg.jl:391 [inlined]
[15] top-level scope
@ ~/dmrg.jl:29
[16] include(fname::String)
@ Base.MainInclude ./client.jl:489
[17] top-level scope
I don’t know what this means, since the psi0 is initialized in the same way as the example codes. In desparation, looking at the differences between my code and the 2D hubbard model example on Github, I added the U term:
using ITensors
let
N = 100
sites = siteinds("Electron", N; conserve_qns=true)
op = OpSum()
t=1.0
for j=1:N-1
op += -t,"Cdagup",j,"Cup",j+1
op += -t,"Cdagup",j+1,"Cup",j
op += -t,"Cdagdn",j,"Cdn",j+1
op += -t,"Cdagdn",j+1,"Cdn",j
end
U=0.01
for n in 1:N
op += U, "Nupdn", n
end
H = MPO(op,sites)
nsweeps = 30
maxdim = [2,2,3,4,6,8,12,16,23,32,46,64,91,128,181,256,362,511,600,600,600,600,600,600,600,600,600,600,600,600] # gradually increase states kept
cutoff = [1E-14] # desired truncation error
noise = [0.0]
states = [isodd(n) ? "Up" : "Dn" for n in 1:N]
print(states)
psi0 = randomMPS(sites,states)
print(psi0)
energy,psi = dmrg(H,psi0; nsweeps, maxdim, cutoff, noise)
return
end
and suddenly it works! But I want non-interacting fermions. Setting U=0 brings back the original problem. In fact even U=1e-3 has problems, but U=1e-2 works. But I want U=0. How do I do non-interacting fermions?