Created
October 17, 2021 20:23
-
-
Save hershsingh/e6bd6c1fab997530c1c0e31e0a1c87d5 to your computer and use it in GitHub Desktop.
MWE for issue at http://itensor.org/support/3534/convergence-issues-system-sizes-transverse-field-ising-model
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using ITensors | |
# DMRG parameters | |
sweeps = Sweeps(100, [ | |
"maxdim" "mindim" "cutoff" "noise" | |
10 10 1e-12 1E-7 | |
10 10 1e-12 1E-7 | |
20 10 1e-12 1E-7 | |
50 10 1e-12 1E-7 | |
100 20 1e-12 1E-8 | |
200 20 1e-12 1E-10 | |
200 20 1e-12 0 | |
]) | |
# setnoise!(sweeps, 0) | |
mutable struct DemoObserver <: AbstractObserver | |
energy_tol::Float64 | |
last_energy::Float64 | |
num_sweeps::Int64 | |
energy_tol_current::Float64 | |
DemoObserver(energy_tol=0.0) = new(energy_tol,1000.0, 0, 0.0) | |
end | |
function ITensors.checkdone!(o::DemoObserver;kwargs...) | |
sw = kwargs[:sweep] | |
energy = kwargs[:energy] | |
o.energy_tol_current = abs(energy-o.last_energy)/abs(energy) | |
o.last_energy = energy | |
o.num_sweeps = sw | |
if o.energy_tol_current < o.energy_tol | |
println("Stopping DMRG after sweep $sw") | |
return true | |
end | |
return false | |
end | |
function dmrg_ising(N,h) | |
println("="^80) | |
println("DMRG for Ising model") | |
println("N = $N") | |
println("-"^20) | |
sites = siteinds("S=1/2", N) | |
N = length(sites) | |
ampo = OpSum() | |
for i in 1:N-1 | |
ampo += -1.0, "Z", i, "Z", i+1 | |
end | |
for i in 1:N | |
ampo += -h, "X", i | |
end | |
H = MPO(ampo, sites) | |
psi0 = randomMPS(sites; linkdims=10) | |
# Set the energy tolerance to 1e-12 | |
dmrg_observer = DemoObserver(1E-12) | |
energy, psi = dmrg(H, psi0, sweeps; observer=dmrg_observer); | |
@show energy | |
return energy, dmrg_observer.num_sweeps, dmrg_observer.energy_tol_current | |
end | |
## Run DMRG for a various lattice sizes | |
h = 0.5 | |
N_arr = [6, 8, 10, 12, 16, 24, 32, 48] | |
data = Any[] | |
for N in N_arr | |
energy, num_sweeps, energy_tol = dmrg_ising(N,h) | |
push!(data, [N, num_sweeps, energy_tol]) | |
end | |
## Print the results | |
print("\n\n", "="^80, "\n") | |
print("N\tnum_sweeps\tenergy_err\n") | |
for row in data | |
print(join(row, "\t\t"), "\n") | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment