Skip to content

Flatten lazy product operands into leaves for contraction ordering - #159

Draft
mtfishman wants to merge 1 commit into
mainfrom
mf/contraction-order-lazy-leaves
Draft

Flatten lazy product operands into leaves for contraction ordering#159
mtfishman wants to merge 1 commit into
mainfrom
mf/contraction-order-lazy-leaves

Conversation

@mtfishman

Copy link
Copy Markdown
Member

Summary

contract_network lowered each operand to a single symbol carrying its outer axes, so a lazy product operand stayed opaque to the contraction-order optimizer. A NormNetwork's doubled vertex is such a product, lazy(ket) * lazy(conj(bra)), and collapsing it hid the physical index shared between the ket and bra. The optimizer could not interleave the other operands between the two layers, so it formed the doubled ket * conj(bra) tensor first, scaling as χ^(2·degree) rather than the χ^(degree+1) a good order reaches. A belief-propagation message update on a degree-3 vertex paid that cost on every sweep.

For a computed order, contract_network now expands each operand into its contraction leaves before ordering, so lazy(ket) * lazy(conj(bra)) reaches the optimizer as two leaves that share the physical index. The optimizer orders the full leaf set and interleaves the messages between the layers. The expansion runs on the operand after promotion to the network's common type (building on #158), so the operator and state semantics are preserved, and it recurses through nested products. An explicit order is honored over the operands as given, so it is not flattened. The Greedy optimizer and the rest of the order machinery are unchanged.

A regression test asserts the computed order's peak intermediate stays at the χ^(degree+1) path rather than forming the χ^(2·degree) doubled tensor.

`contract_network` lowered each operand to a single symbol carrying its outer axes, so a lazy product operand stayed opaque to the contraction-order optimizer. A `NormNetwork`'s doubled vertex is such a product, `lazy(ket) * lazy(conj(bra))`, and collapsing it hid the physical index shared between the ket and bra. The optimizer could not interleave the other operands between the two layers, so it formed the doubled `ket * conj(bra)` tensor first, scaling as χ^(2·degree) rather than the χ^(degree+1) a good order reaches. A belief-propagation message update on a degree-3 vertex paid that cost on every sweep.

For a computed order, `contract_network` now expands each operand into its contraction leaves before ordering, so `lazy(ket) * lazy(conj(bra))` reaches the optimizer as two leaves that share the physical index. The optimizer orders the full leaf set and interleaves the messages between the layers. The expansion runs on the operand after promotion to the network's common type (building on #158), so the operator and state semantics are preserved, and it recurses through nested products. An explicit `order` is honored over the operands as given, so it is not flattened. The Greedy optimizer and the rest of the order machinery are unchanged.

A regression test asserts the computed order's peak intermediate stays at the χ^(degree+1) path rather than forming the χ^(2·degree) doubled tensor.
@codecov

codecov Bot commented Jul 29, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 60.00000% with 4 lines in your changes missing coverage. Please review.
✅ Project coverage is 78.80%. Comparing base (48c5e67) to head (73c0cae).

Files with missing lines Patch % Lines
src/contract_network.jl 60.00% 4 Missing ⚠️

❗ There is a different number of reports uploaded between BASE (48c5e67) and HEAD (73c0cae). Click for more details.

HEAD has 12 uploads less than BASE
Flag BASE (48c5e67) HEAD (73c0cae)
docs 2 1
12 1
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #159      +/-   ##
==========================================
- Coverage   84.81%   78.80%   -6.01%     
==========================================
  Files          15       13       -2     
  Lines         685      689       +4     
==========================================
- Hits          581      543      -38     
- Misses        104      146      +42     
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.

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