Skip to content

Commit fd8dd7f

Browse files
lkdvosogautheJutho
authored
Vectorize fusiontree manipulations (QuantumKitHub#261)
Co-authored-by: Olivier Gauthé <olivier.gauthe.2011+github@polytechnique.org> Co-authored-by: Jutho Haegeman <jutho.haegeman@ugent.be>
1 parent 3b9efee commit fd8dd7f

24 files changed

Lines changed: 2887 additions & 1885 deletions

Project.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ Random = "1"
5454
SafeTestsets = "0.1"
5555
ScopedValues = "1.3.0"
5656
Strided = "2"
57-
TensorKitSectors = "0.3.5"
57+
TensorKitSectors = "0.3.6"
5858
TensorOperations = "5.1"
5959
Test = "1"
6060
TestExtras = "0.2,0.3"
@@ -86,4 +86,4 @@ Zygote = "e88e6eb3-aa80-5325-afca-941959d7151f"
8686
cuTENSOR = "011b41b2-24ef-40a8-b3eb-fa098493e9e1"
8787

8888
[targets]
89-
test = ["ArgParse", "Adapt", "Aqua", "AllocCheck", "Combinatorics", "CUDA", "cuTENSOR", "GPUArrays", "LinearAlgebra", "SafeTestsets", "TensorOperations", "Test", "TestExtras", "ChainRulesCore", "ChainRulesTestUtils", "FiniteDifferences", "Zygote", "Mooncake", "JET"]
89+
test = ["ArgParse", "Adapt", "Aqua", "AllocCheck", "Combinatorics", "CUDA", "cuTENSOR", "GPUArrays", "JET", "LinearAlgebra", "SafeTestsets", "TensorOperations", "Test", "TestExtras", "ChainRulesCore", "ChainRulesTestUtils", "FiniteDifferences", "Zygote", "Mooncake"]

docs/make.jl

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,16 @@
1+
# if examples is not the current active environment, switch to it
2+
if Base.active_project() != joinpath(@__DIR__, "Project.toml")
3+
using Pkg
4+
Pkg.activate(@__DIR__)
5+
Pkg.develop(PackageSpec(; path = joinpath(@__DIR__, "..")))
6+
Pkg.resolve()
7+
Pkg.instantiate()
8+
end
9+
110
using Documenter
211
using Random
312
using TensorKit
13+
using TensorKit: FusionTreePair, Index2Tuple
414
using TensorKit.TensorKitSectors
515
using TensorKit.MatrixAlgebraKit
616
using DocumenterInterLinks
@@ -40,6 +50,9 @@ mathengine = MathJax3(
4050
)
4151
)
4252

