Skip to content

Commit 29e7d24

Browse files
Switch formatting to Runic (#72)
* format using runic * update format workflow * format * remove juliaformatter toml file * move code * small type changes to ising constants * add newline * manual formatting changes for looptnr * remove default `run` function * format blocking.jl * format cft.jl * remove defaults.jl * format projectors.jl
1 parent 9631026 commit 29e7d24

31 files changed

Lines changed: 596 additions & 502 deletions

.JuliaFormatter.toml

Lines changed: 0 additions & 1 deletion
This file was deleted.

.github/workflows/FormatCheck.yml

Lines changed: 6 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -5,43 +5,13 @@ on:
55
branches:
66
- 'main'
77
- 'master'
8-
- 'release-'
98
tags: '*'
109
pull_request:
10+
branches:
11+
- 'main'
12+
- 'master'
1113

1214
jobs:
13-
build:
14-
runs-on: ${{ matrix.os }}
15-
strategy:
16-
matrix:
17-
version:
18-
- '1' # automatically expands to the latest stable 1.x release of Julia
19-
os:
20-
- ubuntu-latest
21-
arch:
22-
- x64
23-
steps:
24-
- uses: julia-actions/setup-julia@latest
25-
with:
26-
version: ${{ matrix.version }}
27-
arch: ${{ matrix.arch }}
28-
29-
- uses: actions/checkout@v4
30-
- name: Install JuliaFormatter and format
31-
# This will use the latest version by default but you can set the version like so:
32-
#
33-
# julia -e 'using Pkg; Pkg.add(PackageSpec(name="JuliaFormatter", version="0.13.0"))'
34-
run: |
35-
julia -e 'using Pkg; Pkg.add(PackageSpec(name="JuliaFormatter"))'
36-
julia -e 'using JuliaFormatter; format(".", verbose=true)'
37-
- name: Format check
38-
run: |
39-
julia -e '
40-
out = Cmd(`git diff --name-only`) |> read |> String
41-
if out == ""
42-
exit(0)
43-
else
44-
@error "Some files have not been formatted !!!"
45-
write(stdout, out)
46-
exit(1)
47-
end'
15+
formatcheck:
16+
name: "Format Check"
17+
uses: "QuantumKitHub/QuantumKitHubActions/.github/workflows/FormatCheck.yml@main"

docs/make.jl

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,16 @@ using Documenter
33
using DocumenterCitations
44

55
bibpath = joinpath(@__DIR__, "src", "assets", "tnrkit.bib")
6-
bib = CitationBibliography(bibpath; style=:authoryear)
6+
bib = CitationBibliography(bibpath; style = :authoryear)
77

8-
makedocs(; sitename="TNRKit.jl",
9-
pages=["Home" => "index.md"
10-
"Library" => "lib/lib.md"
11-
"References" => "references.md"],
12-
plugins=[bib])
8+
makedocs(;
9+
sitename = "TNRKit.jl",
10+
pages = [
11+
"Home" => "index.md"
12+
"Library" => "lib/lib.md"
13+
"References" => "references.md"
14+
],
15+
plugins = [bib]
16+
)
1317

14-
deploydocs(; repo="github.com/VictorVanthilt/TNRKit.jl.git", push_preview=true)
18+
deploydocs(; repo = "github.com/VictorVanthilt/TNRKit.jl.git", push_preview = true)

examples/example.jl

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,16 @@ using Revise, TensorKit, TNRKit
44
trg_f(steps::Int, data) = abs(log(data[end]) * 2.0^(-steps))
55

66
# stop when converged or after 50 steps, whichever comes first
7-
stopping_criterion = convcrit(1e-16, trg_f) & maxiter(20)
7+
stopping_criterion = convcrit(1.0e-16, trg_f) & maxiter(20)
88

99
# choose a TensorKit truncation scheme
10-
trunc = truncdim(16) & truncbelow(1e-40)
10+
trunc = truncdim(16) & truncbelow(1.0e-40)
1111

1212
# initialize the TRG scheme
1313
scheme = TRG(classical_ising(1.0))
1414

1515
# run the TRG scheme (and normalize and store the norm in the beginning (finalize_beginning=true))
16-
data = run!(scheme, trunc, stopping_criterion; finalize_beginning=true)
16+
data = run!(scheme, trunc, stopping_criterion; finalize_beginning = true)
1717
# or: data = run!(scheme, truncdim(16)), this will default to maxiter(100)
1818

1919
# initialize the BTRG scheme

src/TNRKit.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ export run!
5252
# models
5353
include("models/ising.jl")
5454
export classical_ising, classical_ising_symmetric, ising_βc, f_onsager,
55-
ising_βc_3D, classical_ising_symmetric_3D, classical_ising_3D
55+
ising_βc_3D, classical_ising_symmetric_3D, classical_ising_3D
5656

5757
include("models/gross-neveu.jl")
5858
export gross_neveu_start

src/models/gross-neveu.jl

Lines changed: 27 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,50 +1,50 @@
1-
#! format: off
21
function P_tensor()
32
P = zeros(ComplexF64, 2, 2, 2, 2, 2, 2, 2, 2)
43
for (pi1, pj1, pi2, pj2, i1, j1, i2, j2) in Iterators.product([0:1 for _ in 1:8]...)
5-
P[pi1+1, pj1+1, pi2+1, pj2+1, i1+1, j1+1, i2+1, j2+1] =
4+
P[pi1 + 1, pj1 + 1, pi2 + 1, pj2 + 1, i1 + 1, j1 + 1, i2 + 1, j2 + 1] =
65
i1 * (j1 + j2 + pi1 + pi2) + i2 * (j2 + pi1 + pi2) + pj1 * (pi1 + pi2) + pj2 * pi2 + pi1 + pi2
76
end
87
return P
98
end
109

11-
# Manually defining the A and A_bar tensors
12-
A = zeros(ComplexF64, 2, 2, 2, 2)
13-
A[2, 2, 1, 1] = 1 + 1im
14-
A[1, 1, 2, 2] = -1 - 1im
15-
A[2, 1, 1, 2] = 1 - 1im
16-
A[2, 1, 2, 1] = 2
17-
A[1, 2, 1, 2] = -2im
18-
A[1, 2, 2, 1] = 1 - 1im
19-
20-
A_bar = zeros(ComplexF64, 2, 2, 2, 2)
21-
A_bar[2, 2, 1, 1] = -1 + 1im
22-
A_bar[1, 1, 2, 2] = 1 - 1im
23-
A_bar[2, 1, 1, 2] = -1 - 1im
24-
A_bar[2, 1, 2, 1] = -2
25-
A_bar[1, 2, 1, 2] = -2im
26-
A_bar[1, 2, 2, 1] = -1 - 1im
27-
2810
function gross_neveu_8_leg_tensor::Number, m::Number, g::Number)
11+
# Manually defining the A and A_bar tensors
12+
A = zeros(ComplexF64, 2, 2, 2, 2)
13+
A[2, 2, 1, 1] = 1 + 1im
14+
A[1, 1, 2, 2] = -1 - 1im
15+
A[2, 1, 1, 2] = 1 - 1im
16+
A[2, 1, 2, 1] = 2
17+
A[1, 2, 1, 2] = -2im
18+
A[1, 2, 2, 1] = 1 - 1im
19+
20+
A_bar = zeros(ComplexF64, 2, 2, 2, 2)
21+
A_bar[2, 2, 1, 1] = -1 + 1im
22+
A_bar[1, 1, 2, 2] = 1 - 1im
23+
A_bar[2, 1, 1, 2] = -1 - 1im
24+
A_bar[2, 1, 2, 1] = -2
25+
A_bar[1, 2, 1, 2] = -2im
26+
A_bar[1, 2, 2, 1] = -1 - 1im
27+
2928
# Utility Kronecker delta function
3029
δ(x, y) = ==(x, y)
3130

