Derive named auxiliary legs in project - #231
Merged
Merged
Conversation
The named `project`, `tryproject`, and `unchecked_project` methods now derive a named auxiliary leg for each surplus axis of the input array, matching the bare graded-space form. A surplus trailing axis is an auxiliary leg the backend added to keep the result symmetry-allowed, for example a flux-canceling charge leg for a charge-shifting operator, and it now comes back as a named dimension. Also qualifies `space`, `dim`, `dual`, and `scalar` as `TK.*` in the TensorKit-extension tests, since `ITensorBase` marks `space` public and it otherwise clashes with the `TensorKit` import.
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #231 +/- ##
==========================================
+ Coverage 78.02% 78.15% +0.12%
==========================================
Files 30 30
Lines 1734 1744 +10
==========================================
+ Hits 1353 1363 +10
Misses 381 381
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 backend derives the space of at most one trailing surplus axis (the flux-canceling leg appended as the last domain axis), so the docstring and comment describe one such axis rather than an arbitrary number.
The metaprogrammed methods now only forward each named-index signature to a `<verb>_nameddims` worker, matching the `mul_nameddims` and `matricize_nameddims` pattern already in this file. The workers hold the strip, lower, reattach logic as plain functions that are easy to read on their own, and one body per verb also covers the empty codomain (since `unnamed.(())` and `name.(())` are both `()`), so the separate empty-codomain method collapses. `name_projected` attaches the names and the aux leg the backend may append.
Use `uniquename(eltype(input_names))` rather than a name instance, matching how the other named-tensor helpers in this file mint fresh names from the dim-name type.
Attach a docstring to each of the three named-index methods describing the named-tensor layer: the index-selected backend, the codomain/domain split, and the derived auxiliary leg. Only `project` carried this docstring before, with the other two mentioned only in its text. A shared fragment is interpolated into all three so they stay in sync.
Loop the surplus-axis aux-leg assertions over all three named-index verbs, not just `project`. They share the `name_projected` path and the docstrings assert all three derive the leg, so cover `tryproject` and `unchecked_project` too.
mtfishman
enabled auto-merge (squash)
July 27, 2026 20:05
mtfishman
added a commit
to mtfishman/TensorNetworkQuantumSimulator.jl
that referenced
this pull request
Jul 27, 2026
Builds `project_aux` and `project_pair` through ITensorBase's named `project`/`tryproject`, which now derive and name the flux-canceling auxiliary leg from a trailing surplus axis (ITensor/ITensorBase.jl#231). The `space.(...)` unwrap, the `Index(TensorAlgebra.axes(...))` re-mint, and the `ITensor(...)` wrap all go away: `project_aux`'s aux fallback becomes a single `project` call, and `project_pair` drops from four functions (bare-space core, `_itensor` wrapper, two named dispatch entries) to one that reads the shared aux off the first result with `last(inds(p1))`. Bumps the ITensorBase compat floor to `0.13.7`.
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
The named
project,tryproject, andunchecked_projectmethods (the ones takingNamedUnitRangeindices) now derive a named auxiliary leg for a surplus axis of the input array. When the array carries one more axis than the codomain and domain indices account for, that trailing axis is an auxiliary leg the backend added to keep the result symmetry-allowed, for example a flux-canceling charge leg for a charge-shifting operator likeCdag. It now comes back as a named dimension with a freshly minted name, so a caller can read it off the result.An operator that shifts charge can then be built directly through
projectby reshaping its dense matrix to a trailing length-1 axis:project(reshape(m, (size(m)..., 1)), (prime(i),), (i,))returns the operator with its flux carried on a named aux index. The bare graded-space form already derived this axis, but the named wrappers passed it through unnamed.Also qualifies
space,dim,dual, andscalarasTK.*in the TensorKit-extension tests.ITensorBasemarksspacepublic, so an unqualifiedusing TensorKit: spaceclashes with it when the tests run in a session that already hasITensorBase'sspacein scope.