Skip to content

Commit 70c5321

Browse files
committed
add braidingtensor.jl tests
1 parent 11df36b commit 70c5321

3 files changed

Lines changed: 201 additions & 136 deletions

File tree

‎test/braidingtensor.jl‎

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

‎test/runtests.jl‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ testsuite = ParallelTestRunner.find_tests(@__DIR__)
55

66
# Exclude non-test files
77
delete!(testsuite, "setup") # shared setup module
8-
delete!(testsuite, "braidingtensor") # not part of the testsuite (see file header)
98

109
# CUDA tests: only run if CUDA is functional
1110
using CUDA: CUDA

‎test/tensors/braidingtensor.jl‎

Lines changed: 201 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,201 @@
1+
using Test, TestExtras
2+
using TensorKit
3+
using TensorKit: type_repr
4+
5+
spacelist = default_spacelist(fast_tests)
6+
7+
for V_tuple in spacelist
8+
I = sectortype(first(V_tuple))
9+
Istr = type_repr(I)
10+
BraidingStyle(I) isa NoBraiding && continue
11+
V = first(V_tuple)
12+
T = ComplexF64
13+
t = randn(T, V ⊗ V' ⊗ V' ⊗ V ← V ⊗ V')
14+
println("---------------------------------------")
15+
println("BraidingTensor planar contractions with symmetry: $Istr")
16+
println("---------------------------------------")
17+
@timedtestset "BraidingTensor planar contractions with symmetry: $Istr" verbose = true begin
18+
@timedtestset "τ as left factor, all legs contracted" begin
19+
# BraidingTensor(V, V') on leading codomain indices
20+
ττ = TensorMap(BraidingTensor(V, V'))
21+
@planar t1[-1 -2 -3 -4; -5 -6] := τ[-1 -2; 1 2] * t[1 2 -3 -4; -5 -6]
22+
@planar t2[-1 -2 -3 -4; -5 -6] := ττ[-1 -2; 1 2] * t[1 2 -3 -4; -5 -6]
23+
@planar t3[-1 -2 -3 -4; -5 -6] := τ[2 1; -2 -1] * t[1 2 -3 -4; -5 -6]
24+
@planar t4[-1 -2 -3 -4; -5 -6] := τ'[-2 2; -1 1] * t[1 2 -3 -4; -5 -6]
25+
@test t1 ≈ t2
26+
@test t1 ≈ t3
27+
@test t1 ≈ t4
28+
29+
# BraidingTensor(V', V') on inner codomain indices
30+
ττ = TensorMap(BraidingTensor(V', V'))
31+
@planar t1[-1 -2 -3 -4; -5 -6] := τ[-2 -3; 1 2] * t[-1 1 2 -4; -5 -6]
32+
@planar t2[-1 -2 -3 -4; -5 -6] := ττ[-2 -3; 1 2] * t[-1 1 2 -4; -5 -6]
33+
@planar t3[-1 -2 -3 -4; -5 -6] := τ[2 1; -3 -2] * t[-1 1 2 -4; -5 -6]
34+
@planar t4[-1 -2 -3 -4; -5 -6] := τ'[-3 2; -2 1] * t[-1 1 2 -4; -5 -6]
35+
@test t1 ≈ t2
36+
@test t1 ≈ t3
37+
@test t1 ≈ t4
38+
39+
# BraidingTensor(V', V) on trailing codomain indices
40+
ττ = TensorMap(BraidingTensor(V', V))
41+
@planar t1[-1 -2 -3 -4; -5 -6] := τ[-3 -4; 1 2] * t[-1 -2 1 2; -5 -6]
42+
@planar t2[-1 -2 -3 -4; -5 -6] := ττ[-3 -4; 1 2] * t[-1 -2 1 2; -5 -6]
43+
@planar t3[-1 -2 -3 -4; -5 -6] := τ[2 1; -4 -3] * t[-1 -2 1 2; -5 -6]
44+
@planar t4[-1 -2 -3 -4; -5 -6] := τ'[-4 2; -3 1] * t[-1 -2 1 2; -5 -6]
45+
@test t1 ≈ t2
46+
@test t1 ≈ t3
47+
@test t1 ≈ t4
48+
end
49+
50+
@timedtestset "τ as left factor, mixed open legs" begin
51+
# BraidingTensor(V', V) with mixed index pattern
52+
ττ = TensorMap(BraidingTensor(V', V))
53+
@planar t1[-1 -2 -3 -4; -5 -6] := τ[1 -2; 2 -3] * t[-1 1 2 -4; -5 -6]
54+
@planar t2[-1 -2 -3 -4; -5 -6] := ττ[1 -2; 2 -3] * t[-1 1 2 -4; -5 -6]
55+
@planar t3[-1 -2 -3 -4; -5 -6] := τ[-3 2; -2 1] * t[-1 1 2 -4; -5 -6]
56+
@planar t4[-1 -2 -3 -4; -5 -6] := τ'[-2 -3; 1 2] * t[-1 1 2 -4; -5 -6]
57+
@test t1 ≈ t2
58+
@test t1 ≈ t3
59+
@test t1 ≈ t4
60+
61+
# BraidingTensor(V, V') with mixed index pattern (inverse of previous)
62+
ττ = TensorMap(BraidingTensor(V, V'))
63+
@planar t1[-1 -2 -3 -4; -5 -6] := τ[-3 2; -2 1] * t[-1 1 2 -4; -5 -6]
64+
@planar t2[-1 -2 -3 -4; -5 -6] := ττ[-3 2; -2 1] * t[-1 1 2 -4; -5 -6]
65+
@planar t3[-1 -2 -3 -4; -5 -6] := τ[1 -2; 2 -3] * t[-1 1 2 -4; -5 -6]
66+
@planar t4[-1 -2 -3 -4; -5 -6] := τ'[2 1; -3 -2] * t[-1 1 2 -4; -5 -6]
67+
@test t1 ≈ t2
68+
@test t1 ≈ t3
69+
@test t1 ≈ t4
70+
71+
# BraidingTensor(V, V) with mixed index pattern
72+
ττ = TensorMap(BraidingTensor(V, V))
73+
@planar t1[-1 -2 -3 -4; -5 -6] := τ[2 1; -3 -2] * t[-1 1 2 -4; -5 -6]
74+
@planar t2[-1 -2 -3 -4; -5 -6] := ττ[2 1; -3 -2] * t[-1 1 2 -4; -5 -6]
75+
@planar t3[-1 -2 -3 -4; -5 -6] := τ[-2 -3; 1 2] * t[-1 1 2 -4; -5 -6]
76+
@planar t4[-1 -2 -3 -4; -5 -6] := τ'[1 -2; 2 -3] * t[-1 1 2 -4; -5 -6]
77+
@test t1 ≈ t2
78+
@test t1 ≈ t3
79+
@test t1 ≈ t4
80+
end
81+
82+
@timedtestset "τ as right factor" begin
83+
# BraidingTensor(V', V) on all domain indices
84+
ττ = TensorMap(BraidingTensor(V', V))
85+
@planar t1[-1 -2 -3 -4; -5 -6] := t[-1 -2 -3 -4; 1 2] * τ[1 2; -5 -6]
86+
@planar t2[-1 -2 -3 -4; -5 -6] := t[-1 -2 -3 -4; 1 2] * ττ[1 2; -5 -6]
87+
@planar t3[-1 -2 -3 -4; -5 -6] := t[-1 -2 -3 -4; 1 2] * τ[-6 -5; 2 1]
88+
@planar t4[-1 -2 -3 -4; -5 -6] := t[-1 -2 -3 -4; 1 2] * τ'[2 -6; 1 -5]
89+
@test t1 ≈ t2
90+
@test t1 ≈ t3
91+
@test t1 ≈ t4
92+
93+
# BraidingTensor(V, V') adjoint on all domain indices
94+
ττ = TensorMap(BraidingTensor(V, V'))
95+
@planar t1[-1 -2 -3 -4; -5 -6] := t[-1 -2 -3 -4; 1 2] * τ'[1 2; -5 -6]
96+
@planar t2[-1 -2 -3 -4; -5 -6] := t[-1 -2 -3 -4; 1 2] * ττ'[1 2; -5 -6]
97+
@planar t3[-1 -2 -3 -4; -5 -6] := t[-1 -2 -3 -4; 1 2] * τ'[-6 -5; 2 1]
98+
@planar t4[-1 -2 -3 -4; -5 -6] := t[-1 -2 -3 -4; 1 2] * τ[2 -6; 1 -5]
99+
@test t1 ≈ t2
100+
@test t1 ≈ t3
101+
@test t1 ≈ t4
102+
103+
# BraidingTensor(V, V) with mixed domain legs
104+
ττ = TensorMap(BraidingTensor(V, V))
105+
@planar t1[-1 -2 -3 -4; -5 -6] := t[-1 -2 -3 1; -5 2] * τ[-4 -6; 1 2]
106+
@planar t2[-1 -2 -3 -4; -5 -6] := t[-1 -2 -3 1; -5 2] * ττ[-4 -6; 1 2]
107+
@planar t3[-1 -2 -3 -4; -5 -6] := t[-1 -2 -3 1; -5 2] * τ[2 1; -6 -4]
108+
@planar t4[-1 -2 -3 -4; -5 -6] := t[-1 -2 -3 1; -5 2] * τ'[-6 2; -4 1]
109+
@test t1 ≈ t2
110+
@test t1 ≈ t3
111+
@test t1 ≈ t4
112+
end
113+
114+
@timedtestset "τ with fully contracted output" begin
115+
# scalar output
116+
ττ = TensorMap(BraidingTensor(V', V))
117+
@planar t1[(); (-1, -2)] := τ[2 1; 3 4] * t[1 2 3 4; -1 -2]
118+
@planar t2[(); (-1, -2)] := ττ[2 1; 3 4] * t[1 2 3 4; -1 -2]
119+
@planar t3[(); (-1, -2)] := τ[4 3; 1 2] * t[1 2 3 4; -1 -2]
120+
@planar t4[(); (-1, -2)] := τ'[1 4; 2 3] * t[1 2 3 4; -1 -2]
121+
@test t1 ≈ t2
122+
@test t1 ≈ t3
123+
@test t1 ≈ t4
124+
125+
# rank-1 output
126+
ττ = TensorMap(BraidingTensor(V, V))
127+
@planar t1[-1; -2] := τ[2 1; 3 4] * t[-1 1 2 3; -2 4]
128+
@planar t2[-1; -2] := ττ[2 1; 3 4] * t[-1 1 2 3; -2 4]
129+
@planar t3[-1; -2] := τ[4 3; 1 2] * t[-1 1 2 3; -2 4]
130+
@planar t4[-1; -2] := τ'[1 4; 2 3] * t[-1 1 2 3; -2 4]
131+
@test t1 ≈ t2
132+
@test t1 ≈ t3
133+
@test t1 ≈ t4
134+
135+
# rank-2 output
136+
ττ = TensorMap(BraidingTensor(V, V'))
137+
@planar t1[-1 -2] := τ[2 1; 3 4] * t[-1 -2 1 2; 4 3]
138+
@planar t2[-1 -2] := ττ[2 1; 3 4] * t[-1 -2 1 2; 4 3]
139+
@planar t3[-1 -2] := τ[4 3; 1 2] * t[-1 -2 1 2; 4 3]
140+
@planar t4[-1 -2] := τ'[1 4; 2 3] * t[-1 -2 1 2; 4 3]
141+
@test t1 ≈ t2
142+
@test t1 ≈ t3
143+
@test t1 ≈ t4
144+
end
145+
146+
@timedtestset "τ with one open codomain leg" begin
147+
# BraidingTensor(V, V') with one open codomain leg
148+
ττ = TensorMap(BraidingTensor(V, V'))
149+
@planar t1[-1 -2; -3 -4] := τ[-1 3; 1 2] * t[1 2 3 -2; -3 -4]
150+
@planar t2[-1 -2; -3 -4] := ττ[-1 3; 1 2] * t[1 2 3 -2; -3 -4]
151+
@planar t3[-1 -2; -3 -4] := τ[2 1; 3 -1] * t[1 2 3 -2; -3 -4]
152+
@planar t4[-1 -2; -3 -4] := τ'[3 2; -1 1] * t[1 2 3 -2; -3 -4]
153+
@test t1 ≈ t2
154+
@test t1 ≈ t3
155+
@test t1 ≈ t4
156+
157+
# BraidingTensor(V', V') adjoint with one open codomain leg
158+
ττ = TensorMap(BraidingTensor(V', V'))
159+
@planar t1[-1 -2; -3 -4] := τ'[-2 3; 1 2] * t[-1 1 2 3; -3 -4]
160+
@planar t2[-1 -2; -3 -4] := ττ'[-2 3; 1 2] * t[-1 1 2 3; -3 -4]
161+
@planar t3[-1 -2; -3 -4] := τ'[2 1; 3 -2] * t[-1 1 2 3; -3 -4]
162+
@planar t4[-1 -2; -3 -4] := τ[3 2; -2 1] * t[-1 1 2 3; -3 -4]
163+
@test t1 ≈ t2
164+
@test t1 ≈ t3
165+
@test t1 ≈ t4
166+
167+
# BraidingTensor(V', V) with one open codomain leg
168+
ττ = TensorMap(BraidingTensor(V', V))
169+
@planar t1[-1 -2 -3; -4] := τ[-3 3; 1 2] * t[-1 -2 1 2; -4 3]
170+
@planar t2[-1 -2 -3; -4] := ττ[-3 3; 1 2] * t[-1 -2 1 2; -4 3]
171+
@planar t3[-1 -2 -3; -4] := τ[2 1; 3 -3] * t[-1 -2 1 2; -4 3]
172+
@planar t4[-1 -2 -3; -4] := τ'[3 2; -3 1] * t[-1 -2 1 2; -4 3]
173+
@test t1 ≈ t2
174+
@test t1 ≈ t3
175+
@test t1 ≈ t4
176+
end
177+
178+
@timedtestset "τ as right factor with open domain leg" begin
179+
# BraidingTensor(V', V) as right factor with one open domain leg
180+
ττ = TensorMap(BraidingTensor(V', V))
181+
@planar t1[-1 -2 -3; -4] := t[-1 -2 -3 3; 1 2] * τ[1 2; -4 3]
182+
@planar t2[-1 -2 -3; -4] := t[-1 -2 -3 3; 1 2] * ττ[1 2; -4 3]
183+
@planar t3[-1 -2 -3; -4] := t[-1 -2 -3 3; 1 2] * τ[3 -4; 2 1]
184+
@planar t4[-1 -2 -3; -4] := t[-1 -2 -3 3; 1 2] * τ'[2 3; 1 -4]
185+
@test t1 ≈ t2
186+
@test t1 ≈ t3
187+
@test t1 ≈ t4
188+
189+
# BraidingTensor(V, V') adjoint as right factor with one open domain leg
190+
ττ = TensorMap(BraidingTensor(V, V'))
191+
@planar t1[-1 -2 -3; -4] := t[-1 -2 -3 3; 1 2] * τ'[1 2; -4 3]
192+
@planar t2[-1 -2 -3; -4] := t[-1 -2 -3 3; 1 2] * ττ'[1 2; -4 3]
193+
@planar t3[-1 -2 -3; -4] := t[-1 -2 -3 3; 1 2] * τ'[3 -4; 2 1]
194+
@planar t4[-1 -2 -3; -4] := t[-1 -2 -3 3; 1 2] * τ[2 3; 1 -4]
195+
@test t1 ≈ t2
196+
@test t1 ≈ t3
197+
@test t1 ≈ t4
198+
end
199+
end
200+
TensorKit.empty_globalcaches!()
201+
end

0 commit comments

Comments
 (0)