Promote lazy tensors and re-partition operators - #236
Merged
Conversation
Extends the operator promotion from #235 to lazy tensors: a LazyNamedTensor promotes with lazy or eager tensors by promoting the leaf type, so a lazy plain tensor and an operator promote to a lazy operator. Also makes operator() on an existing operator reassign the pairing rather than nesting. Together these let contract_network homogenize networks mixing lazy/eager, plain/operator operands.
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #236 +/- ##
==========================================
+ Coverage 77.79% 77.92% +0.13%
==========================================
Files 30 30
Lines 1792 1803 +11
==========================================
+ Hits 1394 1405 +11
Misses 398 398
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
enabled auto-merge (squash)
July 29, 2026 01:06
mtfishman
added a commit
to ITensor/ITensorNetworksNext.jl
that referenced
this pull request
Jul 29, 2026
## Summary `contract_network` now handles a network that mixes operator-valued (`NamedTensorOperator`) and plain tensors, which previously threw a `convert` `MethodError`. It promotes the operands to their common type with `promote_type` and `convert` before lowering to the lazy expression, so every operand shares one concrete type and the contraction folds with `*`, routing operators through `operator_product` and preserving the output and input pairing. Without that, a mixed network widens the symbolic `Mul` container to a `UnionAll` that cannot be constructed. An all-plain network is unaffected (the promotion is a no-op). The promotion lives in ITensorBase: eager operands via ITensor/ITensorBase.jl#235 and lazy operands via ITensor/ITensorBase.jl#236. With the lazy case handled, this drops the interim `state`-unwrap workarounds in belief propagation: `vertex_scalar` and `updated_message` contract operator messages directly, and the `NormNetwork` `message_update!` re-partitions the result with `operator` (the vertex factor is a lazy `ket * conj(bra)` product, so its surviving bond legs come out unpaired and the message's ket/bra pairing is assigned by the norm-network convention). Also switches the `NormNetwork` tests to the package's `contract_network` rather than a local helper of the same name that shadowed it.
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
Extends the operator promotion added in #235 to lazy tensors, and makes
operatorre-partition an existing operator instead of nesting.A
LazyNamedTensornow promotes with another lazy tensor, or with an eager tensor, to the lazy tensor whose leaf (parent) type is the promotion of the leaves, reusing the eagerNamedTensor/NamedTensorOperatorpromotion at the leaves. So a lazy plain tensor and an operator promote to a lazy operator, andconvertrebuilds the lazy product with each leaf converted. This letscontract_networkhomogenize a network that mixes lazy and eager, plain and operator operands without materializing anything. The motivating case is a norm-network vertex, a lazyket * conj(bra)product, contracted against operator-valued belief-propagation messages, which the eager-only promotion could not reach. An all-eager or all-plain network is unaffected (the promotion stays at the eager or plain type).operator(a, output, input)on an existingNamedTensorOperatornow reassigns the pairing over the same state rather than wrapping another operator around it, since an operator's output/input pairing is a view over its state.Together these let ITensorNetworksNext drop the interim
state-unwrap workarounds in belief propagation.