Skip to content

Let's twist again! - #612

Open
lkdvos wants to merge 6 commits into
mainfrom
contract-fuse
Open

lkdvos wants to merge 6 commits into
mainfrom
contract-fuse

Conversation

@lkdvos

@lkdvos lkdvos commented Nov 5, 2026 •

Copy link
Copy Markdown
Member

For fermionic sectors, blas_contract! twists the contracted legs of one of the operands. That operand is always copied first, so this PR folds the twist into the recoupling coefficients of the copy, instead of running a separate twist! pass over it (#595).

  • treebraider takes a twistmask on the destination legs. Twists are diagonal in the fusion tree basis, so they are multiplied into the braiding coefficients. Ordinary braids and permutations pass an all-false mask and are unchanged, so no extra transformer type or cache is needed. _braid! and its GPU and diagonal-GPU counterparts gain the same argument.
  • blas_contract! computes both twist masks in contraction_twistmasks and always copies through permute_twist!, passing an all-false mask when no twist is needed.

On a fℤ₂×U(1) operand with 1336 subblocks, the twisted copy goes from 0.80 ms to 0.40 ms.

This also fixes the GPU "Adapt SectorVector" test from #610: for IsingBimodule, V1 ⊗ V2 ← V3 has incompatible units and threw a SpaceMismatch, so it now reuses the space of the "Adapt" testset.

Tested locally on Julia 1.13: the contraction, index manipulation, diagonal, braiding tensor and planar suites, the CUDA tensor suite and the Mooncake contraction tests pass. Enzyme was not run locally.

🤖 Generated with Claude Code

lkdvos and others added 3 commits November 4, 2026 16:25
The operand that `blas_contract!` twists for fermionic sectors is always copied first, so the
twist is now folded into the recoupling coefficients of that copy through a cached
`treepermuter`, instead of a separate `twist!` pass over the copied operand (#595).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…epermuter`

`blas_contract!` now computes the twist masks of both operands in `contraction_twistmasks`
and always copies through `permute_twist!`, with an all-false mask when no twist is needed.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
`V1 ⊗ V2 ← V3` has incompatible units for `IsingBimodule`; reuse the space of the `Adapt` testset.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@lkdvos
lkdvos marked this pull request as ready for review November 5, 2026 16:18
@kshyatt

kshyatt commented Nov 12, 2026

Copy link
Copy Markdown
Member

This also fixes the GPU "Adapt SectorVector" test from #610: for IsingBimodule, V1 ⊗ V2 ← V3 has incompatible units and threw a SpaceMismatch, so it now reuses the space of the "Adapt" testset.

I think this already got fixed, right?

@Jutho

Jutho commented Nov 19, 2026

Copy link
Copy Markdown
Member

My first and probably most pertinent comment is that this PR's title should clearly have been: "let's twist again".

@lkdvos lkdvos changed the title Fold the twist of fermionic contraction operands into their permutation Let's twist again! Nov 20, 2026
Jutho and others added 2 commits November 20, 2026 13:45
Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
Comment thread src/tensors/tensoroperations.jl Resolved
The GPU method still had the old six-argument signature, so the new
seven-argument call from `_braid!` fell back to the host `treebraider` and
built a host transformer for GPU storage, which `add_transform_kernel!`
in the GPU extension does not accept.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@codecov

codecov Bot commented Nov 21, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

Files with missing lines Coverage Δ
ext/TensorKitGPUArraysExt.jl 96.96% <100.00%> (ø)
src/tensors/indexmanipulations.jl 91.53% <100.00%> (+0.03%) ⬆️
src/tensors/tensoroperations.jl 97.35% <100.00%> (+0.01%) ⬆️
src/tensors/treetransformers.jl 96.71% <100.00%> (+0.71%) ⬆️

... and 17 files with indirect coverage changes

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

This branch has not been deployed

No deployments
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.

3 participants