Add project convenience for symmetry-restricted arrays and TensorMap support#203
Merged
Conversation
…support Adds `project`, an owned convenience over the existing `project_map` hook for building a symmetry-restricted array from a dense one. The three-argument form takes an explicit codomain/domain split and the two-argument form takes a flat list of axes (an empty domain), both forwarding to `project_map`. `checked_project` is the verified counterpart of `checked_project_map`. This mirrors the `zeros`/`zeros_map` pairing, where the unsuffixed name is the convenience that also accepts the codomain/domain split. Also adds the `TensorMap` path in the TensorKit extension so `project` can build a `TensorMap` from a dense array: `similar_map` allocates a same-device buffer whose block storage type follows the dense prototype, `projectto!` fills the symmetry-allowed blocks through `project_symmetric!` and discards the rest, and `checked_projectto!` verifies the projection by norm, since a dense array and a `TensorMap` are not comparable elementwise and projection onto the symmetric blocks preserves the norm exactly when nothing is discarded.
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #203 +/- ##
==========================================
- Coverage 84.03% 83.90% -0.13%
==========================================
Files 24 24
Lines 739 758 +19
==========================================
+ Hits 621 636 +15
- Misses 118 122 +4
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
The two `similar_map` methods for a dense prototype with space axes had identical bodies and existed only to pin the elementary space type `S` from whichever of codomain/domain is non-empty. Factor the body into a `similar_tensormap` helper that takes `S` explicitly, matching the `_map_homspace` helper and the two-entries-per-constructor pattern used for the map constructors.
Densify the `TensorMap` destination with `convert(Array, ...)` and reuse the dense path's `isapprox(src, dest)` check in `checked_projectto!` instead of the norm-based shortcut, so the check keeps one `InexactError`/`kwargs` contract across backends rather than diverging toward TensorKit's residual-norm `tol`/`ArgumentError` check.
mtfishman
added a commit
to ITensor/ITensorBase.jl
that referenced
this pull request
Jul 2, 2026
## Summary Adds methods extending `TensorAlgebra.project` and `TensorAlgebra.checked_project` (added in ITensor/TensorAlgebra.jl#203) that build a named tensor from a dense array and the indices to attach. The three-argument form takes a codomain/domain split (an operator), and the two-argument form takes a flat list of indices (a state, i.e. an empty domain). The index axes select the backend, so the same call builds an `Array` on dense indices, a block-sparse array on graded indices, and a `TensorMap` on TensorKit spaces. The named entry strips to the unnamed array plus axes, lowers to `TensorAlgebra.project`, and reattaches the names. This is the named-index projection primitive for building symmetric operators and states from a dense basis matrix: `project(Sz, (i',), (i,))` for an operator, `project(v, (i,))` for a state.
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.
Summary
Adds
project, an owned convenience over the existingproject_maphook for building a symmetry-restricted array from a dense one. The three-argument form takes an explicit codomain/domain split and the two-argument form takes a flat list of axes (an empty domain), both forwarding toproject_map, andchecked_projectis the verified counterpart ofchecked_project_map. This mirrors thezeros/zeros_mappairing, where the unsuffixed name is the convenience that also accepts the codomain/domain split.Also adds the
TensorMappath in the TensorKit extension soprojectcan build aTensorMapfrom a dense array:similar_mapallocates a same-device buffer whose block storage type follows the dense prototype,projectto!fills the symmetry-allowed blocks throughproject_symmetric!and discards the rest, andchecked_projectto!verifies the projection by densifying the result and reusing the dense path's elementwiseisapprox(src, dest)check, so it keeps oneInexactError/kwargscontract across backends.The named-index
projectforAbstractITensoris added in ITensor/ITensorBase.jl#208.