QuantumKitHub / MPSKitModels.jl

MIT License
15 stars 13 forks source link

An error about nearest_neighbours function #15

Closed xiaohanyangggg closed 4 months ago

xiaohanyangggg commented 4 months ago

There is a small bug in the function nearest_neighbours(lattice::Union{InfiniteStrip,InfiniteCylinder,InfiniteHelix}). When one calls this function to get the nearest neighbouring bonds of a strip geometry, he will be given some errors. The example is as follows:

julia> using MPSKitModels
julia> Lattice = InfiniteStrip(8)
InfiniteStrip(8, 8)
julia> neighbours = nearest_neighbours(Lattice)
ERROR: BoundsError: attempt to access InfiniteStrip at index [0, 1]
Stacktrace:
 [1] checkbounds
   @ D:\code\julia_code\MPSKitModels.jl-0.3.0\src\lattices\lattices.jl:47 [inlined]
 [2] LatticePoint
   @ D:\code\julia_code\MPSKitModels.jl-0.3.0\src\lattices\latticepoints.jl:10 [inlined]
 [3] +
   @ D:\code\julia_code\MPSKitModels.jl-0.3.0\src\lattices\latticepoints.jl:47 [inlined]
 [4] nearest_neighbours(lattice::InfiniteStrip)
   @ MPSKitModels D:\code\julia_code\MPSKitModels.jl-0.3.0\src\lattices\squarelattice.jl:78
 [5] top-level scope
   @ REPL[32]:1

If one prints the InfiniteStrip instance, the result is:

julia> for v in V
          push!(V_list, v)
       end
julia> print(V_list)
Any[InfiniteStrip(8, 8)[1, 1], InfiniteStrip(8, 8)[2, 1], InfiniteStrip(8, 8)[3, 1], InfiniteStrip(8, 8)[4, 1], InfiniteStrip(8, 8)[5, 1], 
InfiniteStrip(8, 8)[6, 1], InfiniteStrip(8, 8)[7, 1], InfiniteStrip(8, 8)[8, 1]]

Since in nearest_neighbours(lattice::Union{InfiniteStrip,InfiniteCylinder,InfiniteHelix}) we will add a vertex in the InfiniteStrip by (0, 1), the error will happen.

lkdvos commented 4 months ago

Thanks for the report! I think as soon as the tests turn green, this should be fixed, and I'll look into tagging a new version asap