Skip to content
Merged
Show file tree
Hide file tree
Changes from 7 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 1 addition & 4 deletions .github/workflows/FormatCheck.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,8 @@ jobs:

- uses: actions/checkout@v4
- name: Install JuliaFormatter and format
# This will use the latest version by default but you can set the version like so:
#
# julia -e 'using Pkg; Pkg.add(PackageSpec(name="JuliaFormatter", version="0.13.0"))'
run: |
julia -e 'using Pkg; Pkg.add(PackageSpec(name="JuliaFormatter"))'
julia -e 'using Pkg; Pkg.add(PackageSpec(name="JuliaFormatter", version="v1.0.62"))'
julia -e 'using JuliaFormatter; format(".", verbose=true)'
- name: Format check
id: format
Expand Down
1 change: 1 addition & 0 deletions src/MPSKitModels.jl
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ using LinearAlgebra: LinearAlgebra
export AbstractLattice
export InfiniteChain, FiniteChain
export InfiniteCylinder, InfiniteHelix, InfiniteStrip, InfiniteLadder
export FiniteCylinder
export HoneycombXC, HoneycombYC
export LatticePoint, linearize_index
export vertices, nearest_neighbours, next_nearest_neighbours, bipartition
Expand Down
21 changes: 15 additions & 6 deletions src/lattices/squarelattice.jl
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
"""
FiniteStrip(L::Int, N::Int)

An finite strip with `L` sites per rung and `N` sites per unit cell.
A finite strip with `L` sites per rung and `N` sites per unit cell.
"""
struct FiniteStrip <: AbstractLattice{2}
L::Int
Expand Down Expand Up @@ -39,7 +39,7 @@
"""
FiniteCylinder(L::Int, N::Int)

An finite cylinder with `L` sites per rung and `N` sites per unit cell.
A finite cylinder with `L` sites per rung and `N` sites per unit cell.
"""
struct FiniteCylinder <: AbstractLattice{2}
L::Int
Expand Down Expand Up @@ -79,7 +79,7 @@
"""
FiniteHelix(L::Integer, N::Integer)

An finite helix with `L` sites per rung and `N` sites per unit cell.
A finite helix with `L` sites per rung and `N` sites per unit cell.
"""
struct FiniteHelix <: AbstractLattice{2}
L::Int
Expand Down Expand Up @@ -153,7 +153,7 @@
for i in 1:rows, j in 1:(cols - 1))
vertical = (LatticePoint((i, j), lattice) => LatticePoint((i + 1, j), lattice)
for i in 1:(rows - 1), j in 1:cols)
return Iterators.flatten((horizontal, vertical))
return [horizontal..., vertical...]

Check warning on line 156 in src/lattices/squarelattice.jl

View check run for this annotation

Codecov / codecov/patch

src/lattices/squarelattice.jl#L156

Added line #L156 was not covered by tests
end
function nearest_neighbours(lattice::FiniteCylinder)
rows = lattice.L
Expand All @@ -162,7 +162,7 @@
for i in 1:rows, j in 1:(cols - 1))
vertical = (LatticePoint((i, j), lattice) => LatticePoint((i + 1, j), lattice)
for i in 1:rows, j in 1:cols)
return Iterators.flatten((horizontal, vertical))
return [horizontal..., vertical...]
end
function nearest_neighbours(lattice::FiniteHelix)
rows = lattice.L
Expand All @@ -171,7 +171,7 @@
for i in 1:rows, j in 1:(cols - 1))
vertical = (LatticePoint((i, j), lattice) => LatticePoint((i + 1, j), lattice)
for i in 1:rows, j in 1:cols if (i != rows && j != cols))
return Iterators.flatten((horizontal, vertical))
return [horizontal..., vertical...]

Check warning on line 174 in src/lattices/squarelattice.jl

View check run for this annotation

Codecov / codecov/patch

src/lattices/squarelattice.jl#L174

Added line #L174 was not covered by tests
end
function nearest_neighbours(lattice::Union{InfiniteStrip,InfiniteCylinder,InfiniteHelix})
V = vertices(lattice)
Expand All @@ -187,6 +187,15 @@
return neighbours
end

function next_nearest_neighbours(lattice::AbstractLattice{2})
diag1 = (i => i + (1, 1) for i in vertices(lattice) if checkbounds(Bool, lattice,
(i.coordinates .+
(1, 1))...))
diag2 = (i => i + (1, -1) for i in vertices(lattice) if checkbounds(Bool, lattice,
(i.coordinates .+
(1, -1))...))
return [diag1..., diag2...]
end
function next_nearest_neighbours(lattice::Union{InfiniteStrip,InfiniteCylinder,
InfiniteHelix})
V = vertices(lattice)
Expand Down
25 changes: 25 additions & 0 deletions test/lattices.jl
Original file line number Diff line number Diff line change
Expand Up @@ -152,3 +152,28 @@ end
@test_throws ArgumentError HoneycombYC(3)
@test_throws ArgumentError HoneycombYC(4, 6)
end

@testset "FiniteCylinder" begin
for L in 2:5
lattice = FiniteCylinder(L)
@test length(nearest_neighbours(lattice)) == L
@test length(next_nearest_neighbours(lattice)) == 0
for n in 2:4
lattice = FiniteCylinder(L, n * L)
V = vertices(lattice)
@test length(lattice) == length(V) == n * L
@test lattice[1, 1] == first(V)

NN = nearest_neighbours(lattice)
@test length(NN) == 2 * n * L - L
@test allunique(NN)

NNN = next_nearest_neighbours(lattice)
@test length(NNN) == 2 * (n - 1) * L

@test allunique(NNN)

@test_throws ArgumentError FiniteCylinder(L, n * L + 1)
end
end
end
Loading