Good question. A newer interface to the ITensor dmrg
function lets you use arrays for maxdim
and cutoff
and other parameters instead of the Sweeps
object. Using arrays combined with built-in Julia features for making them lets you conveniently define things like DMRG calculations where many sweeps in a row have the same maxdim setting.
Below is a complete working example. Note how it doesn’t use the Sweeps
type but instead just passes nsweeps, cutoff, maxdim
as named arguments to the dmrg
function. If one of these arguments, such as cutoff
is a number then that number is used for every sweep. If it is an array then element n
of that array is used for sweep number n
.
using ITensors
let
N = 100
sites = siteinds("S=1", N)
hterms = OpSum()
for j in 1:(N - 1)
hterms += "Sz", j, "Sz", j + 1
hterms += 0.5, "S+", j, "S-", j + 1
hterms += 0.5, "S-", j, "S+", j + 1
end
H = MPO(hterms, sites)
psi0 = randomMPS(sites, 10)
# Define DMRG accuracy parameters
cutoff = 1E-10
# Do 8 sweeps at maxdim=10, then 8 more at maxdim=20,
# followed by maxdim of 40,80,200,400
maxdim_10 = [10 for j=1:8]
maxdim_20 = [20 for j=1:8]
maxdim_rest = [40,80,200,400]
# vcat is a Julia function that merges vectors:
maxdim = vcat(maxdim_10,maxdim_20,maxdim_rest)
@show maxdim
nsweeps = length(maxdim)
energy, psi = dmrg(H, psi0; nsweeps, cutoff, maxdim)
println("Final energy = ", energy)
end
To do the thing you were asking about and repeat a number like 10
many times, I used an “array comprehension”
[10 for j=1:8]
or you could do fill(10,8)
to make an array with the number 10 over and over.
Then I did a similar thing for the value 20 and finally merged the three arrays together using the Julia function vcat
(vertical concatenate).