Skip to content

Return contraction output labels as a Vector#179

Merged
mtfishman merged 1 commit into
mainfrom
mf/blockedtuple-eltype
Jun 22, 2026
Merged

Return contraction output labels as a Vector#179
mtfishman merged 1 commit into
mainfrom
mf/blockedtuple-eltype

Conversation

@mtfishman

Copy link
Copy Markdown
Member

Summary

Returns the output labels from contract as a Vector rather than a BlockedTuple, so the labels keep their element type even for a full contraction. The labels previously came back as a BlockedTuple, whose eltype falls back to Any, and a full contraction produced an empty Tuple{} whose element type is Union{}. A downstream consumer that builds a labeled array from these labels (such as ITensor in ITensorBase) then widened its dim-name type, so ITensor{IndexName} * ITensor{IndexName} came back as ITensor{Any}.

contract_labels now returns vcat(setdiff(labels1, labels2), setdiff(labels2, labels1)), an ordinary Vector that carries the label element type even when empty. blockedperms(contract, ...) no longer relies on the destination labels carrying block structure, so it takes the codomain length directly.

Also adds an eltype method for BlockedTuple that forwards the underlying flat tuple's element type instead of falling back to Any.

The destination-label container is an implementation detail, so a few tests that asserted the exact BlockedTuple type or value were updated to check the labels by value or set membership.

## Summary

Returns the output labels from `contract` as a `Vector` rather than a `BlockedTuple`, so the labels keep their element type even for a full contraction. The labels previously came back as a `BlockedTuple`, whose `eltype` falls back to `Any`, and a full contraction produced an empty `Tuple{}` whose element type is `Union{}`. A downstream consumer that builds a labeled array from these labels (such as `ITensor` in ITensorBase) then widened its dim-name type, so `ITensor{IndexName} * ITensor{IndexName}` came back as `ITensor{Any}`.

`contract_labels` now returns `vcat(setdiff(labels1, labels2), setdiff(labels2, labels1))`, an ordinary `Vector` that carries the label element type even when empty. `blockedperms(contract, ...)` no longer relies on the destination labels carrying block structure, so it takes the codomain length directly.

Also adds an `eltype` method for `BlockedTuple` that forwards the underlying flat tuple's element type instead of falling back to `Any`.

The destination-label container is an implementation detail, so a few tests that asserted the exact `BlockedTuple` type or value were updated to check the labels by value or set membership.

Co-authored-by: Claude <noreply@anthropic.com>
@codecov

codecov Bot commented Jun 22, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 81.27%. Comparing base (83979cf) to head (a5e6bc9).

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #179      +/-   ##
==========================================
+ Coverage   81.07%   81.27%   +0.20%     
==========================================
  Files          26       26              
  Lines        1046     1047       +1     
==========================================
+ Hits          848      851       +3     
+ Misses        198      196       -2     
Flag Coverage Δ
docs 26.20% <20.00%> (-0.03%) ⬇️

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 mtfishman merged commit 2783b56 into main Jun 22, 2026
26 checks passed
@mtfishman mtfishman deleted the mf/blockedtuple-eltype branch June 22, 2026 17:07
mtfishman added a commit to ITensor/ITensorNetworksNext.jl that referenced this pull request Jun 22, 2026
## Summary

Migrates ITensorNetworksNext to ITensorBase v0.6, which replaces the
named-array core with the new `AbstractITensor{DimName}` model. Tensor
network vertices hold `ITensor`s built on that model across the
contraction, belief-propagation, and operator-application layers. This
requires ITensorBase 0.6.2
(ITensor/ITensorBase.jl#181) for name-based
comparison of graded tensors and TensorAlgebra 0.9.7
(ITensor/TensorAlgebra.jl#179) for contraction
labels that keep their element type.

The lazy expression layer is renamed from `LazyNamedDimsArrays` to
`LazyITensors`, and its symbolic leaf is reworked into a
`SymbolicITensor` that builds lazy products directly and carries named
structure with no array payload. The delta-tensor generators no longer
depend on DiagonalArrays: a dense `diagonaltensor`/`delta` helper places
values on the hyperdiagonal over either plain or named axes.

Relocating the lazy and symbolic core into ITensorBase will follow in a
later PR.
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