Skip to content

Fold the twist of fermionic contraction operands into their permutation - #612

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

lkdvos wants to merge 3 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

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.

1 participant