Skip to content

Commit b2c370e

Browse files
authored
Add test for classical Ising model (#44)
1 parent 0e01ac3 commit b2c370e

File tree

6 files changed

+93
-68
lines changed

6 files changed

+93
-68
lines changed

Project.toml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,14 +16,16 @@ TupleTools = "9d95972d-f1c8-5527-a6e0-b4b365fa01f6"
1616
MPSKit = "0.12"
1717
MacroTools = "0.5"
1818
PrecompileTools = "1"
19+
QuadGK = "2.11.1"
1920
TensorKit = "0.13,0.14"
2021
TensorOperations = "5"
2122
TupleTools = "1"
2223
julia = "1.10"
2324

2425
[extras]
26+
QuadGK = "1fd47b50-473d-5c70-9696-f719f8f3bcdc"
2527
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"
2628
TestExtras = "5ed8adda-3752-4e41-b88a-e8b09835ee3a"
2729

2830
[targets]
29-
test = ["Test", "TestExtras"]
31+
test = ["Test", "TestExtras", "QuadGK"]

src/models/transfermatrices.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
MPO for the partition function of the two-dimensional classical Ising model, defined as
99
1010
```math
11-
\\mathcal{Z}(\\beta) = \\sum_{\\{s\\}} \\exp(-\\beta H(s)) \\text{ with } H(s) = \\sum_{\\langle i, j \\rangle} s_i s_j
11+
\\mathcal{Z}(\\beta) = \\sum_{\\{s\\}} \\exp(-\\beta H(s)) \\text{ with } H(s) = -\\sum_{\\langle i, j \\rangle} s_i s_j
1212
1313
```
1414
where each classical spin can take the values ``s = \\pm 1``.

test/classical_ising.jl

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
using Test
2+
using TensorKit
3+
using QuadGK
4+
using MPSKit
5+
using MPSKitModels
6+
7+
## Setup
8+
9+
beta = 0.6
10+
Vspaces = [ComplexSpace(12), Z2Space(0 => 6, 1 => 6)]
11+
alg = VUMPS(; tol=1e-8, maxiter=25, verbosity=1)
12+
13+
"""
14+
classical_ising_free_energy(; beta)
15+
16+
[Exact Onsager solution](https://en.wikipedia.org/wiki/Square_lattice_Ising_model#Exact_solution)
17+
for the free energy of the 2D classical Ising Model with partition function
18+
19+
```math
20+
\\mathcal{Z}(\\beta) = \\sum_{\\{s\\}} \\exp(-\\beta H(s)) \\text{ with } H(s) = - \\sum_{\\langle i, j \\rangle} s_i s_j
21+
```
22+
"""
23+
function classical_ising_free_energy(; beta=log(1 + sqrt(2)) / 2)
24+
k = 1 / sinh(2 * beta)^2
25+
F = quadgk(theta -> log(cosh(2 * beta)^2 +
26+
1 / k * sqrt(1 + k^2 - 2 * k * cos(2 * theta))),
27+
0, pi)[1]
28+
return -1 / beta * (log(2) / 2 + 1 / (2 * pi) * F)
29+
end
30+
31+
## Test
32+
33+
@testset "Classical Ising for $(sectortype(V)) symmetry" for V in Vspaces
34+
O = classical_ising(sectortype(V); beta)
35+
psi0 = InfiniteMPS(physicalspace(O, 1), V)
36+
psi, envs, = leading_boundary(psi0, O, alg)
37+
λ = expectation_value(psi, O, envs)
38+
f = -log(λ) / beta
39+
f_exact = classical_ising_free_energy(; beta)
40+
@test abs(f - f_exact) < 1e-4
41+
end

test/potts.jl

Lines changed: 0 additions & 66 deletions
This file was deleted.

test/quantum_potts.jl

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
using Test
2+
using TensorKit
3+
using MPSKit
4+
using MPSKitModels
5+
6+
## Setup
7+
8+
χ = 6
9+
qs = [3, 4, 5]
10+
symmetries = [Trivial, ZNIrrep]
11+
Vspaces = [ComplexSpace(12), Z2Space(0 => 6, 1 => 6)]
12+
alg = VUMPS(; maxiter=25, verbosity=0)
13+
14+
# https://iopscience.iop.org/article/10.1088/0305-4470/14/11/020/meta
15+
function quantum_potts_energy(Q::Int; maxiter::Int=1000)
16+
Q == 3 && return -(4 / 3 + 2sqrt(3) / π)
17+
Q == 4 && return 2 - 8 * log(2)
18+
summation = sum((-1)^n / (sqrt(Q) / 2 - cosh((2 * n + 1) * acosh(sqrt(Q) / 2)))
19+
for n in 1:maxiter)
20+
limit = 2 - Q - sqrt(Q) * (Q - 4) * summation
21+
return limit
22+
end
23+
24+
_sectortype(::Type{Trivial}, q::Int) = Trivial
25+
_sectortype(::Type{ZNIrrep}, q::Int) = ZNIrrep{q}
26+
_virtualspace(::Type{Trivial}, q::Int, χ::Int) = ComplexSpace(q * χ)
27+
_virtualspace(::Type{ZNIrrep}, q::Int, χ::Int) = Rep[ℤ{q}](i => χ for i in 0:(q - 1))
28+
29+
## Test
30+
31+
@testset "$q-state Potts with $(_sectortype(symmetry, q))) symmetry" for q in qs,
32+
symmetry in
33+
symmetries
34+
35+
H = quantum_potts(_sectortype(symmetry, q); q)
36+
ψ = InfiniteMPS(physicalspace(H, 1), _virtualspace(symmetry, q, χ))
37+
@test imag(expectation_value(ψ, H)) 0 atol = 1e-10
38+
ψ, envs, δ = find_groundstate(ψ, H, alg)
39+
@test quantum_potts_energy(q) expectation_value(ψ, H, envs) atol = 1e-2
40+
end

test/runtests.jl

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,14 @@ end
3737
include("heisenberg.jl")
3838
end
3939

40+
@testset "quantum potts model" begin
41+
include("quantum_potts.jl")
42+
end
43+
44+
@testset "classical ising model" begin
45+
include("classical_ising.jl")
46+
end
47+
4048
@testset "sixvertex model" begin
4149
include("sixvertex.jl")
4250
end

0 commit comments

Comments
 (0)