53+
# docstrings don't need `using TensorKit`
54+
DocMeta.setdocmeta!(TensorKit, :DocTestSetup, :(using TensorKit); recursive = true)
55+
4356
makedocs(;
4457
modules = [TensorKit, TensorKitSectors],
4558
sitename = "TensorKit.jl",

docs/src/lib/fusiontrees.md

Lines changed: 10 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,7 @@ FusionTree
1313
## Methods for defining and generating fusion trees
1414

1515
```@docs
16-
fusiontrees(uncoupled::NTuple{N,I}, coupled::I,
17-
isdual::NTuple{N,Bool}) where {N,I<:Sector}
16+
fusiontrees(uncoupled::NTuple{N, I}, coupled::I, isdual::NTuple{N, Bool}) where {N, I<:Sector}
1817
```
1918

2019
## Methods for manipulating fusion trees
@@ -23,31 +22,29 @@ For manipulating single fusion trees, the following internal methods are defined
2322
```@docs
2423
insertat
2524
split
25+
TensorKit.join
2626
merge
2727
elementary_trace
28-
planar_trace(f::FusionTree{I,N}, q1::IndexTuple{N₃}, q2::IndexTuple{N₃}) where {I<:Sector,N,N₃}
28+
planar_trace(f::FusionTree, q::Index2Tuple)
2929
artin_braid
30-
braid(f::FusionTree{I,N}, levels::NTuple{N,Int}, p::NTuple{N,Int}) where {I<:Sector,N}
31-
permute(f::FusionTree{I,N}, p::NTuple{N,Int}) where {I<:Sector,N}
30+
braid(f::FusionTree{I, N}, p::IndexTuple{N}, levels::IndexTuple{N}) where {I, N}
31+
permute(f::FusionTree{I, N}, p::IndexTuple{N}) where {I, N}
3232
```
3333

3434
These can be composed to implement elementary manipulations of fusion-splitting tree pairs, according to the following methods
3535

36-
```julia
37-
# TODO: add documentation for the following methods
36+
```@docs
3837
TensorKit.bendright
3938
TensorKit.bendleft
4039
TensorKit.foldright
4140
TensorKit.foldleft
42-
TensorKit.cycleclockwise
43-
TensorKit.cycleanticlockwise
4441
```
4542

4643
Finally, these are used to define large manipulations of fusion-splitting tree pairs, which are then used in the index manipulation of `AbstractTensorMap` objects.
4744
The following methods defined on fusion splitting tree pairs have an associated definition for tensors.
4845
```@docs
49-
repartition(::FusionTree{I,N₁}, ::FusionTree{I,N₂}, ::Int) where {I<:Sector,N₁,N₂}
50-
transpose(::FusionTree{I}, ::FusionTree{I}, ::IndexTuple{N₁}, ::IndexTuple{N₂}) where {I<:Sector,N₁,N₂}
51-
braid(::FusionTree{I}, ::FusionTree{I}, ::IndexTuple, ::IndexTuple, ::IndexTuple{N₁}, ::IndexTuple{N₂}) where {I<:Sector,N₁,N₂}
52-
permute(::FusionTree{I}, ::FusionTree{I}, ::IndexTuple{N₁}, ::IndexTuple{N₂}) where {I<:Sector,N₁,N₂}
46+
repartition(src::Union{FusionTreePair, FusionTreeBlock}, N::Int)
47+
Base.transpose(src::Union{FusionTreePair, FusionTreeBlock}, p::Index2Tuple)
48+
braid(src::Union{FusionTreePair, FusionTreeBlock}, p::Index2Tuple, levels::Index2Tuple)
49+
permute(src::Union{FusionTreePair, FusionTreeBlock}, p::Index2Tuple)
5350
```

docs/src/man/fusiontrees.md

Lines changed: 36 additions & 25 deletions
Large diffs are not rendered by default.

src/TensorKit.jl

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -123,8 +123,8 @@ using OhMyThreads
123123
using ScopedValues
124124

125125
using TensorKitSectors
126-
import TensorKitSectors: dim, BraidingStyle, FusionStyle, ,
127-
import TensorKitSectors: dual, type_repr
126+
import TensorKitSectors: dim, BraidingStyle, FusionStyle, , , ×
127+
import TensorKitSectors: dual, type_repr, fusiontensor
128128
import TensorKitSectors: twist
129129

130130
using Base: @boundscheck, @propagate_inbounds, @constprop,
@@ -215,6 +215,19 @@ function set_num_transformer_threads(n::Int)
215215
return TRANSFORMER_THREADS[] = n
216216
end
217217

218+
const TREEMANIPULATION_THREADS = Ref(1)
219+
220+
get_num_manipulation_threads() = TREEMANIPULATION_THREADS[]
221+
222+
function set_num_manipulation_threads(n::Int)
223+
N = Base.Threads.nthreads()
224+
if n > N
225+
n = N
226+
Strided._set_num_threads_warn(n)
227+
end
228+
return TREEMANIPULATION_THREADS[] = n
229+
end
230+
218231
# Definitions and methods for tensors
219232
#-------------------------------------
220233
# general definitions

src/auxiliary/auxiliary.jl

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,20 @@ function permutation2swaps(perm)
2727
return swaps
2828
end
2929

30+
# one-argument version: check whether `p` is a cyclic permutation (of `1:length(p)`)
31+
function iscyclicpermutation(p)
32+
N = length(p)
33+
@inbounds for i in 1:N
34+
p[mod1(i + 1, N)] == mod1(p[i] + 1, N) || return false
35+
end
36+
return true
37+
end
38+
# two-argument version: check whether `v1` is a cyclic permutation of `v2`
39+
function iscyclicpermutation(v1, v2)
40+
length(v1) == length(v2) || return false
41+
return iscyclicpermutation(indexin(v1, v2))
42+
end
43+
3044
_kron(A, B, C, D...) = _kron(_kron(A, B), C, D...)
3145
function _kron(A, B)
3246
sA = size(A)

0 commit comments

Comments
 (0)