From 92295e26396acc7a7f62cf5f2e1ec97cd44f6538 Mon Sep 17 00:00:00 2001 From: Matthew Fishman Date: Mon, 13 Jul 2026 14:20:41 -0400 Subject: [PATCH] Replace the TensorOperations `Optimal` backend with OMEinsumContractionOrders `ExhaustiveSearch` Drops the TensorOperations dependency, which existed only to compute optimal contraction orders through the `Optimal` backend, in favor of OMEinsumContractionOrders' `ExhaustiveSearch` (added in https://github.com/TensorBFS/OMEinsumContractionOrders.jl/pull/119, released in v1.3). `ExhaustiveSearch` is a port of the same `optimaltree` netcon algorithm, and ITensorBase's OMEinsumContractionOrders extension already dispatches on any `CodeOptimizer`, so no new code is needed. The `Optimal` evaluation-order algorithm is removed. Use `ExhaustiveSearch()` in its place. Co-Authored-By: Claude Opus 4.8 (1M context) --- Project.toml | 7 ++--- docs/Project.toml | 2 +- examples/Project.toml | 2 +- .../ITensorBaseTensorOperationsExt.jl | 26 ------------------- src/lazyitensors/evaluation_order.jl | 3 --- test/Project.toml | 6 ++--- test/test_lazyitensors.jl | 12 ++++----- 7 files changed, 12 insertions(+), 46 deletions(-) delete mode 100644 ext/ITensorBaseTensorOperationsExt/ITensorBaseTensorOperationsExt.jl diff --git a/Project.toml b/Project.toml index 42828b34..59ad31f0 100644 --- a/Project.toml +++ b/Project.toml @@ -1,6 +1,6 @@ name = "ITensorBase" uuid = "4795dd04-0d67-49bb-8f44-b89c448a1dc7" -version = "0.11.5" +version = "0.12.0" authors = ["ITensor developers and contributors"] [workspace] @@ -29,14 +29,12 @@ Adapt = "79e6a3ab-5dfb-504d-930d-738a2a938a0e" Mooncake = "da2b9cff-9c12-43a0-ae48-6db2b0edb7d6" OMEinsumContractionOrders = "6f22d1fd-8eed-4bb7-9776-e7d684900715" TensorKit = "07d1fe3e-3e46-537d-9eac-e9e13d0d4cec" -TensorOperations = "6aa20fa7-93e2-5fca-9bc0-fbd0db3c71a2" [extensions] ITensorBaseAdaptExt = "Adapt" ITensorBaseMooncakeExt = "Mooncake" ITensorBaseOMEinsumContractionOrdersExt = "OMEinsumContractionOrders" ITensorBaseTensorKitExt = "TensorKit" -ITensorBaseTensorOperationsExt = "TensorOperations" [compat] AbstractTrees = "0.4.5" @@ -48,13 +46,12 @@ ConstructionBase = "1.6" LinearAlgebra = "1.10" MatrixAlgebraKit = "0.2, 0.3, 0.4, 0.5, 0.6" Mooncake = "0.4.202, 0.5" -OMEinsumContractionOrders = "1" +OMEinsumContractionOrders = "1.3" OrderedCollections = "1.6" Random = "1.10" SimpleTraits = "0.9.4" TensorAlgebra = "0.17.3" TensorKit = "0.17" -TensorOperations = "5.3.1" TermInterface = "2" TupleTools = "1.6" UUIDs = "1.10" diff --git a/docs/Project.toml b/docs/Project.toml index d54500c0..b5ba24fb 100644 --- a/docs/Project.toml +++ b/docs/Project.toml @@ -12,7 +12,7 @@ path = ".." [compat] Documenter = "1" -ITensorBase = "0.11" +ITensorBase = "0.12" ITensorFormatter = "0.2.27" Literate = "2" MatrixAlgebraKit = "0.2, 0.3, 0.4, 0.5, 0.6" diff --git a/examples/Project.toml b/examples/Project.toml index 5af97d2e..1b8dfcbd 100644 --- a/examples/Project.toml +++ b/examples/Project.toml @@ -6,5 +6,5 @@ MatrixAlgebraKit = "6c742aac-3347-4629-af66-fc926824e5e4" path = ".." [compat] -ITensorBase = "0.11" +ITensorBase = "0.12" MatrixAlgebraKit = "0.2, 0.3, 0.4, 0.5, 0.6" diff --git a/ext/ITensorBaseTensorOperationsExt/ITensorBaseTensorOperationsExt.jl b/ext/ITensorBaseTensorOperationsExt/ITensorBaseTensorOperationsExt.jl deleted file mode 100644 index d8b39773..00000000 --- a/ext/ITensorBaseTensorOperationsExt/ITensorBaseTensorOperationsExt.jl +++ /dev/null @@ -1,26 +0,0 @@ -module ITensorBaseTensorOperationsExt - -using ITensorBase.TermInterface: arguments -using ITensorBase: ITensorBase, Optimal, inds, ismul, optimize_contraction_order, - substitute, symnameddims, unnamed -using TensorOperations: TensorOperations, optimaltree - -function contraction_tree_to_expr(f, tree) - return if !(tree isa AbstractVector) - f(tree) - else - prod(Base.Fix1(contraction_tree_to_expr, f), tree) - end -end - -function ITensorBase.optimize_contraction_order(alg::Optimal, a) - @assert ismul(a) - ts = arguments(a) - inds_network = collect.(inds.(ts)) - # Converting dims to Float64 to minimize overflow issues - inds_to_dims = Dict(i => Float64(length(i)) for i in reduce(∪, inds_network)) - tree, _ = optimaltree(inds_network, inds_to_dims) - return contraction_tree_to_expr(i -> ts[i], tree) -end - -end diff --git a/src/lazyitensors/evaluation_order.jl b/src/lazyitensors/evaluation_order.jl index c0596c73..a2dc0f79 100644 --- a/src/lazyitensors/evaluation_order.jl +++ b/src/lazyitensors/evaluation_order.jl @@ -85,9 +85,6 @@ end abstract type EvaluationOrderAlgorithm end struct Greedy <: EvaluationOrderAlgorithm end -# `Optimal` finds the cost-optimal contraction order. The method is provided by -# the TensorOperations extension. -struct Optimal <: EvaluationOrderAlgorithm end default_optimize_evaluation_order_alg(a) = Greedy() function optimize_contraction_order(alg, a) diff --git a/test/Project.toml b/test/Project.toml index 35563cde..fdba84e2 100644 --- a/test/Project.toml +++ b/test/Project.toml @@ -16,7 +16,6 @@ StableRNGs = "860ef19b-820b-49d6-a774-d7a799459cd3" Suppressor = "fd094767-a336-5f1f-9728-57cf17d0bbfb" TensorAlgebra = "68bd88dc-f39d-4e12-b2ca-f046b68fcc6a" TensorKit = "07d1fe3e-3e46-537d-9eac-e9e13d0d4cec" -TensorOperations = "6aa20fa7-93e2-5fca-9bc0-fbd0db3c71a2" TermInterface = "8ea1fca8-c5ef-4a55-8b96-4e9afe9c9a3c" Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40" UUIDs = "cf7118a7-6976-5b1a-9a39-7adc72f591a4" @@ -31,20 +30,19 @@ AbstractTrees = "0.4.5" Adapt = "4" Aqua = "0.8.9" Combinatorics = "1" -ITensorBase = "0.11" +ITensorBase = "0.12" ITensorPkgSkeleton = "0.3.42" JLArrays = "0.2, 0.3" LinearAlgebra = "1.10" MatrixAlgebraKit = "0.2, 0.3, 0.4, 0.5, 0.6" Mooncake = "0.4, 0.5" -OMEinsumContractionOrders = "1" +OMEinsumContractionOrders = "1.3" Random = "1.10" SafeTestsets = "0.1" StableRNGs = "1" Suppressor = "0.2" TensorAlgebra = "0.17" TensorKit = "0.17" -TensorOperations = "5.3.1" TermInterface = "2" Test = "1.10" UUIDs = "1.10" diff --git a/test/test_lazyitensors.jl b/test/test_lazyitensors.jl index e4a5e9b1..4f560d8c 100644 --- a/test/test_lazyitensors.jl +++ b/test/test_lazyitensors.jl @@ -1,10 +1,9 @@ using AbstractTrees: AbstractTrees, print_tree, printnode using Base.Broadcast: materialize -using ITensorBase: @names, Greedy, LazyNamedTensor, Mul, NamedTensor, Optimal, - SymbolicNamedTensor, dimnames, inds, ismul, lazy, nameddims, namedoneto, - optimize_evaluation_order, substitute, symnameddims -using OMEinsumContractionOrders: GreedyMethod, TreeSA -using TensorOperations: TensorOperations +using ITensorBase: @names, Greedy, LazyNamedTensor, Mul, NamedTensor, SymbolicNamedTensor, + dimnames, inds, ismul, lazy, nameddims, namedoneto, optimize_evaluation_order, + substitute, symnameddims +using OMEinsumContractionOrders: ExhaustiveSearch, GreedyMethod, TreeSA using TermInterface: arguments, arity, children, head, iscall, isexpr, maketerm, operation, sorted_arguments, sorted_children using Test: @test, @test_broken, @test_throws, @testset @@ -108,7 +107,7 @@ using WrappedUnions: unwrap @test arguments(net) == [l[1], l[2] * l[3]] end - @testset "optimize_evaluation_order ($alg)" for alg in (Greedy(), Optimal()) + @testset "optimize_evaluation_order ($alg)" for alg in (Greedy(),) i, j, k, l = namedoneto.((2, 3, 4, 5), (:i, :j, :k, :l)) s = [symnameddims(:a, (i, j)), symnameddims(:b, (j, k)), symnameddims(:c, (k, l))] flat = lazy(Mul(s)) @@ -123,6 +122,7 @@ using WrappedUnions: unwrap @testset "optimize_evaluation_order (OMEinsumContractionOrders $alg)" for alg in ( + ExhaustiveSearch(), GreedyMethod(), TreeSA(), )