Skip to content

Add lazy and symbolic ITensors with contraction-order optimization#182

Merged
mtfishman merged 2 commits into
mainfrom
mf/lazyitensors
Jun 22, 2026
Merged

Add lazy and symbolic ITensors with contraction-order optimization#182
mtfishman merged 2 commits into
mainfrom
mf/lazyitensors

Conversation

@mtfishman

@mtfishman mtfishman commented Jun 22, 2026

Copy link
Copy Markdown
Member

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 sizes, 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.

## 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 previously lived in ITensorNetworksNext's `LazyITensors` submodule. 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` stores `name`, `denamed_axes`, and `dimnames`, mirroring how a plain `ITensor` splits into `denamed` and `dimnames`. The symbolic leaf has no array, so it keeps the underlying axes directly. It is parameterized by the dimension-name type and the name type, the latter matching how the tensor network types parameterize by vertex type.
@codecov

codecov Bot commented Jun 22, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 59.71429% with 141 lines in your changes missing coverage. Please review.
✅ Project coverage is 71.05%. Comparing base (2a23859) to head (31e81ac).

Files with missing lines Patch % Lines
src/lazyitensors/lazyinterface.jl 62.87% 49 Missing ⚠️
src/lazyitensors/evaluation_order.jl 33.33% 36 Missing ⚠️
src/lazyitensors/lazyitensor.jl 58.33% 20 Missing ⚠️
src/lazyitensors/lazybroadcast.jl 0.00% 9 Missing ⚠️
src/lazyitensors/symbolicitensor.jl 79.06% 9 Missing ⚠️
src/lazyitensors/applied.jl 77.77% 8 Missing ⚠️
src/lazyitensors/itensorbaseextensions.jl 50.00% 7 Missing ⚠️
src/lazyitensors/baseextensions.jl 0.00% 3 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #182      +/-   ##
==========================================
- Coverage   74.75%   71.05%   -3.70%     
==========================================
  Files          20       28       +8     
  Lines        1105     1451     +346     
==========================================
+ Hits          826     1031     +205     
- Misses        279      420     +141     
Flag Coverage Δ
docs 15.75% <0.00%> (-5.06%) ⬇️

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.

A symbolic tensor is substituted with a real tensor before contraction,
so it only needs the index sizes for contraction-order selection. Store
`size::Vector{Int}` alongside `dimnames` and reconstruct `inds` as plain
ranges of those sizes.
@mtfishman mtfishman merged commit c6d3531 into main Jun 22, 2026
16 of 18 checks passed
@mtfishman mtfishman deleted the mf/lazyitensors branch June 22, 2026 21:23
mtfishman added a commit to ITensor/ITensorNetworksNext.jl that referenced this pull request Jun 22, 2026
## Summary

Switches ITensorNetworksNext to use the lazy and symbolic ITensor layer
from ITensorBase instead of its own copy. The `LazyITensors` submodule
is removed, and its lazy and symbolic types and contraction-order
machinery are imported directly from ITensorBase, where the
implementation moved in
ITensor/ITensorBase.jl#182.

Also drops the now-redundant `ITensorNetworksNextTensorOperationsExt`
(the `Optimal` order via `TensorOperations.optimaltree` is provided by
ITensorBase's own extension) and the `AbstractTrees`, `TermInterface`,
and `WrappedUnions` dependencies that only the local copy used.
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