Skip to content

Commit 1832434

Browse files
authored
[ITensors] Call out to TensorOperations.jl for optimal sequence finding (#1637)
1 parent faa7996 commit 1832434

File tree

19 files changed

+60
-878
lines changed

19 files changed

+60
-878
lines changed

Project.toml

+5-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
name = "ITensors"
22
uuid = "9136182c-28ba-11e9-034c-db9fb085ebd5"
33
authors = ["Matthew Fishman <[email protected]>", "Miles Stoudenmire <[email protected]>"]
4-
version = "0.8.10"
4+
version = "0.9.0"
55

66
[deps]
77
Adapt = "79e6a3ab-5dfb-504d-930d-738a2a938a0e"
@@ -29,11 +29,13 @@ Zeros = "bd1ec220-6eb4-527a-9b49-e79c3db6233b"
2929

3030
[weakdeps]
3131
HDF5 = "f67ccb44-e63f-5c2f-98bd-6dc0ccc4ba2f"
32+
TensorOperations = "6aa20fa7-93e2-5fca-9bc0-fbd0db3c71a2"
3233
VectorInterface = "409d34a3-91d5-4945-b6ec-7529ddf182d8"
3334
ZygoteRules = "700de1a5-db45-46bc-99cf-38207098b444"
3435

3536
[extensions]
3637
ITensorsHDF5Ext = "HDF5"
38+
ITensorsTensorOperationsExt = "TensorOperations"
3739
ITensorsVectorInterfaceExt = "VectorInterface"
3840
ITensorsZygoteRulesExt = "ZygoteRules"
3941

@@ -58,6 +60,7 @@ SimpleTraits = "0.9.4"
5860
SparseArrays = "<0.0.1, 1.10"
5961
StaticArrays = "0.12, 1.0"
6062
Strided = "1.1, 2"
63+
TensorOperations = "5.1.4"
6164
TimerOutputs = "0.5.5"
6265
TupleTools = "1.2"
6366
VectorInterface = "0.4, 0.5"
@@ -68,5 +71,6 @@ julia = "1.10"
6871
[extras]
6972
ChainRulesCore = "d360d2e6-b24c-11e9-a2a3-2a2ae2dbcce4"
7073
HDF5 = "f67ccb44-e63f-5c2f-98bd-6dc0ccc4ba2f"
74+
TensorOperations = "6aa20fa7-93e2-5fca-9bc0-fbd0db3c71a2"
7175
VectorInterface = "409d34a3-91d5-4945-b6ec-7529ddf182d8"
7276
ZygoteRules = "700de1a5-db45-46bc-99cf-38207098b444"

README.md

+2
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,8 @@ ITensors.jl is supported by the Flatiron Institute, a division of the Simons Fou
3737

3838
## News
3939

40+
- March 26, 2025: ITensors.jl v0.9 has been released. This is a minor breaking change since the `optimal_contraction_sequence` function now passes to the `optimaltree` function from [TensorOperations.jl](https://github.com/Jutho/TensorOperations.jl). The `TensorOperations` package therefore needs to be loaded in order for `optimal_contraction_sequence` to be used or if the flag `ITensors.enable_contraction_sequence_optimization()` is switched on.
41+
4042
- March 22, 2025: As part of the latest release of ITensors.jl (v0.8.3), all documentation related to MPS/MPO functionality has been moved to the [ITensorMPS.jl documentation](https://docs.itensor.org/ITensorMPS).
4143

4244
- February 22, 2025: Please note that there were issues installing the latest version of ITensors.jl (ITensors.jl v0.8) in older versions of Julia v1.10 and v1.11 ([https://github.com/ITensor/ITensors.jl/issues/1618](https://github.com/ITensor/ITensors.jl/issues/1618), [https://itensor.discourse.group/t/typeparameteraccessors-not-found-error-on-julia-v-1-10-0/2260](https://itensor.discourse.group/t/typeparameteraccessors-not-found-error-on-julia-v-1-10-0/2260)). This issue has been fixed in [NDTensors.jl v0.4.4](https://github.com/ITensor/ITensors.jl/pull/1623), so please try updating your packages if you are using older versions of Julia v1.10 or v1.11 and running into issues installing ITensors.jl.

docs/Project.toml

+2-1
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,11 @@ HDF5 = "f67ccb44-e63f-5c2f-98bd-6dc0ccc4ba2f"
44
ITensors = "9136182c-28ba-11e9-034c-db9fb085ebd5"
55
LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e"
66
Strided = "5e0ebb24-38b0-5f93-81fe-25c709ecae67"
7+
TensorOperations = "6aa20fa7-93e2-5fca-9bc0-fbd0db3c71a2"
78

89
[compat]
910
Documenter = "1.9.0"
1011
HDF5 = "0.17.2"
11-
ITensors = "0.8.4"
1212
Strided = "2.2.0"
13+
TensorOperations = "5.1.4"
1314
LinearAlgebra = "1.10.0"

docs/src/ContractionSequenceOptimization.md

+3-4
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
# Contraction sequence optimization
22

3-
When contracting a tensor network, the sequence of contraction makes a big difference in the computational cost. However, the complexity of determining the optimal sequence grows exponentially with the number of tensors, but there are many heuristic algorithms available for computing optimal sequences for small networks[^1][^2][^3][^4][^5][^6]. ITensors.jl provides some functionality for helping you find the optimal contraction sequence for small tensor network, as we will show below.
4-
5-
The algorithm in ITensors.jl currently uses a modified version of[^1] with simplifications for outer product contractions and is based on the implementation in [TensorOperations.jl](https://github.com/Jutho/TensorOperations.jl).
3+
When contracting a tensor network, the sequence of contraction makes a big difference in the computational cost. However, the complexity of determining the optimal sequence grows exponentially with the number of tensors, but there are many heuristic algorithms available for computing optimal sequences for small networks[^1][^2][^3][^4][^5][^6]. ITensors.jl imports functionality from [TensorOperations.jl](https://github.com/Jutho/TensorOperations.jl) for helping you find the optimal contraction sequence for small tensor network, as we will show below.
64

75
[^1]: [Faster identification of optimal contraction sequences for tensor networks](https://arxiv.org/abs/1304.6112)
86
[^2]: [Improving the efficiency of variational tensor network algorithms](https://arxiv.org/abs/1310.8023)
@@ -64,12 +62,13 @@ display(cost2)
6462
```
6563
This example helps us learn that in the limit of large MPS bond dimension `m`, the first contraction sequence is faster, while in the limit of large MPO bond dimension `k`, the second sequence is faster. This has practical implications for writing an efficient DMRG algorithm in both limits, which we plan to incorporate into ITensors.jl.
6664

67-
Here is a more systematic example of searching through the parameter space to find optimal contraction sequences:
65+
Here is a more systematic example of searching through the parameter space to find optimal contraction sequences. Note, the TensorOperations.jl library must be loaded to use the optimal_contraction_sequence function:
6866
```julia
6967
using ITensors
7068
using Symbolics
7169

7270
using ITensors: contraction_cost, optimal_contraction_sequence
71+
using TensorOperations: TensorOperations
7372

7473
function tensor_network(; m, k, d)
7574
l = Index(m, "l")
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
module ITensorsTensorOperationsExt
2+
3+
using ITensors: ITensors, ITensor, dim, inds
4+
using TensorOperations: optimaltree
5+
6+
function ITensors.optimal_contraction_sequence(
7+
As::Union{Vector{<:ITensor},Tuple{Vararg{ITensor}}}
8+
)
9+
network = collect.(inds.(As))
10+
inds_to_dims = Dict(i => Float64(dim(i)) for i in unique(reduce(vcat, network)))
11+
seq, _ = optimaltree(network, inds_to_dims)
12+
return seq
13+
end
14+
15+
end

src/ITensors.jl

+1-3
Original file line numberDiff line numberDiff line change
@@ -51,9 +51,6 @@ Documentation: https://itensor.github.io/ITensors.jl/stable/
5151
module ITensors
5252
include("usings.jl")
5353
include("utils.jl")
54-
include("lib/ContractionSequenceOptimization/src/ContractionSequenceOptimization.jl")
55-
# TODO: `using .ContractionSequenceOptimization: ContractionSequenceOptimization, ...`.
56-
using .ContractionSequenceOptimization
5754
include("lib/LazyApply/src/LazyApply.jl")
5855
# TODO: `using .LazyApply: LazyApply, ...`.
5956
using .LazyApply
@@ -105,6 +102,7 @@ include("indexset.jl")
105102
include("itensor.jl")
106103
include("qn/flux.jl")
107104
include("oneitensor.jl")
105+
include("tensor_operations/contraction_cost.jl")
108106
include("tensor_operations/tensor_algebra.jl")
109107
include("tensor_operations/matrix_algebra.jl")
110108
include("tensor_operations/permutations.jl")

src/imports.jl

-3
Original file line numberDiff line numberDiff line change
@@ -81,9 +81,6 @@ import Base.Broadcast:
8181
broadcastable,
8282
instantiate
8383

84-
import ITensors.ContractionSequenceOptimization:
85-
contraction_cost, optimal_contraction_sequence
86-
8784
import Adapt: adapt_structure, adapt_storage
8885

8986
import LinearAlgebra:

src/lib/ContractionSequenceOptimization/src/ContractionSequenceOptimization.jl

-42
This file was deleted.

0 commit comments

Comments
 (0)