Skip to content

Promote lazy tensors and re-partition operators - #236

Merged
mtfishman merged 1 commit into
mainfrom
mf/lazy-operator-promotion
Jul 29, 2026
Merged

Promote lazy tensors and re-partition operators#236
mtfishman merged 1 commit into
mainfrom
mf/lazy-operator-promotion

Conversation

@mtfishman

Copy link
Copy Markdown
Member

Summary

Extends the operator promotion added in #235 to lazy tensors, and makes operator re-partition an existing operator instead of nesting.

A LazyNamedTensor now 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 eager NamedTensor / NamedTensorOperator promotion at the leaves. So a lazy plain tensor and an operator promote to a lazy operator, and convert rebuilds the lazy product with each leaf converted. This lets contract_network homogenize a network that mixes lazy and eager, plain and operator operands without materializing anything. The motivating case is a norm-network vertex, a lazy ket * 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 existing NamedTensorOperator now 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.

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

codecov Bot commented Jul 29, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 77.92%. Comparing base (eb6bb3c) to head (119b408).

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              
Flag Coverage Δ
docs 26.36% <0.00%> (-0.17%) ⬇️

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 enabled auto-merge (squash) July 29, 2026 01:06
@mtfishman
mtfishman merged commit 4a3c1ed into main Jul 29, 2026
18 checks passed
@mtfishman
mtfishman deleted the mf/lazy-operator-promotion branch July 29, 2026 01:16
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.
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