From 839cc8a93e125da3a38a4932b0f596177b29ef76 Mon Sep 17 00:00:00 2001 From: leburgel Date: Tue, 24 Nov 2026 14:50:31 +0100 Subject: [PATCH] Fix the interactions in qstate_clock MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Couple neighbouring legs W - S - E - N of the `W ⊗ S ← N ⊗ E` tensor instead of the opposite pairs. This broke in b608f72, which adapted the transfer matrices to MPSKit's new leg order but missed the clock tensor. Add tests against the Onsager free energy for q = 2 and q = 4. Co-Authored-By: Claude Opus 5.5 --- src/models/transfermatrices.jl | 13 ++++++++++-- test/qstate_clock.jl | 36 ++++++++++++++++++++++++++++++++++ 2 files changed, 47 insertions(+), 2 deletions(-) create mode 100644 test/qstate_clock.jl diff --git a/src/models/transfermatrices.jl b/src/models/transfermatrices.jl index 0f7fc54..494ccd7 100644 --- a/src/models/transfermatrices.jl +++ b/src/models/transfermatrices.jl @@ -111,7 +111,16 @@ end """ qstate_clock([elt::Type{<:Number}=ComplexF64], [symmetry::Type{<:Sector}=Trivial]; beta::Number=1.0, q::Integer=3) -MPO for the partition function of the two-dimensional discrete clock model with ``q`` states. +MPO for the partition function of the two-dimensional discrete clock model with ``q`` states, + +```math +\\mathcal{Z}(\\beta) = \\sum_{\\{s\\}} \\exp(-\\beta H(s)) \\text{ with } H(s) = -\\sum_{\\langle i, j \\rangle} \\cos\\left(\\frac{2\\pi (s_i - s_j)}{q}\\right), +``` + +where each classical spin can take the values ``s = 0, …, q - 1``. The spins live on the +legs of the MPO tensor, which carries the interactions between neighbouring legs +`W - S - E - N - W` (legs ordered as `W ⊗ S ← N ⊗ E`). Every tensor therefore contains two +spins, and the partition function per tensor is the square of the partition function per spin. """ function qstate_clock( elt::Type{<:Number} = ComplexF64, ::Type{Trivial} = Trivial; @@ -120,7 +129,7 @@ function qstate_clock( comega(d) = cos(2 * pi * d / q) O = zeros(elt, q, q, q, q) for i in 1:q, j in 1:q, k in 1:q, l in 1:q - O[i, j, k, l] = exp(beta * (comega(i - j) + comega(j - k) + comega(k - l) + comega(l - i))) + O[i, j, k, l] = exp(beta * (comega(i - j) + comega(j - l) + comega(l - k) + comega(k - i))) end return InfiniteMPO([TensorMap(O, ℂ^q * ℂ^q, ℂ^q * ℂ^q)]) diff --git a/test/qstate_clock.jl b/test/qstate_clock.jl new file mode 100644 index 0000000..456b733 --- /dev/null +++ b/test/qstate_clock.jl @@ -0,0 +1,36 @@ +using Test +using TensorKit +using QuadGK +using MPSKit +using MPSKitModels + +# Onsager free energy per spin of the 2D classical Ising model with coupling J = 1 +function classical_ising_free_energy(; beta) + k = 1 / sinh(2 * beta)^2 + F = quadgk( + θ -> log(cosh(2 * beta)^2 + 1 / k * sqrt(1 + k^2 - 2 * k * cos(2 * θ))), + 0, pi + )[1] + return -1 / beta * (log(2) / 2 + 1 / (2 * pi) * F) +end + +alg = VUMPS(; tol = 1.0e-10, maxiter = 100, verbosity = 0) + +# Every MPO tensor contains two spins, so the free energy per spin is -log(λ) / (2β). +function clock_free_energy(q, beta; D = 16) + O = qstate_clock(; beta, q) + ψ, envs, = leading_boundary(InfiniteMPS(ℂ^q, ℂ^D), O, alg) + λ = expectation_value(ψ, O, envs) + return -log(abs(λ)) / (2 * beta) +end + +@testset "q = 2 is the Ising model (β = $beta)" for beta in (0.3, 0.6) + @test clock_free_energy(2, beta) ≈ classical_ising_free_energy(; beta) atol = 1.0e-6 +end + +# cos(θ - θ') = (σσ' + ττ') / 2 for σ = cos θ + sin θ and τ = cos θ - sin θ, so the q = 4 clock +# model is two decoupled Ising models at half the coupling. +@testset "q = 4 is two Ising models (β = $beta)" for beta in (0.6, 1.2) + f_ising = classical_ising_free_energy(; beta = beta / 2) * (beta / 2) + @test clock_free_energy(4, beta) * beta ≈ 2 * f_ising atol = 1.0e-6 +end