Return contraction output labels as a Vector#179
Merged
Conversation
## 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 Report✅ All modified and coverable lines are covered by tests. 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
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:
|
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.
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
Returns the output labels from
contractas aVectorrather than aBlockedTuple, so the labels keep their element type even for a full contraction. The labels previously came back as aBlockedTuple, whoseeltypefalls back toAny, and a full contraction produced an emptyTuple{}whose element type isUnion{}. A downstream consumer that builds a labeled array from these labels (such asITensorin ITensorBase) then widened its dim-name type, soITensor{IndexName} * ITensor{IndexName}came back asITensor{Any}.contract_labelsnow returnsvcat(setdiff(labels1, labels2), setdiff(labels2, labels1)), an ordinaryVectorthat 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
eltypemethod forBlockedTuplethat forwards the underlying flat tuple's element type instead of falling back toAny.The destination-label container is an implementation detail, so a few tests that asserted the exact
BlockedTupletype or value were updated to check the labels by value or set membership.