Skip to content

Replace BackendSelection with dedicated contraction algorithm types#123

Merged
mtfishman merged 1 commit into
mainfrom
mf/lazyitensors-cleanup
Jun 22, 2026
Merged

Replace BackendSelection with dedicated contraction algorithm types#123
mtfishman merged 1 commit into
mainfrom
mf/lazyitensors-cleanup

Conversation

@mtfishman

Copy link
Copy Markdown
Member

Summary

Replaces the string-based BackendSelection.Algorithm"..." selection for tensor-network contraction with dedicated algorithm types, and drops BackendSelection, TypeParameterAccessors, and FunctionImplementations as dependencies.

Contraction order is now chosen with types instead of Algorithm strings: Greedy and Optimal (the optimize_contraction_order strategies, with Optimal provided by the TensorOperations extension), Flat and LeftAssociative (the contraction_order strategies), and Exact (the contract_network algorithm, carrying its order/order_alg as fields rather than as Algorithm parameters). Greedy replaces the old "eager" name, the standard term for the cost-minimizing pairwise heuristic.

TypeParameterAccessors was unused. The lone FunctionImplementations.zero! call becomes fill!(a, zero(eltype(a))). The structure-aware zero! it relied on is worth keeping as a shared overloadable primitive, but where that should live is a separate question, and the dense path delta actually uses is unaffected.

Also un-breaks the show/printnode/print_tree tests for the lazy and symbolic tensors: the rendered output was already correct, the expected strings just predated ITensorBase's index-name display.

This sets up moving the LazyITensors submodule into ITensorBase, which its BackendSelection use had stood in the way of.

## Summary

Replaces the string-based `BackendSelection.Algorithm"..."` selection for tensor-network contraction with dedicated algorithm types, and drops `BackendSelection`, `TypeParameterAccessors`, and `FunctionImplementations` as dependencies.

Contraction order is now chosen with types instead of `Algorithm` strings: `Greedy` and `Optimal` (the `optimize_contraction_order` strategies, with `Optimal` provided by the TensorOperations extension), `Flat` and `LeftAssociative` (the `contraction_order` strategies), and `Exact` (the `contract_network` algorithm, carrying its `order`/`order_alg` as fields rather than as `Algorithm` parameters). `Greedy` replaces the old `"eager"` name, the standard term for the cost-minimizing pairwise heuristic.

`TypeParameterAccessors` was unused. The lone `FunctionImplementations.zero!` call becomes `fill!(a, zero(eltype(a)))`. The structure-aware `zero!` it relied on is worth keeping as a shared overloadable primitive, but where that should live is a separate question, and the dense path `delta` actually uses is unaffected.

Also un-breaks the `show`/`printnode`/`print_tree` tests for the lazy and symbolic tensors: the rendered output was already correct, the expected strings just predated ITensorBase's index-name display.

This sets up moving the `LazyITensors` submodule into ITensorBase, which its `BackendSelection` use had stood in the way of.
@codecov

codecov Bot commented Jun 22, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 88.00000% with 3 lines in your changes missing coverage. Please review.
✅ Project coverage is 74.30%. Comparing base (bf9bca0) to head (6e61b01).

Files with missing lines Patch % Lines
src/contract_network.jl 88.88% 2 Missing ⚠️
src/LazyITensors/evaluation_order.jl 75.00% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #123      +/-   ##
==========================================
- Coverage   74.33%   74.30%   -0.03%     
==========================================
  Files          23       23              
  Lines        1087     1082       -5     
==========================================
- Hits          808      804       -4     
+ Misses        279      278       -1     
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 merged commit 0bf9e06 into main Jun 22, 2026
18 checks passed
@mtfishman mtfishman deleted the mf/lazyitensors-cleanup branch June 22, 2026 19:28
mtfishman added a commit to ITensor/ITensorBase.jl that referenced this pull request Jun 22, 2026
)

## Summary

Adds the lazy and symbolic tensor types and the contraction-order
machinery to ITensorBase, in the top-level namespace: `LazyITensor` and
`SymbolicITensor` expression leaves, `lazy` / `Mul` / `symnameddims` /
`substitute` for building lazy contraction expressions, and
`optimize_evaluation_order` with the `Greedy` and `Optimal` order
algorithms. This code was moved from ITensorNetworksNext's
`LazyITensors` submodule, most recently reworked in
ITensor/ITensorNetworksNext.jl#123 to use
dedicated contraction-order algorithm types and fewer dependencies. It
moves down to ITensorBase so it sits alongside the `ITensor` type it
builds on, and a follow-up will switch ITensorNetworksNext to consume it
instead of carrying its own copy.

`AbstractTrees` becomes a regular dependency rather than a weakdep: the
lazy and symbolic `show` and tree rendering use it throughout, and the
`printnode(::AbstractITensor)` method that was in
`ITensorBaseAbstractTreesExt` moves into the package. `TermInterface`,
`WrappedUnions`, and `Combinatorics` are new dependencies. The `Optimal`
order, which uses `TensorOperations.optimaltree`, is provided by a new
`TensorOperations` extension.

`SymbolicITensor` is a placeholder that gets substituted with a real
tensor before contraction, so it stores only what contraction-order
selection needs: `name`, the index `size`s, and `dimnames`, with `inds`
reconstructed as plain ranges of those sizes. It is parameterized by the
dimension-name type and the name type, the latter matching how the
tensor network types parameterize by vertex type.
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