Skip to content

Commit 40ba9cd

Browse files
committed
update precompilation docs
1 parent 054aa33 commit 40ba9cd

3 files changed

Lines changed: 45 additions & 42 deletions

File tree

docs/make.jl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ pages = [
3333
"man/indexmanipulations.md",
3434
"man/factorizations.md",
3535
"man/contractions.md",
36+
"man/precompilation.md",
3637
],
3738
],
3839
"Library" => [

docs/src/man/contractions.md

Lines changed: 0 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -317,45 +317,3 @@ Since in this case `@tensor` and `@planar` yield different results, the `@planso
317317

318318

319319
[^Mortier]: Mortier, Q., Devos, L., Burgelman, L., et al. (2025). Fermionic Tensor Network Methods. SciPost Physics 18, no. 1. [10.21468/SciPostPhys.18.1.012](https://doi.org/10.21468/SciPostPhys.18.1.012).
320-
321-
## Precompilation
322-
323-
The first tensor contraction in a Julia session incurs a significant compilation latency
324-
(time-to-first-execution, TTFX). To mitigate this, TensorKit ships a precompilation workload
325-
that is **enabled by default**: it runs a small set of representative contractions, traces and
326-
permutations for the `Trivial`, `Z2Irrep`, `SU2Irrep` and `FermionParity` symmetries over
327-
`Float64` and `ComplexF64`.
328-
329-
Because the numerically-heavy kernels are *sector-agnostic* (they depend only on the element
330-
type, the arity, and `sectorscalartype`), this workload also speeds up the first contraction of
331-
symmetries that are *not* in the workload — including user-defined ones.
332-
333-
The workload can be tuned or disabled through [Preferences](https://github.com/JuliaPackaging/Preferences.jl):
334-
335-
```julia
336-
using TensorKit, Preferences
337-
# disable the workload entirely (fastest precompilation, no TTFX benefit)
338-
set_preferences!(TensorKit, "precompile_workload" => false; force=true)
339-
# restrict the element types
340-
set_preferences!(TensorKit, "precompile_eltypes" => ["Float64"]; force=true)
341-
# restrict / change the symmetries that are precompiled
342-
set_preferences!(TensorKit, "precompile_sectors" => ["Trivial", "Z2Irrep"]; force=true)
343-
# change the tensor arities (leg counts) that are precompiled, e.g. up to rank-6 for PEPS/PEPO
344-
set_preferences!(TensorKit, "precompile_ndims" => [2, 3, 4, 5, 6]; force=true)
345-
```
346-
347-
Changing a preference triggers recompilation of TensorKit the next time it is loaded.
348-
349-
Downstream packages that define their own symmetry can precompile TensorKit's contraction path
350-
for it by calling [`precompile_contract`](@ref) inside their own `PrecompileTools.@compile_workload`:
351-
352-
```julia
353-
using TensorKit, PrecompileTools
354-
@compile_workload begin
355-
TensorKit.precompile_contract(Vect[MyAnyon](s₀ => 1, s₁ => 1))
356-
end
357-
```
358-
359-
```@docs; canonical=false
360-
precompile_contract
361-
```

docs/src/man/precompilation.md

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
# Precompilation
2+
3+
The first tensor operation in a Julia session — a contraction, an index manipulation, or a factorization — incurs a significant compilation latency (time-to-first-execution, TTFX).
4+
To mitigate this, TensorKit ships a precompilation workload that is **enabled by default**:
5+
it runs a small set of representative index manipulations, contractions and factorizations for the `Trivial`, `Z2Irrep`, `SU2Irrep` and `FermionParity` symmetries over `Float64` and `ComplexF64`.
6+
7+
Because the numerically-heavy kernels are mostly *sector-agnostic* (they depend only on the element type, the arity, and `sectorscalartype`),
8+
this workload also speeds up the first operation on symmetries that are *not* in the workload — including user-defined ones.
9+
10+
The workload can be tuned or disabled through [Preferences](https://github.com/JuliaPackaging/Preferences.jl):
11+
12+
```julia
13+
using TensorKit, Preferences, PrecompileTools
14+
# disable the workload entirely (fastest precompilation, no TTFX benefit)
15+
PrecompileTools.set_preferences!(TensorKit, "precompile_workloads" => false; force=true)
16+
# disable individual suites (each defaults to `true`)
17+
set_preferences!(TensorKit, "precompile_contract" => false; force=true)
18+
set_preferences!(TensorKit, "precompile_indexmanipulations" => false; force=true)
19+
set_preferences!(TensorKit, "precompile_factorizations" => false; force=true)
20+
# restrict the element types
21+
set_preferences!(TensorKit, "precompile_eltypes" => ["Float64"]; force=true)
22+
# restrict / change the symmetries that are precompiled
23+
set_preferences!(TensorKit, "precompile_sectors" => ["Trivial", "Z2Irrep"]; force=true)
24+
# highest tensor arity (leg count) to precompile, i.e. arities `1:n`; e.g. rank-6 for PEPS/PEPO
25+
set_preferences!(TensorKit, "precompile_ndims" => 6; force=true)
26+
```
27+
28+
Changing a preference triggers recompilation of TensorKit the next time it is loaded.
29+
30+
Downstream packages or startup files that define or heavily use their own symmetry can precompile TensorKit's operations for it by
31+
calling the `precompile_*` helpers inside their own `PrecompileTools.@compile_workload`:
32+
33+
```julia
34+
using TensorKit, PrecompileTools
35+
@compile_workload begin
36+
TensorKit.precompile_contract(Vect[MyAnyon](s₀ => 1, s₁ => 1))
37+
end
38+
```
39+
40+
```@docs; canonical=false
41+
TensorKit.precompile_contract
42+
TensorKit.precompile_indexmanipulations
43+
TensorKit.precompile_factorizations
44+
```

0 commit comments

Comments
 (0)