Skip to content

Add tag verbs, an Index keyword constructor, and factorization bond decoration#214

Merged
mtfishman merged 11 commits into
mainfrom
mf/tag-decoration-api
Jul 10, 2026
Merged

Add tag verbs, an Index keyword constructor, and factorization bond decoration#214
mtfishman merged 11 commits into
mainfrom
mf/tag-decoration-api

Conversation

@mtfishman

@mtfishman mtfishman commented Jul 9, 2026

Copy link
Copy Markdown
Member

Summary

Reworks the index tag interface around key-value tags and adds a consistent way to decorate the names that the Index constructor and the factorizations mint.

Because tags are key-value pairs, the plural verbs are now merge-based and permissive. settags inserts or overwrites the given tags (as one or more pairs, a collection of pairs, or an AbstractDict), unsettags removes a collection of keys, and emptytags clears them. Setting a tag that already exists overwrites it, and removing one that is absent is a no-op. These verbs, together with gettags, gettag, hastag, tags, plev, and decoration, are now public. settags previously replaced the entire tag dictionary and now merges, but it was neither exported nor public, so this is a non-breaking patch release.

Index(2; tags = "i" => "1", plev = 1) mints a fresh index carrying the given tags and prime level, and uniquename(IndexName; tags, plev) does the same at the name level.

Factorizations can now decorate the bonds they create. Each new bond takes a keyword, name for the single shared bond of the qr/lq/orth/polar/null family, and leftname/rightname for the two legs of the central matrix in svd and the eigendecompositions. Each accepts either a NamedTuple of decoration that is splatted into uniquename (leftname = (; tags = "link" => "1")) or a name-minting callback for full control over how the name is built. decoration(i) returns an index's (; tags, plev) for forwarding an existing bond's decoration onto a fresh one. The default leaves bonds bare, so existing calls mint the same undecorated names they do today. The Factorizations section of the user interface manual documents these keywords.

Also restores test/Project.toml's [sources.ITensorBase] path to .., which a machine-specific absolute path had replaced.

@codecov

codecov Bot commented Jul 10, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 75.95%. Comparing base (1917dea) to head (5690842).
⚠️ Report is 1 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #214      +/-   ##
==========================================
+ Coverage   74.65%   75.95%   +1.30%     
==========================================
  Files          30       30              
  Lines        1653     1680      +27     
==========================================
+ Hits         1234     1276      +42     
+ Misses        419      404      -15     
Flag Coverage Δ
docs 26.05% <21.73%> (+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.

mtfishman added 5 commits July 9, 2026 20:37
…ecoration

Rework index tags onto merge-based plural verbs (settags, unsettags, emptytags),
add an `Index(space; tags, plev)` keyword constructor and a
`uniquename(IndexName; tags, plev)` method, and let factorizations decorate the
bonds they mint via a per-bond keyword spec, either a NamedTuple splatted into
uniquename or a name-minting callback. settags now merges rather than replaces.
Rename the single-bond and null factorization keyword from `bondname` to
`name`, reaching the `name` function through the module (`ITensorBase.name`)
in the bodies where the keyword shadows it.
Splat `kwargs...` to the `IndexName` constructor rather than naming `tags`/`plev`,
so the type form tracks the constructor's keywords without restating them.
Fold the `Index` keyword constructor into the generic `NamedUnitRange{Name}(space; kwargs...)`, which forwards keywords to `uniquename`, so there is no `IndexName`-specific method. Rename the bond-name canonicalizer `bondnamer` to `to_uniquename_function` and its `NamedTuple` argument to `decoration`, matching the `to_range` naming already in this file. Add a `decoration` fallback returning an empty `NamedTuple` for undecorated names.
Point `[sources.ITensorBase]` in `test/Project.toml` back at `..`. A machine-specific absolute path to a sibling worktree had replaced it, so the test project resolved `ITensorBase` from the wrong checkout.
@mtfishman mtfishman force-pushed the mf/tag-decoration-api branch from c6fca9a to 6dd5fb4 Compare July 10, 2026 00:42
Rename the SVD and eigendecomposition bond-decoration keywords from `rowname`/`colname` to `leftname`/`rightname`, matching legacy ITensor's `lefttags`/`righttags` and the left/right framing used across the tensor-network ecosystem. `leftname` decorates the U-side bond, `rightname` the V-side bond. The single-bond keyword stays `name`.
Document a single `Index(space; tags, plev)` signature and state the keyword defaults (no tags, prime level 0) instead of listing `Index(space)` as a separate signature.
Add the `name`/`leftname`/`rightname` bond-decoration keywords to the Factorizations section of the user interface manual, with a runnable SVD example. The factorizations are wrapped MatrixAlgebraKit methods without ITensorBase docstrings, so the decoration keywords are documented once here rather than on each wrapped function.
Spell the example link tag `"link"` rather than `"Link"` in the tests and the manual.
Word the decoration example as the same SVD with its two bonds tagged, right after the plain `svd_compact` example, and drop the redundant `svd_compact` import (the shared example state already has it).
A comment sitting between the docstring and the definition detached the `settags` docstring, so it fell out of the reference docs and `@ref` links to it could not resolve, failing the docs build. Move the comment after the definition so the docstring attaches.
@mtfishman mtfishman changed the title [WIP] Add tag verbs, an Index keyword constructor, and factorization bond decoration Add tag verbs, an Index keyword constructor, and factorization bond decoration Jul 10, 2026
@mtfishman mtfishman marked this pull request as ready for review July 10, 2026 15:43
@mtfishman mtfishman enabled auto-merge (squash) July 10, 2026 15:43
@mtfishman mtfishman merged commit b32dc08 into main Jul 10, 2026
26 of 28 checks passed
@mtfishman mtfishman deleted the mf/tag-decoration-api branch July 10, 2026 16:04
mtfishman added a commit to mtfishman/TensorNetworkQuantumSimulator.jl that referenced this pull request Jul 10, 2026
#3)

## Summary

Continues shrinking the `itensors.jl` shim onto the upstream API, now
that `ITensorBase` exposes the tag and factorization-decoration verbs
(added in ITensor/ITensorBase.jl#214). Builds on
#2.

- **Name the new bond at the factorization instead of relabeling it
after.** The `left_orth` / `right_orth` call sites pass `name = (; tags
= ...)`, which mints the bond with the tag directly, so the `commonind`
/ `settags` / `replaceinds` retag that followed each factorization is
gone. The full-update bond takes its tags from `commonind(p, q)`, which
errors clearly when there is not exactly one shared index, rather than
`trycommonind`.
- **Retire the local `settags` shim** for the now-public
`ITensorBase.settags`, and mint tagged site and link indices through the
`Index(dim; tags = ...)` keyword constructor.
- **Take the `loop_correlation` eigenvalues with `eig_vals` directly on
the ITensor**, dropping the `matricize` / `adapt` / `Array`
densification and the `LinearAlgebra.eigvals` call. It returns the same
eigenvalues, and the routine only reads `maximum(abs, λ)` and `sum(abs,
λ)`.
- **Use the greedy contraction optimizer unconditionally for loop
weights.** `weight` picked the optimizer with `hasqns` (exact for graded
tensors, greedy otherwise), but `loop_correlation` in the same module
already runs greedy on every backend, so drop the branch and the
`hasqns` helper it was the only caller of.
- **Update the API reference** for the removed `safe_eigen` and the `op`
methods that moved into the `Ops` submodule.

Verified with the local symmetric smoke across the dense, graded, and
TensorKit backends, the package test suite, and a docs build.

---------

Co-authored-by: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
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