From fc1078a60442081010447caf65c9a22c7278e4ce Mon Sep 17 00:00:00 2001 From: Ryan Levy Date: Mon, 14 Oct 2024 11:46:04 -0400 Subject: [PATCH] Fix 2d heisenberg example and add error for bad unit cell inputs (#88) --- examples/vumps/vumps_2d_heisenberg.jl | 20 +++++++++++++------- src/models/models.jl | 8 ++++++++ 2 files changed, 21 insertions(+), 7 deletions(-) diff --git a/examples/vumps/vumps_2d_heisenberg.jl b/examples/vumps/vumps_2d_heisenberg.jl index 968606d..f82c03c 100644 --- a/examples/vumps/vumps_2d_heisenberg.jl +++ b/examples/vumps/vumps_2d_heisenberg.jl @@ -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 @@ -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") diff --git a/src/models/models.jl b/src/models/models.jl index 206defd..e159175 100644 --- a/src/models/models.jl +++ b/src/models/models.jl @@ -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)