|
| 1 | +#!/usr/bin/env julia |
| 2 | + |
| 3 | +using HDF5 |
| 4 | +using ITensors |
| 5 | +using MKL |
| 6 | +using Random |
| 7 | + |
| 8 | +# 2D Heisenberg |
| 9 | +function main(; |
| 10 | + L::Int, |
| 11 | + max_B::Int, |
| 12 | + L2::Int = 0, |
| 13 | + peri::Bool = false, |
| 14 | + mars::Bool = true, |
| 15 | + J2::Number = 0, |
| 16 | + J22::Number = 0, |
| 17 | + J3::Number = 0, |
| 18 | + cmpl::Bool = false, |
| 19 | + zero_mag::Bool = true, |
| 20 | + snake::Bool = true, |
| 21 | + max_step::Int = 100, |
| 22 | + seed::Int = 0, |
| 23 | +) |
| 24 | + @assert L % 2 == 0 |
| 25 | + |
| 26 | + out_filename = "L$L" |
| 27 | + if L2 == 0 |
| 28 | + L2 = L |
| 29 | + else |
| 30 | + @assert L2 % 2 == 0 |
| 31 | + out_filename *= ",$L2" |
| 32 | + end |
| 33 | + if !peri |
| 34 | + out_filename *= "_open" |
| 35 | + end |
| 36 | + if mars |
| 37 | + out_filename *= "_mars" |
| 38 | + end |
| 39 | + if J2 != 0 |
| 40 | + out_filename *= "_J2=$J2" |
| 41 | + end |
| 42 | + if J22 != 0 |
| 43 | + out_filename *= "_J22=$J22" |
| 44 | + end |
| 45 | + if J3 != 0 |
| 46 | + out_filename *= "_J3=$J3" |
| 47 | + end |
| 48 | + out_filename *= "_B$max_B" |
| 49 | + if cmpl |
| 50 | + out_filename *= "_cmpl" |
| 51 | + end |
| 52 | + if zero_mag |
| 53 | + out_filename *= "_zm" |
| 54 | + end |
| 55 | + if !snake |
| 56 | + out_filename *= "_ro_none" |
| 57 | + end |
| 58 | + out_filename *= ".hdf5" |
| 59 | + @show out_filename |
| 60 | + |
| 61 | + if seed > 0 |
| 62 | + Random.seed!(seed) |
| 63 | + end |
| 64 | + |
| 65 | + sites = siteinds("S=1/2", L * L2; conserve_qns = zero_mag) |
| 66 | + |
| 67 | + ampo = OpSum() |
| 68 | + |
| 69 | + function ind(i, j) |
| 70 | + i = mod1(i, L) |
| 71 | + j = mod1(j, L2) |
| 72 | + if snake |
| 73 | + if i % 2 == 1 |
| 74 | + return (i - 1) * L2 + j |
| 75 | + else |
| 76 | + return (i - 1) * L2 + (L2 + 1 - j) |
| 77 | + end |
| 78 | + else |
| 79 | + return (i - 1) * L2 + j |
| 80 | + end |
| 81 | + end |
| 82 | + |
| 83 | + function add_edge!(J, i1, j1, i2, j2) |
| 84 | + Jxy = 0.5 * J |
| 85 | + if mars |
| 86 | + d = i2 - i1 + j2 - j1 |
| 87 | + if mod(d, 2) == 1 |
| 88 | + Jxy *= -1 |
| 89 | + end |
| 90 | + end |
| 91 | + |
| 92 | + k1 = ind(i1, j1) |
| 93 | + k2 = ind(i2, j2) |
| 94 | + ampo += J, "Sz", k1, "Sz", k2 |
| 95 | + ampo += Jxy, "S+", k1, "S-", k2 |
| 96 | + ampo += Jxy, "S-", k1, "S+", k2 |
| 97 | + end |
| 98 | + |
| 99 | + for i = 1:L |
| 100 | + for j = 1:L2-1+peri |
| 101 | + add_edge!(1, i, j, i, j + 1) |
| 102 | + end |
| 103 | + end |
| 104 | + for i = 1:L-1+peri |
| 105 | + for j = 1:L2 |
| 106 | + add_edge!(1, i, j, i + 1, j) |
| 107 | + end |
| 108 | + end |
| 109 | + |
| 110 | + # Diagonal term, needed for triangular lattice and J1-J2 model |
| 111 | + if J2 != 0 |
| 112 | + for i = 1:L-1+peri |
| 113 | + for j = 1:L2-1+peri |
| 114 | + add_edge!(J2, i, j, i + 1, j + 1) |
| 115 | + end |
| 116 | + end |
| 117 | + end |
| 118 | + |
| 119 | + # Inverse diagonal term, needed for J1-J2 model |
| 120 | + if J22 != 0 |
| 121 | + for i = 1:L-1+peri |
| 122 | + for j = 1:L2-1+peri |
| 123 | + add_edge!(J22, i, j + 1, i + 1, j) |
| 124 | + end |
| 125 | + end |
| 126 | + end |
| 127 | + |
| 128 | + # J3 term |
| 129 | + if J3 != 0 |
| 130 | + for i = 1:L |
| 131 | + for j = 1:L2-2+peri*2 |
| 132 | + add_edge!(J3, i, j, i, j + 2) |
| 133 | + end |
| 134 | + end |
| 135 | + for i = 1:L-2+peri*2 |
| 136 | + for j = 1:L2 |
| 137 | + add_edge!(J3, i, j, i + 2, j) |
| 138 | + end |
| 139 | + end |
| 140 | + end |
| 141 | + |
| 142 | + H = MPO(ampo, sites) |
| 143 | + |
| 144 | + dtype = cmpl ? ComplexF64 : Float64 |
| 145 | + psi = nothing |
| 146 | + if zero_mag |
| 147 | + L_half = div(L, 2) |
| 148 | + L2_half = div(L2, 2) |
| 149 | + state = ["Up", "Dn"] |
| 150 | + state = repeat(state, L2_half) |
| 151 | + if snake |
| 152 | + state = vcat(state, reverse(state)) |
| 153 | + else |
| 154 | + state = repeat(state, 2) |
| 155 | + end |
| 156 | + state = repeat(state, L_half) |
| 157 | + psi = randomMPS(dtype, sites, state; linkdims = max_B) |
| 158 | + else |
| 159 | + psi = randomMPS(dtype, sites; linkdims = max_B) |
| 160 | + end |
| 161 | + |
| 162 | + sweeps = Sweeps(max_step) |
| 163 | + setmaxdim!(sweeps, max_B) |
| 164 | + setcutoff!(sweeps, 1e-12) |
| 165 | + noise = 10 .^ LinRange(-3, -12, div(max_step, 2)) |
| 166 | + setnoise!(sweeps, noise..., 0) |
| 167 | + |
| 168 | + energy, psi = dmrg(H, psi, sweeps) |
| 169 | + @show energy |
| 170 | + |
| 171 | + h5open(out_filename, "w") do f |
| 172 | + write(f, "psi", dense(psi)) |
| 173 | + end |
| 174 | + |
| 175 | + GC.gc() |
| 176 | + |
| 177 | + H_sqr = real(inner(H, psi, H, psi)) |
| 178 | + energy_std = sqrt(H_sqr - energy^2) |
| 179 | + @show energy_std |
| 180 | + |
| 181 | + return sites, H, psi |
| 182 | +end |
0 commit comments