Skip to content

Commit

Permalink
Fix 2d heisenberg example and add error for bad unit cell inputs (#88)
Browse files Browse the repository at this point in the history
  • Loading branch information
ryanlevy authored Oct 14, 2024
1 parent 0e0494e commit fc1078a
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 7 deletions.
20 changes: 13 additions & 7 deletions examples/vumps/vumps_2d_heisenberg.jl
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ conserve_qns = true
solver_tol = (x -> x / 10)
outer_iters = 10 # Number of times to increase the bond dimension
width = 4
yperiodic = false # OBC vs cylinder

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

function ITensorInfiniteMPS.unit_cell_terms(::Model"heisenberg2D"; width)
function ITensorInfiniteMPS.unit_cell_terms(::Model"heisenberg2D"; width, yperiodic)
opsum = OpSum()
for i in 1:width
# Vertical
opsum += -0.5, "S+", i, "S-", mod(i + 1, width)
opsum += -0.5, "S-", i, "S+", mod(i + 1, width)
opsum += "Sz", i, "Sz", mod(i + 1, width)
opsum -= 0.5, "S+", i, "S-", i + 1
opsum -= 0.5, "S-", i, "S+", i + 1
opsum += "Sz", i, "Sz", i + 1
# Horizontal
opsum += -0.5, "S+", i, "S-", i + width
opsum += -0.5, "S-", i, "S+", i + width
opsum -= 0.5, "S+", i, "S-", i + width
opsum -= 0.5, "S-", i, "S+", i + width
opsum += "Sz", i, "Sz", i + width
end
if yperiodic
opsum -= 0.5, "S+", 1, "S-", width
opsum -= 0.5, "S-", 1, "S+", width
opsum += "Sz", 1, "Sz", width
end
return opsum
end
model = Model("heisenberg2D")

# Form the Hamiltonian
H = InfiniteSum{MPO}(model, s; width)
H = InfiniteSum{MPO}(model, s; width, yperiodic)

# Check translational invariance
# println("\nCheck translation invariance of the initial VUMPS state")
Expand Down
8 changes: 8 additions & 0 deletions src/models/models.jl
Original file line number Diff line number Diff line change
Expand Up @@ -245,6 +245,14 @@ function infinite_terms(opsum::OpSum; kwargs...)
# stores all terms starting on site `i`.
opsum_cell_dict = groupreduce(minimum ITensors.sites, +, opsum)
nsites = maximum(keys(opsum_cell_dict))
# check that we don't have terms we will ignore
dropped = filter(x -> x <= 0, keys(opsum_cell_dict))
if length(dropped) > 0
error(
"The input unit cell terms include terms that are being ignored on sites: $([d for d in dropped])",
)
end

# Assumes each site in the unit cell has a term
for j in 1:nsites
if !haskey(opsum_cell_dict, j)
Expand Down

0 comments on commit fc1078a

Please sign in to comment.