Precompilation

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). To mitigate this, TensorKit ships a precompilation workload that is enabled by default: it runs a small set of representative index manipulations, contractions and factorizations for the Trivial, Z2Irrep, SU2Irrep and FermionParity symmetries over Float64 and ComplexF64.

Because the numerically-heavy kernels are mostly sector-agnostic (they depend only on the element type, the arity, and sectorscalartype), this workload also speeds up the first operation on symmetries that are not in the workload — including user-defined ones.

The workload can be tuned or disabled through Preferences:

using TensorKit, Preferences, PrecompileTools
# disable the workload entirely (fastest precompilation, no TTFX benefit)
PrecompileTools.set_preferences!(TensorKit, "precompile_workload" => false; force=true)
# disable individual suites (each defaults to `true`)
set_preferences!(TensorKit, "precompile_contract" => false; force=true)
set_preferences!(TensorKit, "precompile_indexmanipulations" => false; force=true)
set_preferences!(TensorKit, "precompile_factorizations" => false; force=true)
# restrict the element types
set_preferences!(TensorKit, "precompile_eltypes" => ["Float64"]; force=true)
# restrict / change the symmetries that are precompiled
set_preferences!(TensorKit, "precompile_sectors" => ["Trivial", "Z2Irrep"]; force=true)
# highest tensor arity (leg count) to precompile, i.e. arities `1:n`; e.g. rank-6 for PEPS/PEPO
set_preferences!(TensorKit, "precompile_ndims" => 6; force=true)

Changing a preference triggers recompilation of TensorKit the next time it is loaded.

Downstream packages or startup files that define or heavily use their own symmetry can precompile TensorKit's operations for it by calling the precompile_* helpers inside their own PrecompileTools.@compile_workload:

using TensorKit, PrecompileTools
@compile_workload begin
    TensorKit.Precompilation.precompile_contract(Vect[MySector])
end
TensorKit.Precompilation.precompile_contractFunction
precompile_contract(S::Type{<:IndexSpace}; eltypes=[Float64, ComplexF64], ndims=4)

Run a small, representative set of contraction, trace, and permutation operations on tensors built from the space V = unitspace(S), for each element type in eltypes and each tensor arity (number of legs) in 1:ndims.

Note that it can be beneficial to put a more comprehensive set of relevant symmetries in a startup file, for example by adding:

@compile_workload begin
    TensorKit.precompile_contract(Vect[MySector])
end

See also precompile_indexmanipulations, precompile_factorizations.

source
TensorKit.Precompilation.precompile_indexmanipulationsFunction
precompile_indexmanipulations(S::Type{<:IndexSpace}; eltypes=[Float64, ComplexF64], ndims=4)

Run a small, representative set of index-manipulation operations on tensors built from the space V = unitspace(S), for each element type in eltypes and each tensor arity (number of legs) in 1:ndims.

Note that it can be beneficial to put a more comprehensive set of relevant symmetries in a startup file, for example by adding:

@compile_workload begin
    TensorKit.precompile_indexmanipulations(Vect[MySector])
end

See also precompile_contract, precompile_factorizations.

source
TensorKit.Precompilation.precompile_factorizationsFunction
precompile_factorizations(S::Type{<:IndexSpace}; eltypes=[Float64, ComplexF64])

Run a small, representative set of tensor-factorization operations (singular value, QR, LQ, eigenvalue, orthogonal/null-space and polar decompositions) on tensors built from the space V = unitspace(S), for each element type in eltypes.

Note that it can be beneficial to put a more comprehensive set of relevant symmetries in a startup file, for example by adding:

@compile_workload begin
    TensorKit.precompile_factorizations(Vect[MySector])
end

See also precompile_contract, precompile_indexmanipulations.

source