Skip to content

Contract networks mixing operators and plain tensors - #158

Merged
mtfishman merged 2 commits into
mainfrom
mf/contract-network-operators
Jul 29, 2026
Merged

Contract networks mixing operators and plain tensors#158
mtfishman merged 2 commits into
mainfrom
mf/contract-network-operators

Conversation

@mtfishman

@mtfishman mtfishman commented Jul 28, 2026

Copy link
Copy Markdown
Member

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.

@codecov

codecov Bot commented Jul 28, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 84.81%. Comparing base (4b43b57) to head (257e09a).
⚠️ Report is 1 commits behind head on main.

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              
Flag Coverage Δ
docs 0.00% <0.00%> (ø)

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 force-pushed the mf/contract-network-operators branch 2 times, most recently from 5e82909 to 1a96648 Compare July 28, 2026 21:15
@mtfishman mtfishman changed the title [WIP] Contract networks mixing operators and plain tensors Contract networks mixing operators and plain tensors Jul 28, 2026
@mtfishman
mtfishman marked this pull request as ready for review July 28, 2026 22:25
@mtfishman
mtfishman marked this pull request as draft July 29, 2026 00:15
@mtfishman mtfishman changed the title Contract networks mixing operators and plain tensors [WIP] Contract networks mixing operators and plain tensors Jul 29, 2026
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
mtfishman force-pushed the mf/contract-network-operators branch from 1a96648 to 2bbc3b2 Compare July 29, 2026 00:58
@mtfishman mtfishman changed the title [WIP] Contract networks mixing operators and plain tensors Contract networks mixing operators and plain tensors Jul 29, 2026
@mtfishman
mtfishman marked this pull request as ready for review July 29, 2026 01:32
@mtfishman
mtfishman enabled auto-merge (squash) July 29, 2026 01:33
@mtfishman
mtfishman merged commit 48c5e67 into main Jul 29, 2026
25 of 28 checks passed
@mtfishman
mtfishman deleted the mf/contract-network-operators branch July 29, 2026 01:52
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