From 84ed841d90aa85740f5481687c5063146f062af9 Mon Sep 17 00:00:00 2001 From: victor Date: Fri, 11 Apr 2025 15:46:38 +0200 Subject: [PATCH 01/13] fix typos --- src/lattices/squarelattice.jl | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/lattices/squarelattice.jl b/src/lattices/squarelattice.jl index 52a85ae..09bb43c 100644 --- a/src/lattices/squarelattice.jl +++ b/src/lattices/squarelattice.jl @@ -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 @@ -39,7 +39,7 @@ Base.isfinite(::Type{InfiniteStrip}) = false """ 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 @@ -79,7 +79,7 @@ Base.isfinite(::Type{InfiniteCylinder}) = false """ 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 From 3f84626bc48838fae04e994623726bfba5f21a00 Mon Sep 17 00:00:00 2001 From: victor Date: Fri, 11 Apr 2025 15:49:52 +0200 Subject: [PATCH 02/13] unpack `nearest_neighbours` iterators --- src/lattices/squarelattice.jl | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/lattices/squarelattice.jl b/src/lattices/squarelattice.jl index 09bb43c..1fcbe00 100644 --- a/src/lattices/squarelattice.jl +++ b/src/lattices/squarelattice.jl @@ -153,7 +153,7 @@ function nearest_neighbours(lattice::FiniteStrip) 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...] end function nearest_neighbours(lattice::FiniteCylinder) rows = lattice.L @@ -162,7 +162,7 @@ function nearest_neighbours(lattice::FiniteCylinder) 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 @@ -171,7 +171,7 @@ function nearest_neighbours(lattice::FiniteHelix) 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...] end function nearest_neighbours(lattice::Union{InfiniteStrip,InfiniteCylinder,InfiniteHelix}) V = vertices(lattice) From febf91c3a0e976036ef28bf36e92a07b5baf8956 Mon Sep 17 00:00:00 2001 From: victor Date: Fri, 11 Apr 2025 15:53:35 +0200 Subject: [PATCH 03/13] add generic `next_nearest_neighbours` for 2D `AbstractLattice`s Co-authored-by: Lukas Devos --- src/lattices/squarelattice.jl | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/lattices/squarelattice.jl b/src/lattices/squarelattice.jl index 1fcbe00..4fd8ac2 100644 --- a/src/lattices/squarelattice.jl +++ b/src/lattices/squarelattice.jl @@ -187,6 +187,11 @@ function nearest_neighbours(lattice::Union{InfiniteStrip,InfiniteCylinder,Infini 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) From 8b59130124a075681760037bab98acba25964152 Mon Sep 17 00:00:00 2001 From: victor Date: Fri, 11 Apr 2025 16:15:45 +0200 Subject: [PATCH 04/13] format --- src/lattices/squarelattice.jl | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/lattices/squarelattice.jl b/src/lattices/squarelattice.jl index 4fd8ac2..5882d4a 100644 --- a/src/lattices/squarelattice.jl +++ b/src/lattices/squarelattice.jl @@ -188,8 +188,12 @@ function nearest_neighbours(lattice::Union{InfiniteStrip,InfiniteCylinder,Infini 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))...)) + 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, From 94f6cab092a71cde9acc15b2ccdece5fbe9245e4 Mon Sep 17 00:00:00 2001 From: victor Date: Fri, 11 Apr 2025 16:16:14 +0200 Subject: [PATCH 05/13] force formatcheck CI to use JuliaFormatter v1.0.62, v2 seems broken --- .github/workflows/FormatCheck.yml | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/.github/workflows/FormatCheck.yml b/.github/workflows/FormatCheck.yml index 5e0277a..aa42ed3 100644 --- a/.github/workflows/FormatCheck.yml +++ b/.github/workflows/FormatCheck.yml @@ -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 From 039fa237706548ac07f5e12d445c690d72f9733d Mon Sep 17 00:00:00 2001 From: victor Date: Fri, 11 Apr 2025 16:16:33 +0200 Subject: [PATCH 06/13] add test for `FiniteCylinder` --- test/lattices.jl | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/test/lattices.jl b/test/lattices.jl index a28c849..72d5d48 100644 --- a/test/lattices.jl +++ b/test/lattices.jl @@ -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 From c45b47b60514dcc43ed9f5342e77bb8641071939 Mon Sep 17 00:00:00 2001 From: victor Date: Fri, 11 Apr 2025 16:16:59 +0200 Subject: [PATCH 07/13] export `FiniteCylinder` --- src/MPSKitModels.jl | 1 + 1 file changed, 1 insertion(+) diff --git a/src/MPSKitModels.jl b/src/MPSKitModels.jl index e8b05f3..4048144 100644 --- a/src/MPSKitModels.jl +++ b/src/MPSKitModels.jl @@ -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 From c37b929dab0e378e0a7e83a8e6b5b70967878638 Mon Sep 17 00:00:00 2001 From: victor Date: Sat, 12 Apr 2025 11:58:51 +0200 Subject: [PATCH 08/13] relax version requirement for JuliaFormatter in formatcheck CI --- .github/workflows/FormatCheck.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/FormatCheck.yml b/.github/workflows/FormatCheck.yml index aa42ed3..2838990 100644 --- a/.github/workflows/FormatCheck.yml +++ b/.github/workflows/FormatCheck.yml @@ -29,7 +29,7 @@ jobs: - uses: actions/checkout@v4 - name: Install JuliaFormatter and format run: | - julia -e 'using Pkg; Pkg.add(PackageSpec(name="JuliaFormatter", version="v1.0.62"))' + julia -e 'using Pkg; Pkg.add(PackageSpec(name="JuliaFormatter", version="v1"))' julia -e 'using JuliaFormatter; format(".", verbose=true)' - name: Format check id: format From cfe1836dabd89edf7185c07de9c38e65dd2edfff Mon Sep 17 00:00:00 2001 From: victor Date: Sat, 12 Apr 2025 12:00:06 +0200 Subject: [PATCH 09/13] clarify docstring of `FiniteStrip` --- src/lattices/squarelattice.jl | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/lattices/squarelattice.jl b/src/lattices/squarelattice.jl index 5882d4a..27b69fc 100644 --- a/src/lattices/squarelattice.jl +++ b/src/lattices/squarelattice.jl @@ -1,7 +1,9 @@ """ FiniteStrip(L::Int, N::Int) -A finite strip with `L` sites per rung and `N` sites per unit cell. +A finite strip with a width of `L` and a total number of `N` sites. + +This representes an `L` by `N÷L` rectangular patch. """ struct FiniteStrip <: AbstractLattice{2} L::Int From ee4ee3e1950ed20e58e1026019e48a9ab0f8700d Mon Sep 17 00:00:00 2001 From: victor Date: Sun, 13 Apr 2025 15:10:45 +0200 Subject: [PATCH 10/13] update docstring for `FiniteHelix` and `FiniteCylinder` --- src/lattices/squarelattice.jl | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/lattices/squarelattice.jl b/src/lattices/squarelattice.jl index 27b69fc..1bdb7b5 100644 --- a/src/lattices/squarelattice.jl +++ b/src/lattices/squarelattice.jl @@ -41,7 +41,7 @@ Base.isfinite(::Type{InfiniteStrip}) = false """ FiniteCylinder(L::Int, N::Int) -A finite cylinder with `L` sites per rung and `N` sites per unit cell. +A cylinder with circumference `L` and `N` sites in total. """ struct FiniteCylinder <: AbstractLattice{2} L::Int @@ -81,7 +81,7 @@ Base.isfinite(::Type{InfiniteCylinder}) = false """ FiniteHelix(L::Integer, N::Integer) -A finite helix with `L` sites per rung and `N` sites per unit cell. +A finite helix with `L` sites per rung and `N` sites in total. """ struct FiniteHelix <: AbstractLattice{2} L::Int From adf90df294015c06cdeb5e2df3521a1b219e7ad0 Mon Sep 17 00:00:00 2001 From: victor Date: Mon, 14 Apr 2025 09:38:20 +0200 Subject: [PATCH 11/13] add FiniteStrip Tests --- test/lattices.jl | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/test/lattices.jl b/test/lattices.jl index 72d5d48..81c1bfb 100644 --- a/test/lattices.jl +++ b/test/lattices.jl @@ -177,3 +177,27 @@ end end end end + +@testset "FiniteStrip" begin + for L in 2:8, n in 2:4 + N = n*L + lattice = FiniteStrip(L, N) + V = vertices(lattice) + + # Test the number of vertices + @test length(lattice) == length(V) == N + + # Test the first vertex + @test lattice[1, 1] == first(V) + + # Test nearest neighbors + NN = nearest_neighbours(lattice) + @test length(NN) == 2N - L - n # coordination number 4 - edge effects + @test allunique(NN) + + # Test next-nearest neighbors + NNN = next_nearest_neighbours(lattice) + @test length(NNN) == 2N - 2L - (2n - 2) # coordination number 4 - edge effects + @test allunique(NNN) + end +end From 5f4a0b8edf195b9d1790fda9dff3d7ba1564c235 Mon Sep 17 00:00:00 2001 From: victor Date: Mon, 14 Apr 2025 09:39:44 +0200 Subject: [PATCH 12/13] export `FiniteStrip` --- src/MPSKitModels.jl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/MPSKitModels.jl b/src/MPSKitModels.jl index 4048144..64e8064 100644 --- a/src/MPSKitModels.jl +++ b/src/MPSKitModels.jl @@ -11,7 +11,7 @@ using LinearAlgebra: LinearAlgebra export AbstractLattice export InfiniteChain, FiniteChain export InfiniteCylinder, InfiniteHelix, InfiniteStrip, InfiniteLadder -export FiniteCylinder +export FiniteCylinder, FiniteStrip export HoneycombXC, HoneycombYC export LatticePoint, linearize_index export vertices, nearest_neighbours, next_nearest_neighbours, bipartition From d4ead69a68fc94909999b7b6d451bff2db80f948 Mon Sep 17 00:00:00 2001 From: victor Date: Mon, 14 Apr 2025 09:39:58 +0200 Subject: [PATCH 13/13] format --- test/lattices.jl | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/test/lattices.jl b/test/lattices.jl index 81c1bfb..a467d3a 100644 --- a/test/lattices.jl +++ b/test/lattices.jl @@ -180,7 +180,7 @@ end @testset "FiniteStrip" begin for L in 2:8, n in 2:4 - N = n*L + N = n * L lattice = FiniteStrip(L, N) V = vertices(lattice) @@ -197,7 +197,7 @@ end # Test next-nearest neighbors NNN = next_nearest_neighbours(lattice) - @test length(NNN) == 2N - 2L - (2n - 2) # coordination number 4 - edge effects + @test length(NNN) == 2N - 2L - (2n - 2) # coordination number 4 - edge effects @test allunique(NNN) end end