Skip to content

Precompilation - #487

Open
lkdvos wants to merge 5 commits into
mainfrom
ld-blascompile
Open

Precompilation#487
lkdvos wants to merge 5 commits into
mainfrom
ld-blascompile

Conversation

@lkdvos

@lkdvos lkdvos commented Jul 14, 2026

Copy link
Copy Markdown
Member

This PR adds a precompilation suite to TensorKit.
It takes about 300 seconds on my machine, and is enabled by default.
Given the general migration of the ecosystem towards more heavy precompilation workflows, I think this is warranted, and I'm hoping this improves our CI times as well as the general user experiences.

I've also structured it in such a way that you could conceivably reuse this locally for projects with specific symmetry needs, to ensure faster startup times.
As in general TensorKit is not updated all that often, I hope this is not something that has to be retriggered too much, therefore I felt the ~5mins of precompilation time to be reasonable.

@lkdvos
lkdvos force-pushed the ld-blascompile branch 2 times, most recently from ce58308 to f6b5b49 Compare July 14, 2026 20:50
@codecov

codecov Bot commented Jul 14, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 96.07843% with 4 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
src/precompile/precompile.jl 86.95% 3 Missing ⚠️
src/tensors/indexmanipulations.jl 75.00% 1 Missing ⚠️
Files with missing lines Coverage Δ
src/TensorKit.jl 17.24% <ø> (ø)
src/fusiontrees/duality_manipulations.jl 95.86% <100.00%> (ø)
src/precompile/contract.jl 100.00% <100.00%> (ø)
src/precompile/factorizations.jl 100.00% <100.00%> (ø)
src/precompile/indexmanipulations.jl 100.00% <100.00%> (ø)
src/tensors/indexmanipulations.jl 88.40% <75.00%> (+0.04%) ⬆️
src/precompile/precompile.jl 86.95% <86.95%> (ø)

... and 1 file with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Comment thread docs/src/man/precompilation.md Outdated
Comment thread docs/src/man/precompilation.md Outdated
Comment thread src/precompile.jl Outdated
Comment thread src/tensors/indexmanipulations.jl
lkdvos and others added 4 commits August 26, 2026 05:32
Add `src/precompile.jl`: a default-on `@compile_workload` that runs
representative contractions, traces and permutations for `Trivial`, `Z2Irrep`,
`SU2Irrep` and `FermionParity` over `Float64`/`ComplexF64` and arities [2,3,4].
The heavy kernels (tree transformers, `add_transform!`, per-block BLAS `mul!`)
are sector-agnostic, so this also speeds up the first contraction of other
symmetries -- including user-defined ones.

The exported `precompile_contract(V; eltypes, ndims)` helper is the reusable
unit; downstream packages can call it for their own symmetry inside their own
`@compile_workload`. The workload is tunable/disable-able through Preferences
(`precompile_workload`, `precompile_eltypes`, `precompile_sectors`,
`precompile_ndims`), mirroring TensorOperations.

Also move `_repartition_body` above the `@generated repartition` that calls it
at generation time: the workload is the first code to trigger `repartition` at
precompile time, which exposed a latent world-age ordering bug (`UndefVarError`
that runtime masks via a later world age).

Adds PrecompileTools and Preferences dependencies.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@lkdvos
lkdvos marked this pull request as ready for review August 26, 2026 13:39
@lkdvos
lkdvos requested a review from borisdevos August 26, 2026 13:39
@lkdvos

lkdvos commented Aug 26, 2026

Copy link
Copy Markdown
Member Author

@borisdevos I'd be very interested in any timing results you have for the MPSKit testsuite on main TensorKit vs on this branch, in case you were already investigating

@lkdvos
lkdvos requested a review from Jutho August 26, 2026 14:19
@borisdevos

Copy link
Copy Markdown
Member

https://quantumkithub.github.io/TensorKit.jl/previews/PR487/man/precompilation/ for the relevant docs preview. Completely unrelated to this PR, but I noticed in the docs that the contents of tensors only show the first page, namely "Constructing tensors and the TensorMap type", and its subsections.

Besides that, with my one data point on the MPSKit tests, it seems this precompilation is useful, but my machine is so garbage that there's lots of noise, so I'm testing some of the heavier compilation files more.


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

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
TensorKit.precompile_contract(Vect[MySector])
TensorKit.Precompilation.precompile_contract(Vect[MySector])

I think? Same for the other 2 docstrings.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

they are actually exported from the precompilation module, so this is not required.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants