Package: MPSKitModels v0.4.7
File: src/lattices/snakepattern.jl
Two related problems with the cylinder ordering helpers.
1. backandforth_pattern / frontandback_pattern throw MethodError
Both build the index list as a lazy iterator and return a closure that indexes it:
# backandforth_pattern, lines 39–41
inds = Iterators.flatten((1:L, reverse((L+1):(2L))) .+ (L*(i-1)) for i in 1:2:N)
return pattern(i::Integer) = inds[i]
Iterators.flatten(...) returns a Base.Iterators.Flatten, which supports iteration but has no getindex, so the closure errors as soon as it is called (e.g. through linearize_index):
using MPSKitModels
cyl = InfiniteCylinder(4, 2) # L = 4, even period N = 2
backandforth_pattern(cyl)(1)
# ERROR: MethodError: no method matching getindex(::Base.Iterators.Flatten{…}, ::Int64)
frontandback_pattern has the identical defect at line 64. (Its even-L branch additionally does edge = L/2, a Float64, so 1:edge is a float range.)
Fix: materialize the iterator before indexing, e.g. inds = collect(Iterators.flatten(...)).
2. A finite SnakePattern permutation BoundsErrors on infinite lattices
A length-N permutation works on a FiniteCylinder but errors on an InfiniteCylinder, because nearest_neighbours emits bonds into the next unit cell (linear index > N):
perm = collect(1:12) # one unit cell of InfiniteCylinder(3, 4)
snake = SnakePattern(InfiniteCylinder(3, 4), i -> perm[i])
[linearize_index(snake, x) => linearize_index(snake, y) for (x, y) in nearest_neighbours(snake)]
# ERROR: BoundsError (bonds reference indices beyond one unit cell)
A pattern for an infinite lattice has to be defined for every integer and wrap periodically, e.g.
pattern(i) = ((i - 1) ÷ N) * N + perm[mod1(i, N)]
Once (1) is fixed the built-in helpers cover this, since they are meant to be functions of all indices; it may also be worth a docstring note that a SnakePattern on an infinite lattice must accept indices beyond one unit cell.
Package: MPSKitModels v0.4.7
File:
src/lattices/snakepattern.jlTwo related problems with the cylinder ordering helpers.
1.
backandforth_pattern/frontandback_patternthrowMethodErrorBoth build the index list as a lazy iterator and return a closure that indexes it:
Iterators.flatten(...)returns aBase.Iterators.Flatten, which supports iteration but has nogetindex, so the closure errors as soon as it is called (e.g. throughlinearize_index):frontandback_patternhas the identical defect at line 64. (Its even-Lbranch additionally doesedge = L/2, aFloat64, so1:edgeis a float range.)Fix: materialize the iterator before indexing, e.g.
inds = collect(Iterators.flatten(...)).2. A finite
SnakePatternpermutationBoundsErrors on infinite latticesA length-
Npermutation works on aFiniteCylinderbut errors on anInfiniteCylinder, becausenearest_neighboursemits bonds into the next unit cell (linear index> N):A pattern for an infinite lattice has to be defined for every integer and wrap periodically, e.g.
Once (1) is fixed the built-in helpers cover this, since they are meant to be functions of all indices; it may also be worth a docstring note that a
SnakePatternon an infinite lattice must accept indices beyond one unit cell.