Precompute planar trace kernels in a `TraceTransformer` #605
All Vouch review confidence checks passed
Residual risk 0.21 = Change Risk (0.52) × (1 − Review Confidence (0.60)).
Review depth and reviewer attention state are adequate.
Model 1 · Change Risk (XGBoost)
Score: 0.52 · 650 lines diff across 8 files
Model 2 · Review Depth (DistilBERT)
Depth Score: 0.17 · 1 substantive comment(s)
Model 3 · Review Timing & Attention
Session adequacy: 100% · Reviewer familiarity: 35%
Bedrock Claude 3 · Risk Narration
(disconnected)
Groq Risk Narration
AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
Model 1 · Change Risk Attribution
SHAP Weights
Diff Size
diff_size
0.388
Shallow Review Depth
shallow_review_depth
0.289
Real PR Conversation Timeline
1 comments
"Review active on #605"
general
weight: 0.35
kshyatt
This replaces the per-tree loop in
planartrace!, which used the fusion tree internals through ad-hoc single-pairFusionTreeBlocks, with the same precompute/execute split as the index manipulations (treetransformers.jl/indexmanipulations.jl).Fusion trees
planar_trace(src::Union{FusionTreePair, FusionTreeBlock}, p, q)follows the conventions oftranspose/repartition: unique-fusion pairs map todst => coeff, blocks todst => Uwith a dense recoupling matrix. It repartitions all legs to the outgoing side, traces the splitting trees into the full block of remaining trees, and transposes that block.trace_sectors_matchinstead, which in the generic case avoids computing repartitions/transposes of blocks that vanish anyway.FusionTreeBlocks now hash their uncoupled sectors and duality flags, since the ad-hoc single-pair blocks are gone.Precompute:
TraceTransformer@cached treetracer(A, Vdst, Vsrc, p, q), keyed on the destination storagetype like the other transformers.(U, inds_dst, inds_src)entries, grouped by destination block: several source blocks (one per traced sector) contribute to the same destination. Every destination subblock appears in exactly one entry, so threaded tasks never write the same subblock, and subblocks without contributions get an entry that only scales byβ.Execute:
trace_transform_kernel!add_transform_kernel!, including the per-task workspaces.βon the first contribution._recouple!), and add into the destinations.GPU kernel
TraceTransformerintoisbitsdescriptors (cached per device storagetype, like the braid/transpose transformers) and trace in two stages:1. partial traces: one thread per (chunk, remaining entry) of every source subblock sums at most
max(256, √ntraced)traced entries (one summed stride per traced pair) into a scratch buffer fromallocator, so full reductions and traces with few remaining entries are still spread over many threads;2. recoupling: one thread per destination element sums the partials of every source, weighted by the recoupling coefficients, so the traced entries are summed once per source rather than once per destination tree.
TensorMaps first. Tracing subblock views with cuTENSOR, as the previous implementation did for all GPU tensors, fails withCUDA error: misaligned addressfor data at unaligned offsets (reproduced forFloat64fℤ₂ ⊠ SU₂ data)._linear_indexis now an explicit loop, sincesum(())(a full trace) does not compile for GPUs.Float64andComplexF64, including adjoint sources,β = 0with NaN-filled output, and full traces split into several chunks.test/cuda/planar.jlgains a symmetricplanartracetest for every space in the spacelist and for large traces;cuda/planarandcuda/tensorspass locally.| | partial (3 legs left) | 1 leg left | full reduction |
|---|---|---|---|
| fℤ₂ | 0.28 → 0.31 ms | 4.0 → 0.25 ms | 4.0 → 0.19 ms |
| Fibonacci | 0.16 → 0.20 ms | 2.8 → 0.21 ms | 2.8 → 0.18 ms |
| fℤ₂ ⊠ SU₂ | 0.042 → 0.036 ms | 0.81 → 0.12 ms | 0.81 → 0.12 ms |
Enzyme rules
taskforeachin the new trace kernel (IllegalTypeAnalysisExceptioninsync_end), soplanartrace!now has forward and reverse Enzyme rules, structured like thepermute!/transpose!rules.treetraceris marked inactive, liketreetransposer/treebraider.planartrace_pullback_ΔA!reuses the cachedTraceTransformer: it addsΔCto the traced diagonal of every source subblock (aStridedViewwith summed strides, no identity tensor), with coefficientsconj(α U[i, j]) dim(cᵢ) / dim(cⱼ)sinceinnerweighs every block withdim(c). It goes through_transform_subblocks, so adjoint tensors are supported, and falls back totrace_permute_pullback_ΔA!for bosonic sectors.planartrace!test skipped every draw without a remaining leg or traced pair, which in practice skipped (almost) all of them, so this was never tested. It now always draws at least one of each, retries multifusion draws with mismatched units, and also compares the pullback of adjoint tensors.⟨ΔC, tr(dA)⟩ = ⟨pullback(ΔC), dA⟩for fℤ₂, Fibonacci, fℤ₂ ⊠ SU₂, Fibonacci ⊠ fℤ₂ and SU₂ with partial, nested, full and domain traces;enzyme/tracepasses locally withCI=true(16145 tests, ~28 min locally, previously theplanartrace!part was effectively empty).Testing
tensors/planar,tensors/contractionsandsymmetries/doubletreepass locally; the planar trace test indoubletree.jlnow uses the block method for generic fusion.Not covered: JET was not run locally (it passes in CI); the GPU kernels were only tested on CUDA, not AMDGPU.
🤖 Generated with Claude Code