3231
T = zeros(ComplexF64, 2, 2, 2, 2, 2, 2, 2, 2)
3332
P = P_tensor()
3433
V = Vect[FermionParity](0 => 1, 1 => 1)
3534
for (pi1, pj1, pi2, pj2, i1, j1, i2, j2) in Iterators.product([0:1 for _ in 1:8]...)
36-
p = P[pi1+1, pj1+1, pi2+1, pj2+1, i1+1, j1+1, i2+1, j2+1]
37-
T[pi1+1, pj1+1, pi2+1, pj2+1, i2+1, j2+1, i1+1, j1+1] =
35+
p = P[pi1 + 1, pj1 + 1, pi2 + 1, pj2 + 1, i1 + 1, j1 + 1, i2 + 1, j2 + 1]
36+
T[pi1 + 1, pj1 + 1, pi2 + 1, pj2 + 1, i2 + 1, j2 + 1, i1 + 1, j1 + 1] =
3837
((-1)^p) * exp(0.5 * μ * (i2 - j2 + pi2 - pj2)) * ((1 / sqrt(2))^(i1 + i2 + j1 + j2 + pi1 + pi2 + pj1 + pj2)) *
39-
(((m + 2)^2 + 2 * g^2) * δ(i1 + i2 + pj1 + pj2, 0) * δ(j1 + j2 + pi1 + pi2, 0) -
40-
(m + 2) * δ(i1 + i2 + pj1 + pj2, 1) * δ(j1 + j2 + pi1 + pi2, 1) -
41-
((-1)^(i1 + i2 + j2 + pi1)) * (1im^(i2 + j2 + pi2 + pj2)) * (m + 2) * δ(i1 + i2 + pj1 + pj2, 1) * δ(j1 + j2 + pi1 + pi2, 1) -
42-
A_bar[i1+1, i2+1, pj1+1, pj2+1] * A[j1+1, j2+1, pi1+1, pi2+1])
38+
(
39+
((m + 2)^2 + 2 * g^2) * δ(i1 + i2 + pj1 + pj2, 0) * δ(j1 + j2 + pi1 + pi2, 0) -
40+
(m + 2) * δ(i1 + i2 + pj1 + pj2, 1) * δ(j1 + j2 + pi1 + pi2, 1) -
41+
((-1)^(i1 + i2 + j2 + pi1)) * (1im^(i2 + j2 + pi2 + pj2)) * (m + 2) * δ(i1 + i2 + pj1 + pj2, 1) * δ(j1 + j2 + pi1 + pi2, 1) -
42+
A_bar[i1 + 1, i2 + 1, pj1 + 1, pj2 + 1] * A[j1 + 1, j2 + 1, pi1 + 1, pi2 + 1]
43+
)
4344

