@@ -20,6 +20,7 @@ function precompile_contract(::Type{S}; eltypes = PRECOMPILE_ELTYPES, ndims = PR
2020 V = unitspace (S)
2121 backend = TO. DefaultBackend ()
2222 allocator = TO. DefaultAllocator ()
23+ symmetric_braiding = BraidingStyle (sectortype (S)) isa SymmetricBraiding
2324 for T in eltypes
2425 α, β = rand (T), rand (T)
2526
@@ -32,27 +33,31 @@ function precompile_contract(::Type{S}; eltypes = PRECOMPILE_ELTYPES, ndims = PR
3233 B = randn (T, W ← V)
3334 pA = ((1 ,), ntuple (i -> i + 1 , Val (N - 1 )))
3435 pB = (ntuple (identity, Val (N - 1 )), (N,))
35- C = TO. tensoralloc_contract (T, A, pA, false , B, pB, false , ((1 ,), (2 ,)), Val (false ))
36- # both scalar-type paths: generic `(α,β)` and the identity `(One(), Zero())` fast path
37- TO. tensorcontract! (C, A, pA, false , B, pB, false , ((1 ,), (2 ,)), α, β, backend, allocator)
38- TO. tensorcontract! (C, A, pA, false , B, pB, false , ((1 ,), (2 ,)), One (), Zero (), backend, allocator)
39-
40- # a non-trivial permutation exercises the repartition/braid/transform machinery at
41- # arity N (the contraction above takes the no-copy view path for its natural partition)
42- permute (A, (ntuple (i -> N - i + 1 , Val (N)), ()))
36+ pAB = ((1 ,), (2 ,))
37+ C = TO. tensoralloc_contract (T, A, pA, false , B, pB, false , pAB, Val (false ))
38+
39+ planarcontract! (C, A, pA, B, pB, pAB, α, β, backend, allocator)
40+ planarcontract! (C, A, pA, B, pB, pAB, One (), Zero (), backend, allocator)
41+
42+ if symmetric_braiding
43+ TO. tensorcontract! (C, A, pA, false , B, pB, false , pAB, α, β, backend, allocator)
44+ TO. tensorcontract! (C, A, pA, false , B, pB, false , pAB, One (), Zero (), backend, allocator)
45+ end
4346 end
4447
4548 # the conjugated-operand branch (`conjA=true`) is a distinct runtime path (adjoint
46- # handling) that `conj(A) * B` networks hit; `@tensor` handles the space bookkeeping
49+ # handling) that `conj(A) * B` networks hit; `@plansor` picks the planar or non-planar
50+ # implementation depending on the braiding style, so this compiles for any sectortype
4751 A2 = randn (T, V ← V)
4852 B2 = randn (T, V ← V)
49- @tensor Cc[a; c] := conj (A2[b; a]) * B2[b; c]
53+ @plansor Cc[a; c] := conj (A2[b; a]) * B2[b; c]
5054
5155 # partial trace (the two traced legs are mutually dual)
5256 At = randn (T, V ⊗ V' ← V)
53- TO. tensortrace! (
54- TO. tensoralloc_add (T, At, ((3 ,), ()), false , Val (false )),
55- At, ((3 ,), ()), ((1 ,), (2 ,)), false , α, β, backend, allocator
57+ Ct = TO. tensoralloc_add (T, At, ((3 ,), ()), false , Val (false ))
58+ planartrace! (Ct, At, ((3 ,), ()), ((1 ,), (2 ,)), α, β, backend, allocator)
59+ symmetric_braiding && TO. tensortrace! (
60+ Ct, At, ((3 ,), ()), ((1 ,), (2 ,)), false , α, β, backend, allocator
5661 )
5762 end
5863 return nothing
0 commit comments