Repository navigation
Conversation
Codecov Report✅ All modified and coverable lines are covered by tests.
🚀 New features to boost your workflow:
|
lkdvos
approved these changes
Nov 27, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Since TensorKit v0.17.4 (QuantumKitHub/TensorKit.jl#599),
twist(t, inds)calls the newtwist!(tdst, tsrc, inds, α, β, ...), which unwraps adjoints and calls the internal_twist!. BlockTensorKit only overloaded the in-placetwist!(t, inds), so for block tensorstwistand the newtwist!ended up in TensorKit's generic kernel.What went wrong though, is that for a sparse block tensor the subblock of a missing block is just a temporary zero array, so
twistof a sparse block tensor returns zeros, andtwist!into a sparse destination drops blocks it didn't already have.What worked but was slow due to the generic fallback in TK was dense block tensors (by a factor 5 at least, up to 20).
This PR overloads
TK._twist!blockwise, like_braid!, with one difference: in_twist!the twist mask refers to the legs of the source.I added a test covering
twistandtwist!(tdst, tsrc, ...)with dense/sparse source and destination, with and without adjoint, which currently fails on main.transpose!could get the same treatment through_transpose!, but BlockTensorKit'stranspose!already supports this except for aAdjointTensorMap(D)destination. That case is wrong for a sparseDand slow for a dense one, so I'll look into that as well.