4445
end
4546
return TensorMap(T, V V V V V V V V)
4647
end
47-
#! format: on
4848

4949
function gross_neveu_start::Number, m::Number, g::Number)
5050
T_unfused = gross_neveu_8_leg_tensor(μ, m, g)
@@ -53,7 +53,7 @@ function gross_neveu_start(μ::Number, m::Number, g::Number)
5353
Udg = adjoint(U)
5454

5555
@tensor T_fused[-1 -2; -3 -4] := T_unfused[1 2 3 4; 5 6 7 8] * U[-1; 1 2] * U[-2; 3 4] *
56-
Udg[5 6; -3] * Udg[7 8; -4]
56+
Udg[5 6; -3] * Udg[7 8; -4]
5757

5858
# restore the TNRKit.jl convention
5959
return T_fused

src/models/ising.jl

Lines changed: 20 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,21 @@
1-
const ising_βc = BigFloat(log(1.0 + sqrt(2)) / 2.0)
2-
const ising_cft_exact = [1 / 8, 1, 9 / 8, 9 / 8, 2, 2, 2, 2, 17 / 8, 17 / 8, 17 / 8, 3, 3,
3-
3, 3, 3,
4-
25 / 8, 25 / 8, 25 / 8, 25 / 8, 25 / 8, 25 / 8]
5-
function classical_ising::Number; h=0)
1+
const ising_βc = BigFloat(log(BigFloat(1.0) + sqrt(BigFloat(2.0))) / BigFloat(2.0))
2+
const ising_cft_exact = [
3+
1 / 8, 1, 9 / 8, 9 / 8, 2, 2, 2, 2, 17 / 8, 17 / 8, 17 / 8, 3, 3,
4+
3, 3, 3,
5+
25 / 8, 25 / 8, 25 / 8, 25 / 8, 25 / 8, 25 / 8,
6+
]
7+
function classical_ising::Number; h = 0)
68
function σ(i::Int64)
79
return 2i - 3
810
end
911

10-
T_array = Float64[exp* (σ(i)σ(j) + σ(j)σ(l) + σ(l)σ(k) + σ(k)σ(i)) +
11-
h / 2 * β * (σ(i) + σ(j) + σ(k) + σ(l)))
12-
for i in 1:2, j in 1:2, k in 1:2, l in 1:2]
12+
T_array = Float64[
13+
exp(
14+
β * (σ(i)σ(j) + σ(j)σ(l) + σ(l)σ(k) + σ(k)σ(i)) +
15+
h / 2 * β * (σ(i) + σ(j) + σ(k) + σ(l))
16+
)
17+
for i in 1:2, j in 1:2, k in 1:2, l in 1:2
18+
]
1319

1420
T = TensorMap(T_array, ℝ^2 ^2 ^2 ^2)
1521

@@ -23,8 +29,8 @@ function classical_ising_symmetric(β)
2329

