Skip to content

[WIP] Name-based index-set algebra, whole-tensor index ops, and the id/uuid rename#213

Draft
mtfishman wants to merge 6 commits into
mainfrom
mf/nextgen-followups-round1
Draft

[WIP] Name-based index-set algebra, whole-tensor index ops, and the id/uuid rename#213
mtfishman wants to merge 6 commits into
mainfrom
mf/nextgen-followups-round1

Conversation

@mtfishman

Copy link
Copy Markdown
Member

Summary

A batch of next-generation index and identity utilities for AbstractNamedTensor, plus one breaking rename. Depends on TensorAlgebra ITensor/TensorAlgebra.jl#205 and is pinned to its branch via [sources] while that is in flight.

  • Name-based index-set algebra: commoninds, uniqueinds, unioninds, noncommoninds, hascommoninds, the singular commonind/uniqueind, and the non-erroring trycommonind/trynoncommonind. Indices match by name, so a shared bond matches even when one tensor carries its dual.
  • Whole-tensor index manipulation: prime, noprime, and sim on a tensor relabel every index, built on mapinds/replaceinds. These are the index-level counterpart of replacedimnames/mapdimnames, a name-only relabel that changes an index's name and leaves its space untouched.
  • id(elt, codomain, domain): the from-scratch identity operator, a sibling of one(a, codomain, domain) that needs only the indices and an element type rather than a prototype tensor. Exported.
  • svd_trunc truncation error: the named-tensor wrapper now returns (U, S, Vᴴ, ϵ) to match the matrix-level primitive, so the discarded weight is available directly.
  • Smaller fixes: a clearer error when building a tensor from a single named range, index-keyed pairs in replacedimnames, and trivialrange for a NamedUnitRange.

Breaking: the unique-identifier accessor on an index or index name is renamed from id to uuid, freeing id for the identity constructor.

TODO

  • Remove the [sources.TensorAlgebra] pin once the required TensorAlgebra version registers.
  • Dogfood the cross-pinned stack downstream before marking ready.

mtfishman added 6 commits July 8, 2026 14:34
…runc ϵ, trivialrange for named ranges

Bugfixes and additive index utilities. `ITensor(array, Index-tuple)` now throws
with guidance toward `array[i, j]` and `ITensor(array, name.((i, j)))` instead of
silently mis-constructing. `replacedimnames` accepts `Index` keys by stripping to
the dimname. `svd_trunc` returns the truncation error `ϵ` as a fourth output. And
`trivialrange(::NamedUnitRange)` mints a fresh trivial named range on the same
backend.
…replaceinds, rank-0 similar/one

Whole-tensor index manipulation on `AbstractNamedTensor`. `mapinds(f, t)` relabels
every index name-only (leaving the space untouched), with `prime(t)`, `noprime(t)`,
and `sim(t)` built on it. `replaceinds` becomes a name-only relabel, a synonym for
`replacedimnames`, and `sim(i)` mints a fresh id preserving tags and prime level.
`similar(a, ())` and `one(a)` give a rank-0 scalar tensor on `a`'s backend.
Adds `commoninds`, `uniqueinds`, `unioninds`, `noncommoninds`, and `hascommoninds` on `AbstractNamedTensor`, along with the singular `commonind`/`uniqueind` and their non-erroring `trycommonind`/`trynoncommonind` counterparts. Indices are compared by name, so a shared bond matches even when the two tensors carry it as an index on one and its dual on the other.
The function form of `replaceinds`/`mapinds` forwarded straight to `replacedimnames`, so its `f` received a dimension name rather than the index its docstring describes. Apply `f` to each index instead, relabeling name-only through the pair form, so `replaceinds`/`mapinds` are the index-level counterpart of the name-level `replacedimnames`/`mapdimnames`.
…ity constructor

Rename the unique-identifier accessor `id` on `IndexName`/`Index` to `uuid` (along with the struct field, the constructor keyword, and the `setuuid` setter), freeing the `id` name for the identity-tensor constructor. Add `id(elt, codomain, domain)`, the from-scratch identity operator over the given codomain and domain indices, a sibling of `one(a, codomain, domain)` that needs only the indices and an element type rather than a prototype tensor. `id` is exported.

Breaking: `ITensorBase.id` on an index or index name is now `ITensorBase.uuid`.
`name` already strips an index to its dimension name and passes a bare name through unchanged, so `to_dimname` duplicated it. Call `name` directly when normalizing relabel pairs, which handles either an index or a bare name on either side of the pair.
@codecov

codecov Bot commented Jul 8, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 23.80952% with 64 lines in your changes missing coverage. Please review.
✅ Project coverage is 23.01%. Comparing base (daa7646) to head (02e184a).

Files with missing lines Patch % Lines
src/abstractnamedtensor.jl 2.63% 37 Missing ⚠️
src/tensoralgebra.jl 23.80% 16 Missing ⚠️
src/index.jl 61.11% 7 Missing ⚠️
src/namedunitrange.jl 0.00% 4 Missing ⚠️

❗ There is a different number of reports uploaded between BASE (daa7646) and HEAD (02e184a). Click for more details.

HEAD has 13 uploads less than BASE
Flag BASE (daa7646) HEAD (02e184a)
docs 2 1
12 0
Additional details and impacted files
@@             Coverage Diff             @@
##             main     #213       +/-   ##
===========================================
- Coverage   74.40%   23.01%   -51.40%     
===========================================
  Files          30       29        -1     
  Lines        1567     1590       +23     
===========================================
- Hits         1166      366      -800     
- Misses        401     1224      +823     
Flag Coverage Δ
docs 23.01% <23.80%> (-0.12%) ⬇️

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.

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