Skip to content

Derive named auxiliary legs in project - #231

Merged
mtfishman merged 6 commits into
mainfrom
mf/project-aux-leg
Jul 27, 2026
Merged

Derive named auxiliary legs in project#231
mtfishman merged 6 commits into
mainfrom
mf/project-aux-leg

Conversation

@mtfishman

@mtfishman mtfishman commented Jul 25, 2026

Copy link
Copy Markdown
Member

Summary

The named project, tryproject, and unchecked_project methods (the ones taking NamedUnitRange indices) 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 like Cdag. 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 project by 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, and scalar as TK.* in the TensorKit-extension tests. ITensorBase marks space public, so an unqualified using TensorKit: space clashes with it when the tests run in a session that already has ITensorBase's space in scope.

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

codecov Bot commented Jul 25, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 78.15%. Comparing base (d963009) to head (24e1edc).
⚠️ Report is 1 commits behind head on main.

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              
Flag Coverage Δ
docs 26.96% <50.00%> (+0.10%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

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

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
mtfishman enabled auto-merge (squash) July 27, 2026 20:05
@mtfishman
mtfishman merged commit c9144f8 into main Jul 27, 2026
17 checks passed
@mtfishman
mtfishman deleted the mf/project-aux-leg branch July 27, 2026 20:17
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`.
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