Skip to content

Commit bcc9ee0

Browse files
committed
small refactor to bypass runic issue
1 parent 935d6a2 commit bcc9ee0

File tree

1 file changed

+36
-59
lines changed

1 file changed

+36
-59
lines changed

test/setup.jl

Lines changed: 36 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ export c_plusmin, c_minplus, c_number
1717
export force_planar
1818
export symm_mul_mpo
1919
export transverse_field_ising, heisenberg_XXX, bilinear_biquadratic_model, XY_model,
20-
kitaev_model
20+
kitaev_model
2121
export classical_ising, finite_classical_ising, sixvertex
2222

2323
# using TensorOperations
@@ -27,10 +27,9 @@ force_planar(x::Number) = x
2727
force_planar(c::Sector) = PlanarTrivial() c
2828

2929
# convert spaces
30-
force_planar(V::Union{CartesianSpace,ComplexSpace}) =^dim(V)
30+
force_planar(V::Union{CartesianSpace, ComplexSpace}) =^dim(V)
3131
function force_planar(V::GradedSpace)
32-
return Vect[PlanarTrivial sectortype(V)](force_planar(c) => dim(V, c)
33-
for c in sectors(V))
32+
return Vect[PlanarTrivial sectortype(V)](force_planar(c) => dim(V, c) for c in sectors(V))
3433
end
3534
force_planar(V::SumSpace) = SumSpace(map(force_planar, V.spaces))
3635
force_planar(V::ProductSpace) = ProductSpace(map(force_planar, V.spaces))
@@ -86,7 +85,7 @@ end
8685
# Toy models
8786
# ----------------------------
8887