2430
S = ℤ₂Space(0 => 1, 1 => 1)
2531
T = zeros(Float64, S S S S)
26-
block(T, Irrep[ℤ₂](0)) .= [2x^2 2x*y; 2x*y 2y^2]
27-
block(T, Irrep[ℤ₂](1)) .= [2x*y 2x*y; 2x*y 2x*y]
32+
block(T, Irrep[ℤ₂](0)) .= [2x^2 2x * y; 2x * y 2y^2]
33+
block(T, Irrep[ℤ₂](1)) .= [2x * y 2x * y; 2x * y 2x * y]
2834

2935
return T
3036
end
@@ -41,7 +47,7 @@ function classical_ising_symmetric_3D(β)
4147
for a in 1:2
4248
# Outer product of W[a, :] with itself 6 times
4349
T_array[i, j, k, l, m, n] += W[a, i] * W[a, j] * W[a, k] * W[a, l] * W[a, m] *
44-
W[a, n]
50+
W[a, n]
4551
end
4652
end
4753
S = ℤ₂Space(0 => 1, 1 => 1)
@@ -50,7 +56,7 @@ function classical_ising_symmetric_3D(β)
5056
return permute(T, ((1, 4), (5, 6, 2, 3)))
5157
end
5258

53-
function classical_ising_3D(β; J=1.0)
59+
function classical_ising_3D(β; J = 1.0)
5460
K = β * J
5561

5662
# Boltzmann weights
@@ -63,13 +69,13 @@ function classical_ising_3D(β; J=1.0)
6369
O[1, 1, 1, 1, 1, 1] = 1
6470
O[2, 2, 2, 2, 2, 2] = 1
6571
@tensor o[-1 -2; -3 -4 -5 -6] := O[1 2; 3 4 5 6] * q[-1; 1] * q[-2; 2] * q[-3; 3] *
66-
q[-4; 4] * q[-5; 5] * q[-6; 6]
72+
q[-4; 4] * q[-5; 5] * q[-6; 6]
6773

6874
TMS =^2 (ℂ^2)' ^2 ^2 (ℂ^2)' (ℂ^2)'
6975

7076
return TensorMap(o, TMS)
7177
end
72-
ising_βc_3D = 1 / 4.51152469
78+
const ising_βc_3D = 1.0 / 4.51152469
7379

7480
classical_ising_symmetric_3D() = classical_ising_symmetric_3D(ising_βc_3D)
7581
classical_ising_3D() = classical_ising_3D(ising_βc_3D)

src/models/potts.jl

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
potts_βc(q) = log(1.0 + sqrt(q))
2+
23
function classical_potts(q::Int, β::Float64)
34
V =^q
45
A_potts = TensorMap(zeros, V V V V)
@@ -17,7 +18,7 @@ function classical_potts(q::Int, β::Float64)
1718
end
1819
classical_potts(q::Int) = classical_potts(q, potts_βc(q))
1920

20-
function weyl_heisenberg_matrices(Q::Int, elt=ComplexF64)
21+
function weyl_heisenberg_matrices(Q::Int, elt = ComplexF64)
2122
U = zeros(elt, Q, Q) # clock matrix
2223
V = zeros(elt, Q, Q) # shift matrix
2324
W = zeros(elt, Q, Q) # DFT
@@ -49,8 +50,10 @@ function classical_potts_symmetric(q::Int64, β::Float64)
4950
Vp = Vect[ZNIrrep{q}](sector => 1 for sector in 0:(q - 1))
5051
_, _, W = weyl_heisenberg_matrices(q)
5152
P = TensorMap(W, ℂ^q ^q)
52-
A_potts = TensorMap(reshape(((P' P') * A_potts * (P P)).data, (q, q, q, q)),
53-
Vp Vp Vp Vp)
53+
A_potts = TensorMap(
54+
reshape(((P' P') * A_potts * (P P)).data, (q, q, q, q)),
55+
Vp Vp Vp Vp
56+
)
5457
return A_potts
5558
end
5659
classical_potts_symmetric(q::Int) = classical_potts_symmetric(q, potts_βc(q))

