Skip to content

Commit 972d455

Browse files
Katharine Hyattkshyatt
authored andcommitted
More symmetric braiding
1 parent bffc7f1 commit 972d455

1 file changed

Lines changed: 74 additions & 82 deletions

File tree

test/amd/tensors.jl

Lines changed: 74 additions & 82 deletions
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ for V in spacelist
100100
@test TensorKit.to_cpu(t) == convert(TensorMap, d)
101101
end
102102
end
103-
@timedtestset "Basic linear algebra" begin
103+
symmetricbraiding && @timedtestset "Basic linear algebra" begin
104104
W = V1 V2 V3 V4 V5
105105
for T in (Float32, ComplexF64)
106106
t = @constinferred AMDGPU.rand(T, W)
@@ -267,26 +267,24 @@ for V in spacelist
267267
end
268268
end
269269
end
270-
if BraidingStyle(I) isa SymmetricBraiding
271-
@timedtestset "Permutations: test via CPU" begin
272-
W = V1 V2 V3 V4 V5
273-
t = AMDGPU.rand(ComplexF64, W)
274-
for k in 0:5
275-
for p in permutations(1:5)
276-
p1 = ntuple(n -> p[n], k)
277-
p2 = ntuple(n -> p[k + n], 5 - k)
278-
dt2 = AMDGPU.@allowscalar permute(t, (p1, p2))
279-
ht2 = permute(TensorKit.to_cpu(t), (p1, p2))
280-
@test ht2 == TensorKit.to_cpu(dt2)
281-
end
282-
283-
dt3 = AMDGPU.@allowscalar repartition(t, k)
284-
ht3 = repartition(TensorKit.to_cpu(t), k)
285-
@test ht3 == TensorKit.to_cpu(dt3)
270+
symmetricbraiding && @timedtestset "Permutations: test via CPU" begin
271+
W = V1 V2 V3 V4 V5
272+
t = AMDGPU.rand(ComplexF64, W)
273+
for k in 0:5
274+
for p in permutations(1:5)
275+
p1 = ntuple(n -> p[n], k)
276+
p2 = ntuple(n -> p[k + n], 5 - k)
277+
dt2 = AMDGPU.@allowscalar permute(t, (p1, p2))
278+
ht2 = permute(TensorKit.to_cpu(t), (p1, p2))
279+
@test ht2 == TensorKit.to_cpu(dt2)
286280
end
281+
282+
dt3 = AMDGPU.@allowscalar repartition(t, k)
283+
ht3 = repartition(TensorKit.to_cpu(t), k)
284+
@test ht3 == TensorKit.to_cpu(dt3)
287285
end
288286
end
289-
@timedtestset "Full trace: test self-consistency" begin
287+
symmetricbraiding && @timedtestset "Full trace: test self-consistency" begin
290288
t = AMDGPU.rand(ComplexF64, V1 V2' V2 V1')
291289
AMDGPU.@allowscalar begin
292290
t2 = permute(t, ((1, 2), (4, 3)))
@@ -306,24 +304,22 @@ for V in spacelist
306304
@test ss s2
307305
@test ss s3
308306
end
309-
#=@timedtestset "Partial trace: test self-consistency" begin
307+
#=symmetricbraiding && @timedtestset "Partial trace: test self-consistency" begin
310308
t = AMDGPU.rand(ComplexF64, V1 ⊗ V2' ⊗ V3 ⊗ V2 ⊗ V1' ⊗ V3')
311309
@tensor t2[a, b] := t[c, d, b, d, c, a]
312310
@tensor t4[a, b, c, d] := t[d, e, b, e, c, a]
313311
@tensor t5[a, b] := t4[a, b, c, c]
314312
@test t2 ≈ t5
315313
end
316-
if BraidingStyle(I) isa Bosonic && hasfusiontensor(I)
317-
@timedtestset "Trace: test via conversion" begin
318-
t = AMDGPU.rand(ComplexF64, V1 ⊗ V2' ⊗ V3 ⊗ V2 ⊗ V1' ⊗ V3')
319-
AMDGPU.@allowscalar begin
320-
@tensor t2[a, b] := t[c, d, b, d, c, a]
321-
@tensor t3[a, b] := ad(t)[c, d, b, d, c, a]
322-
end
323-
@test t3 ≈ ad(t2)
314+
symmetricbraiding && @timedtestset "Trace: test via conversion" begin
315+
t = AMDGPU.rand(ComplexF64, V1 ⊗ V2' ⊗ V3 ⊗ V2 ⊗ V1' ⊗ V3')
316+
AMDGPU.@allowscalar begin
317+
@tensor t2[a, b] := t[c, d, b, d, c, a]
318+
@tensor t3[a, b] := ad(t)[c, d, b, d, c, a]
324319
end
320+
@test t3 ≈ ad(t2)
325321
end
326-
@timedtestset "Trace and contraction" begin
322+
symmetricbraiding && @timedtestset "Trace and contraction" begin
327323
t1 = AMDGPU.rand(ComplexF64, V1 ⊗ V2 ⊗ V3)
328324
t2 = AMDGPU.rand(ComplexF64, V2' ⊗ V4 ⊗ V1')
329325
AMDGPU.@allowscalar begin
@@ -349,7 +345,7 @@ for V in spacelist
349345
@test TensorKit.to_cpu(dHrA12) ≈ hHrA12
350346
end
351347
end=# # doesn't yet work because of AdjointTensor
352-
@timedtestset "Index flipping: test flipping inverse" begin
348+
BraidingStyle(I) isa HasBraiding && @timedtestset "Index flipping: test flipping inverse" begin
353349
t = AMDGPU.rand(ComplexF64, V1 ⊗ V1' ← V1' ⊗ V1)
354350
for i in 1:4
355351
AMDGPU.@allowscalar begin
@@ -454,46 +450,44 @@ for V in spacelist
454450
end=#
455451
end
456452
end
457-
if BraidingStyle(I) isa Bosonic && hasfusiontensor(I)
458-
@timedtestset "Tensor functions" begin
459-
W = V1 V2
460-
for T in (Float64, ComplexF64)
461-
#=t = project_hermitian!(AMDGPU.randn(T, W, W))
462-
s = dim(W)
463-
@test (@constinferred sqrt(t))^2 ≈ t
464-
@test TensorKit.to_cpu(sqrt(t)) ≈ sqrt(TensorKit.to_cpu(t))
465-
expt = @constinferred exp(t)
466-
@test TensorKit.to_cpu(expt) ≈ exp(TensorKit.to_cpu(t))
467-
@test exp(@constinferred log(project_hermitian!(expt))) ≈ expt
468-
@test TensorKit.to_cpu(log(project_hermitian!(expt))) ≈ log(TensorKit.to_cpu(expt))
453+
symmetricbraiding && @timedtestset "Tensor functions" begin
454+
W = V1 V2
455+
for T in (Float64, ComplexF64)
456+
#=t = project_hermitian!(AMDGPU.randn(T, W, W))
457+
s = dim(W)
458+
@test (@constinferred sqrt(t))^2 ≈ t
459+
@test TensorKit.to_cpu(sqrt(t)) ≈ sqrt(TensorKit.to_cpu(t))
460+
expt = @constinferred exp(t)
461+
@test TensorKit.to_cpu(expt) ≈ exp(TensorKit.to_cpu(t))
462+
@test exp(@constinferred log(project_hermitian!(expt))) ≈ expt
463+
@test TensorKit.to_cpu(log(project_hermitian!(expt))) ≈ log(TensorKit.to_cpu(expt))
469464
470-
@test (@constinferred cos(t))^2 + (@constinferred sin(t))^2 ≈
471-
id(storagetype(t), W)
472-
@test (@constinferred tan(t)) ≈ sin(t) / cos(t)
473-
@test (@constinferred cot(t)) ≈ cos(t) / sin(t)
474-
@test (@constinferred cosh(t))^2 - (@constinferred sinh(t))^2 ≈
475-
id(storagetype(t), W)
476-
@test (@constinferred tanh(t)) ≈ sinh(t) / cosh(t)
477-
@test (@constinferred coth(t)) ≈ cosh(t) / sinh(t)=# # TODO in AMDGPU
465+
@test (@constinferred cos(t))^2 + (@constinferred sin(t))^2 ≈
466+
id(storagetype(t), W)
467+
@test (@constinferred tan(t)) ≈ sin(t) / cos(t)
468+
@test (@constinferred cot(t)) ≈ cos(t) / sin(t)
469+
@test (@constinferred cosh(t))^2 - (@constinferred sinh(t))^2 ≈
470+
id(storagetype(t), W)
471+
@test (@constinferred tanh(t)) ≈ sinh(t) / cosh(t)
472+
@test (@constinferred coth(t)) ≈ cosh(t) / sinh(t)=# # TODO in AMDGPU
478473

479-
#=t1 = sin(t)
480-
@test sin(@constinferred asin(t1)) ≈ t1
481-
t2 = cos(t)
482-
@test cos(@constinferred acos(t2)) ≈ t2
483-
t3 = sinh(t)
484-
@test sinh(@constinferred asinh(t3)) ≈ t3
485-
t4 = cosh(t)
486-
@test cosh(@constinferred acosh(t4)) ≈ t4
487-
t5 = tan(t)
488-
@test tan(@constinferred atan(t5)) ≈ t5
489-
t6 = cot(t)
490-
@test cot(@constinferred acot(t6)) ≈ t6
491-
t7 = tanh(t)
492-
@test tanh(@constinferred atanh(t7)) ≈ t7
493-
t8 = coth(t)
494-
@test coth(@constinferred acoth(t8)) ≈ t8=#
495-
# TODO in AMDGPU
496-
end
474+
#=t1 = sin(t)
475+
@test sin(@constinferred asin(t1)) ≈ t1
476+
t2 = cos(t)
477+
@test cos(@constinferred acos(t2)) ≈ t2
478+
t3 = sinh(t)
479+
@test sinh(@constinferred asinh(t3)) ≈ t3
480+
t4 = cosh(t)
481+
@test cosh(@constinferred acosh(t4)) ≈ t4
482+
t5 = tan(t)
483+
@test tan(@constinferred atan(t5)) ≈ t5
484+
t6 = cot(t)
485+
@test cot(@constinferred acot(t6)) ≈ t6
486+
t7 = tanh(t)
487+
@test tanh(@constinferred atanh(t7)) ≈ t7
488+
t8 = coth(t)
489+
@test coth(@constinferred acoth(t8)) ≈ t8=#
490+
# TODO in AMDGPU
497491
end
498492
end
499493
# Sylvester not defined for AMDGPU
@@ -527,24 +521,22 @@ for V in spacelist
527521
@test norm(t) ≈ norm(t1) * norm(t2)
528522
end
529523
end
530-
if BraidingStyle(I) isa Bosonic && hasfusiontensor(I)
531-
@timedtestset "Tensor product: test via conversion" begin
532-
for T in (Float32, ComplexF64)
533-
t1 = AMDGPU.rand(T, V2 ⊗ V3 ⊗ V1, V1)
534-
t2 = AMDGPU.rand(T, V2 ⊗ V1 ⊗ V3, V2)
535-
d1 = dim(codomain(t1))
536-
d2 = dim(codomain(t2))
537-
d3 = dim(domain(t1))
538-
d4 = dim(domain(t2))
539-
AMDGPU.@allowscalar begin
540-
t = @constinferred (t1 ⊗ t2)
541-
At = ad(t)
542-
@test ad(t) ≈ ad(t1) ⊗ ad(t2)
543-
end
524+
symmetricbraiding && @timedtestset "Tensor product: test via conversion" begin
525+
for T in (Float32, ComplexF64)
526+
t1 = AMDGPU.rand(T, V2 ⊗ V3 ⊗ V1, V1)
527+
t2 = AMDGPU.rand(T, V2 ⊗ V1 ⊗ V3, V2)
528+
d1 = dim(codomain(t1))
529+
d2 = dim(codomain(t2))
530+
d3 = dim(domain(t1))
531+
d4 = dim(domain(t2))
532+
AMDGPU.@allowscalar begin
533+
t = @constinferred (t1 ⊗ t2)
534+
At = ad(t)
535+
@test ad(t) ≈ ad(t1) ⊗ ad(t2)
544536
end
545537
end
546538
end=#
547-
#=@timedtestset "Tensor product: test via tensor contraction" begin
539+
#=symmetricbraiding && @timedtestset "Tensor product: test via tensor contraction" begin
548540
for T in (Float32, ComplexF64)
549541
t1 = AMDGPU.rand(T, V2 ⊗ V3 ⊗ V1)
550542
t2 = AMDGPU.rand(T, V2 ⊗ V1 ⊗ V3)

0 commit comments

Comments
 (0)