89-
function S_x(::Type{Trivial}=Trivial, ::Type{T}=ComplexF64; spin=1 // 2) where {T<:Number}
88+
function S_x(::Type{Trivial} = Trivial, ::Type{T} = ComplexF64; spin = 1 // 2) where {T <: Number}
9089
return if spin == 1 // 2
9190
TensorMap(T[0 1; 1 0], ℂ^2 ^2)
9291
elseif spin == 1
@@ -95,7 +94,7 @@ function S_x(::Type{Trivial}=Trivial, ::Type{T}=ComplexF64; spin=1 // 2) where {
9594
throw(ArgumentError("spin $spin not supported"))
9695
end
9796
end
98-
function S_y(::Type{Trivial}=Trivial, ::Type{T}=ComplexF64; spin=1 // 2) where {T<:Number}
97+
function S_y(::Type{Trivial} = Trivial, ::Type{T} = ComplexF64; spin = 1 // 2) where {T <: Number}
9998
return if spin == 1 // 2
10099
TensorMap(T[0 -im; im 0], ℂ^2 ^2)
101100
elseif spin == 1
@@ -104,7 +103,7 @@ function S_y(::Type{Trivial}=Trivial, ::Type{T}=ComplexF64; spin=1 // 2) where {
104103
throw(ArgumentError("spin $spin not supported"))
105104
end
106105
end
107-
function S_z(::Type{Trivial}=Trivial, ::Type{T}=ComplexF64; spin=1 // 2) where {T<:Number}
106+
function S_z(::Type{Trivial} = Trivial, ::Type{T} = ComplexF64; spin = 1 // 2) where {T <: Number}
108107
return if spin == 1 // 2
109108
TensorMap(T[1 0; 0 -1], ℂ^2 ^2)
110109
elseif spin == 1
@@ -113,19 +112,19 @@ function S_z(::Type{Trivial}=Trivial, ::Type{T}=ComplexF64; spin=1 // 2) where {
113112
throw(ArgumentError("spin $spin not supported"))
114113
end
115114
end
116-
function S_xx(::Type{Trivial}=Trivial, ::Type{T}=ComplexF64; spin=1 // 2) where {T<:Number}
115+
function S_xx(::Type{Trivial} = Trivial, ::Type{T} = ComplexF64; spin = 1 // 2) where {T <: Number}
117116
return S_x(Trivial, T; spin) S_x(Trivial, T; spin)
118117
end
119-
function S_yy(::Type{Trivial}=Trivial, ::Type{T}=ComplexF64; spin=1 // 2) where {T<:Number}
118+
function S_yy(::Type{Trivial} = Trivial, ::Type{T} = ComplexF64; spin = 1 // 2) where {T <: Number}
120119
return S_y(Trivial, T; spin) S_y(Trivial, T; spin)
121120
end
122-
function S_zz(::Type{Trivial}=Trivial, ::Type{T}=ComplexF64; spin=1 // 2) where {T<:Number}
121+
function S_zz(::Type{Trivial} = Trivial, ::Type{T} = ComplexF64; spin = 1 // 2) where {T <: Number}
123122
return S_z(Trivial, T; spin) S_z(Trivial, T; spin)
124123
end
125124

126-
function transverse_field_ising(::Type{T}=ComplexF64; g=1.0, L=Inf) where {T<:Number}
127-
X = S_x(Trivial, T; spin=1 // 2)
128-
ZZ = S_zz(Trivial, T; spin=1 // 2)
125+
function transverse_field_ising(::Type{T} = ComplexF64; g = 1.0, L = Inf) where {T <: Number}
126+
X = S_x(Trivial, T; spin = 1 // 2)
127+
ZZ = S_zz(Trivial, T; spin = 1 // 2)
129128

130129
if L == Inf
131130
lattice = PeriodicArray([ℂ^2])
@@ -139,7 +138,7 @@ function transverse_field_ising(::Type{T}=ComplexF64; g=1.0, L=Inf) where {T<:Nu
139138
return H₁ + H₂
140139
end
141140

142-
function heisenberg_XXX(::Type{SU2Irrep}; spin=1, L=Inf)
141+
function heisenberg_XXX(::Type{SU2Irrep}; spin = 1, L = Inf)
143142
h = ones(ComplexF64, SU2Space(spin => 1)^2 SU2Space(spin => 1)^2)
144143
for (c, b) in blocks(h)
145144
S = (dim(c) - 1) / 2
@@ -156,8 +155,10 @@ function heisenberg_XXX(::Type{SU2Irrep}; spin=1, L=Inf)
156155
end
157156
end
158157

159-
function heisenberg_XXX(::Type{Trivial}=Trivial, ::Type{T}=ComplexF64; spin=1,
160-
L=Inf) where {T<:Number}
158+
function heisenberg_XXX(
159+
::Type{Trivial} = Trivial, ::Type{T} = ComplexF64; spin = 1,
160+
L = Inf
161+
) where {T <: Number}
161162
h = ones(T, SU2Space(spin => 1)^2 SU2Space(spin => 1)^2)
162163
for (c, b) in blocks(h)
163164
S = (dim(c) - 1) / 2
@@ -176,9 +177,11 @@ function heisenberg_XXX(::Type{Trivial}=Trivial, ::Type{T}=ComplexF64; spin=1,
176177
end
177178
end
178179

179-
function XY_model(::Type{U1Irrep}; g=1 / 2, L=Inf)
180-
h = zeros(ComplexF64,
181-
U1Space(-1 // 2 => 1, 1 // 2 => 1)^2 U1Space(-1 // 2 => 1, 1 // 2 => 1)^2)
180+
function XY_model(::Type{U1Irrep}; g = 1 / 2, L = Inf)
181+
h = zeros(
182+
ComplexF64,
183+
U1Space(-1 // 2 => 1, 1 // 2 => 1)^2 U1Space(-1 // 2 => 1, 1 // 2 => 1)^2
184+
)
182185
h[U1Irrep.((-1 // 2, 1 // 2, -1 // 2, 1 // 2))] .= 1
183186
h[U1Irrep.((1 // 2, -1 // 2, 1 // 2, -1 // 2))] .= 1
184187
Sz = zeros(ComplexF64, space(h, 1) space(h, 1))
@@ -197,7 +200,7 @@ function XY_model(::Type{U1Irrep}; g=1 / 2, L=Inf)
197200
end
198201
end
199202

200-
function bilinear_biquadratic_model(::Type{SU2Irrep}; θ=atan(1 / 3), L=Inf)
203+
function bilinear_biquadratic_model(::Type{SU2Irrep}; θ = atan(1 / 3), L = Inf)
201204
h1 = ones(ComplexF64, SU2Space(1 => 1)^2 SU2Space(1 => 1)^2)
202205
for (c, b) in blocks(h1)
203206
S = (dim(c) - 1) / 2
@@ -253,7 +256,7 @@ function c_number()
253256
return t
254257
end
255258

256-
function kitaev_model(; t=1.0, mu=1.0, Delta=1.0, L=Inf)
259+
function kitaev_model(; t = 1.0, mu = 1.0, Delta = 1.0, L = Inf)
257260
TB = scale!(c_plusmin() + c_minplus(), -t / 2) # tight-binding term
258261
SC = scale!(c_plusplus() + c_minmin(), Delta / 2) # superconducting term
259262
CP = scale!(c_number(), -mu) # chemical potential term
@@ -263,8 +266,9 @@ function kitaev_model(; t=1.0, mu=1.0, Delta=1.0, L=Inf)
263266
return InfiniteMPOHamiltonian(lattice, (1, 2) => TB + SC, (1,) => CP)
264267
else
265268
lattice = fill(space(TB, 1), L)
266-
terms = Iterators.flatten((((i, i + 1) => TB + SC for i in 1:(L - 1)),
267-
(i,) => CP for i in 1:L))
269+
onsite_terms = ((i,) => CP for i in 1:L)
270+
twosite_terms = ((i, i + 1) => TP + SC for i in 1:(L - 1))
271+
terms = Iterators.flatten(twosite_terms, onsite_terms)
268272
return FiniteMPOHamiltonian(lattice, terms)
269273
end
270274
end
@@ -276,14 +280,14 @@ function ising_bond_tensor(β)
276280
return nt
277281
end
278282

279-
function classical_ising(; β=log(1 + sqrt(2)) / 2, L=Inf)
283+
function classical_ising(; β = log(1 + sqrt(2)) / 2, L = Inf)
280284
nt = ising_bond_tensor(β)
281285

282286
δbulk = zeros(ComplexF64, (2, 2, 2, 2))
283287
δbulk[1, 1, 1, 1] = 1
284288
δbulk[2, 2, 2, 2] = 1
285289
@tensor obulk[-1 -2; -3 -4] := δbulk[1 2; 3 4] * nt[-1; 1] * nt[-2; 2] * nt[-3; 3] *
286-
nt[-4; 4]
290+
nt[-4; 4]
287291
Obulk = TensorMap(obulk, ℂ^2 *^2, ℂ^2 *^2)
288292

289293
L == Inf && return InfiniteMPO([Obulk])
@@ -303,40 +307,13 @@ function classical_ising(; β=log(1 + sqrt(2)) / 2, L=Inf)
303307
return FiniteMPO([Oleft, fill(Obulk, L - 2)..., Oright])
304308
end
305309

306-
function finite_classical_ising(N)
307-
return classical_ising(; L=N)
308-
β = log(1 + sqrt(2)) / 2
309-
nt = ising_bond_tensor(β)
310-
311-
# bulk
312-
O = zeros(ComplexF64, (2, 2, 2, 2))
313-
O[1, 1, 1, 1] = 1
314-
O[2, 2, 2, 2] = 1
315-
@tensor o[-1 -2; -3 -4] := O[1 2; 3 4] * nt[-1; 1] * nt[-2; 2] * nt[-3; 3] * nt[-4; 4]
316-
Obulk = TensorMap(o, ℂ^2 *^2, ℂ^2 *^2)
317-
318-
# left
319-
OL = zeros(ComplexF64, (1, 2, 2, 2))
320-
OL[1, 1, 1, 1] = 1
321-
OL[1, 2, 2, 2] = 1
322-
@tensor oL[-1 -2; -3 -4] := OL[-1 1; 2 3] * nt[-2; 1] * nt[-3; 2] * nt[-4; 3]
323-
Oleft = TensorMap(oL, ℂ^1 *^2, ℂ^2 *^2)
324-
325-
# right
326-
OR = zeros(ComplexF64, (2, 2, 2, 1))
327-
OR[1, 1, 1, 1] = 1
328-
OR[2, 2, 2, 1] = 1
329-
@tensor oR[-1 -2; -3 -4] := OR[1 2; 3 -4] * nt[-1; 1] * nt[-2; 2] * nt[-3; 3]
330-
Oright = TensorMap(oR, ℂ^2 *^2, ℂ^2 *^1)
331-
332-
return DenseMPO([Oleft, fill(Obulk, N - 2)..., Oright])
333-
end
334-
335-
function sixvertex(; a=1.0, b=1.0, c=1.0)
336-
d = ComplexF64[a 0 0 0
337-
0 c b 0
338-
0 b c 0
339-
0 0 0 a]
310+
function sixvertex(; a = 1.0, b = 1.0, c = 1.0)
311+
d = ComplexF64[
312+
a 0 0 0
313+
0 c b 0
314+
0 b c 0
315+
0 0 0 a
316+
]
340317
return InfiniteMPO([permute(TensorMap(d, ℂ^2 ^2, ℂ^2 ^2), ((1, 2), (4, 3)))])
341318
end
342319

0 commit comments

Comments
 (0)