src/models/sixvertex.jl

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,26 @@
11
# Taken from MPSKitModels.jl
22
sixvertex(symmetry::Type{<:Sector}; kwargs...) = sixvertex(ComplexF64, symmetry; kwargs...)
3-
function sixvertex(elt::Type{<:Number}=ComplexF64, (::Type{Trivial})=Trivial; a=1.0, b=1.0,
4-
c=1.0)
5-
d = elt[a 0 0 0
6-
0 c b 0
7-
0 b c 0
8-
0 0 0 a]
3+
function sixvertex(
4+
elt::Type{<:Number} = ComplexF64, (::Type{Trivial}) = Trivial; a = 1.0, b = 1.0,
5+
c = 1.0
6+
)
7+
d = elt[
8+
a 0 0 0
9+
0 c b 0
10+
0 b c 0
11+
0 0 0 a
12+
]
913
return TensorMap(d, ℂ^2 ^2, ℂ^2 ^2)
1014
end
11-
function sixvertex(elt::Type{<:Number}, ::Type{U1Irrep}; a=1.0, b=1.0, c=1.0)
15+
function sixvertex(elt::Type{<:Number}, ::Type{U1Irrep}; a = 1.0, b = 1.0, c = 1.0)
1216
pspace = U1Space(-1 // 2 => 1, 1 // 2 => 1)
1317
mpo = zeros(elt, pspace pspace, pspace pspace)
1418
block(mpo, Irrep[U₁](0)) .= [b c; c b]
1519
block(mpo, Irrep[U₁](1)) .= reshape([a], (1, 1))
1620
block(mpo, Irrep[U₁](-1)) .= reshape([a], (1, 1))
1721
return mpo
1822
end
19-
function sixvertex(elt::Type{<:Number}, ::Type{CU1Irrep}; a=1.0, b=1.0, c=1.0)
23+
function sixvertex(elt::Type{<:Number}, ::Type{CU1Irrep}; a = 1.0, b = 1.0, c = 1.0)
2024
pspace = CU1Space(1 // 2 => 1)
2125
mpo = zeros(elt, pspace pspace, pspace pspace)
2226
block(mpo, Irrep[CU₁](0, 0)) .= reshape([b + c], (1, 1))

src/schemes/atrg.jl

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ mutable struct ATRG <: TNRScheme
2727
T::TensorMap
2828

2929
finalize!::Function
30-
function ATRG(T::TensorMap{E,S,2,2}; finalize=(finalize!)) where {E,S}
30+
function ATRG(T::TensorMap{E, S, 2, 2}; finalize = (finalize!)) where {E, S}
3131
return new(T, finalize)
3232
end
3333
end
@@ -43,7 +43,7 @@ function step!(scheme::ATRG, trunc::TensorKit.TruncationScheme)
4343
end
4444

4545
function _step!(scheme::ATRG, trunc::TensorKit.TruncationScheme)
46-
A, S, B, _ = tsvd(scheme.T, ((1, 3), (2, 4)); trunc=trunc)
46+
A, S, B, _ = tsvd(scheme.T, ((1, 3), (2, 4)); trunc = trunc)
4747
C, D = deepcopy.([A, B])
4848

4949
@tensor begin
@@ -53,7 +53,7 @@ function _step!(scheme::ATRG, trunc::TensorKit.TruncationScheme)
5353

5454
@tensor M[-1 -2; -3 -4] := B[-3; 1 -4] * C[-1 1; -2]
5555

56-
X, S, Y, _ = tsvd(M, ((1, 3), (2, 4)); trunc=trunc)
56+
X, S, Y, _ = tsvd(M, ((1, 3), (2, 4)); trunc = trunc)
5757
sqrtS = sqrt(S)
5858

5959
@tensor begin
@@ -62,17 +62,17 @@ function _step!(scheme::ATRG, trunc::TensorKit.TruncationScheme)
6262
end
6363

6464
@tensor Q[-1 -2; -3 -4] := A[3 -3; 2] * D[1; -2 4] * X[4 2; -4] *
65-
Y[-1 1; 3]
65+
Y[-1 1; 3]
6666

67-
H, S, G, _ = tsvd(Q; trunc=trunc)
67+
H, S, G, _ = tsvd(Q; trunc = trunc)
6868
sqrtS = sqrt(S)
6969

7070
@tensor begin
7171
H[-1 -2; -3] = H[-1 -2; 1] * sqrtS[1; -3]
7272
G[-1; -2 -3] = sqrtS[-1; 1] * G[1; -2 -3]
7373
end
7474

75-
@tensor scheme.T[-1 -2; -3 -4] := G[-1; -3 1] * H[1 -2; -4]
75+
return @tensor scheme.T[-1 -2; -3 -4] := G[-1; -3 1] * H[1 -2; -4]
7676
end
7777

7878
function Base.show(io::IO, scheme::ATRG)

0 commit comments

Comments
 (0)