Contract networks mixing operators and plain tensors - #158
Merged
Conversation
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #158 +/- ##
==========================================
+ Coverage 84.79% 84.81% +0.02%
==========================================
Files 15 15
Lines 684 685 +1
==========================================
+ Hits 580 581 +1
Misses 104 104
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
force-pushed
the
mf/contract-network-operators
branch
2 times, most recently
from
July 28, 2026 21:15
5e82909 to
1a96648
Compare
mtfishman
marked this pull request as ready for review
July 28, 2026 22:25
mtfishman
marked this pull request as draft
July 29, 2026 00:15
Promote the operands to their common type before lowering to the lazy expression, so a network mixing operators and plain tensors contracts via operator_product instead of throwing a convert MethodError. The promotion lives in ITensorBase (eager operands in ITensorBase.jl PR 235, lazy operands in PR 236), so this also drops the interim state-unwrap workarounds in belief propagation now that operator messages contract directly against the lazy norm-network factor.
mtfishman
force-pushed
the
mf/contract-network-operators
branch
from
July 29, 2026 00:58
1a96648 to
2bbc3b2
Compare
mtfishman
marked this pull request as ready for review
July 29, 2026 01:32
mtfishman
enabled auto-merge (squash)
July 29, 2026 01:33
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
contract_networknow handles a network that mixes operator-valued (NamedTensorOperator) and plain tensors, which previously threw aconvertMethodError. It promotes the operands to their common type withpromote_typeandconvertbefore lowering to the lazy expression, so every operand shares one concrete type and the contraction folds with*, routing operators throughoperator_productand preserving the output and input pairing. Without that, a mixed network widens the symbolicMulcontainer to aUnionAllthat 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_scalarandupdated_messagecontract operator messages directly, and theNormNetworkmessage_update!re-partitions the result withoperator(the vertex factor is a lazyket * 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
NormNetworktests to the package'scontract_networkrather than a local helper of the same name that shadowed it.