Skip to content

Commit fc1078a

Browse files
authored
Fix 2d heisenberg example and add error for bad unit cell inputs (#88)
1 parent 0e0494e commit fc1078a

File tree

2 files changed

+21
-7
lines changed

2 files changed

+21
-7
lines changed

examples/vumps/vumps_2d_heisenberg.jl

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ conserve_qns = true
1919
solver_tol = (x -> x / 10)
2020
outer_iters = 10 # Number of times to increase the bond dimension
2121
width = 4
22+
yperiodic = false # OBC vs cylinder
2223

2324
##############################################################################
2425
# CODE BELOW HERE DOES NOT NEED TO BE MODIFIED
@@ -30,24 +31,29 @@ initstate(n) = isodd(n) ? "↑" : "↓"
3031
s = infsiteinds("S=1/2", N; conserve_qns, initstate)
3132
ψ = InfMPS(s, initstate)
3233

33-
function ITensorInfiniteMPS.unit_cell_terms(::Model"heisenberg2D"; width)
34+
function ITensorInfiniteMPS.unit_cell_terms(::Model"heisenberg2D"; width, yperiodic)
3435
opsum = OpSum()
3536
for i in 1:width
3637
# Vertical
37-
opsum += -0.5, "S+", i, "S-", mod(i + 1, width)
38-
opsum += -0.5, "S-", i, "S+", mod(i + 1, width)
39-
opsum += "Sz", i, "Sz", mod(i + 1, width)
38+
opsum -= 0.5, "S+", i, "S-", i + 1
39+
opsum -= 0.5, "S-", i, "S+", i + 1
40+
opsum += "Sz", i, "Sz", i + 1
4041
# Horizontal
41-
opsum += -0.5, "S+", i, "S-", i + width
42-
opsum += -0.5, "S-", i, "S+", i + width
42+
opsum -= 0.5, "S+", i, "S-", i + width
43+
opsum -= 0.5, "S-", i, "S+", i + width
4344
opsum += "Sz", i, "Sz", i + width
4445
end
46+
if yperiodic
47+
opsum -= 0.5, "S+", 1, "S-", width
48+
opsum -= 0.5, "S-", 1, "S+", width
49+
opsum += "Sz", 1, "Sz", width
50+
end
4551
return opsum
4652
end
4753
model = Model("heisenberg2D")
4854

4955
# Form the Hamiltonian
50-
H = InfiniteSum{MPO}(model, s; width)
56+
H = InfiniteSum{MPO}(model, s; width, yperiodic)
5157

5258
# Check translational invariance
5359
# println("\nCheck translation invariance of the initial VUMPS state")

src/models/models.jl

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -245,6 +245,14 @@ function infinite_terms(opsum::OpSum; kwargs...)
245245
# stores all terms starting on site `i`.
246246
opsum_cell_dict = groupreduce(minimum ITensors.sites, +, opsum)
247247
nsites = maximum(keys(opsum_cell_dict))
248+
# check that we don't have terms we will ignore
249+
dropped = filter(x -> x <= 0, keys(opsum_cell_dict))
250+
if length(dropped) > 0
251+
error(
252+
"The input unit cell terms include terms that are being ignored on sites: $([d for d in dropped])",
253+
)
254+
end
255+
248256
# Assumes each site in the unit cell has a term
249257
for j in 1:nsites
250258
if !haskey(opsum_cell_dict, j)

0 commit comments

Comments
 (0)