From b5a91795f457a40dc0a304f2809746848f50908b Mon Sep 17 00:00:00 2001 From: Matt Fishman Date: Wed, 8 May 2024 21:04:43 -0400 Subject: [PATCH] [ITensors] Remove combine-contract codepath (#1427) --- Project.toml | 2 +- src/deprecated.jl | 3 -- src/global_variables.jl | 18 ---------- src/tensor_operations/tensor_algebra.jl | 34 +------------------ test/base/test_itensor_combine_contract.jl | 27 --------------- .../TestITensorsExportedNames.jl | 3 -- 6 files changed, 2 insertions(+), 85 deletions(-) delete mode 100644 test/base/test_itensor_combine_contract.jl diff --git a/Project.toml b/Project.toml index d8378678ae..9fd5c9f574 100644 --- a/Project.toml +++ b/Project.toml @@ -1,7 +1,7 @@ name = "ITensors" uuid = "9136182c-28ba-11e9-034c-db9fb085ebd5" authors = ["Matthew Fishman ", "Miles Stoudenmire "] -version = "0.5.8" +version = "0.6.0" [deps] Adapt = "79e6a3ab-5dfb-504d-930d-738a2a938a0e" diff --git a/src/deprecated.jl b/src/deprecated.jl index 7cb108c5dc..6e2bc80472 100644 --- a/src/deprecated.jl +++ b/src/deprecated.jl @@ -1,13 +1,10 @@ # global_variables.jl -@deprecate disable_combine_contract!() ITensors.disable_combine_contract() @deprecate disable_tblis!() ITensors.disable_tblis() @deprecate disable_warn_order!() ITensors.disable_warn_order() -@deprecate enable_combine_contract!() ITensors.enable_combine_contract() @deprecate enable_tblis!() ITensors.enable_tblis() @deprecate reset_warn_order!() ITensors.reset_warn_order() @deprecate set_warn_order!(N) ITensors.set_warn_order(N) -@deprecate use_combine_contract() ITensors.using_combine_contract() @deprecate use_debug_checks() ITensors.using_debug_checks() # index.jl diff --git a/src/global_variables.jl b/src/global_variables.jl index 1db9724698..18ef622ac2 100644 --- a/src/global_variables.jl +++ b/src/global_variables.jl @@ -166,24 +166,6 @@ $(NDTensors.enable_threaded_blocksparse_docstring(@__MODULE__)) """ disable_threaded_blocksparse() = NDTensors._disable_threaded_blocksparse() -# -# Turn enable or disable combining QN ITensors before contracting -# - -const _using_combine_contract = Ref(false) - -using_combine_contract() = _using_combine_contract[] - -function enable_combine_contract() - _using_combine_contract[] = true - return nothing -end - -function disable_combine_contract() - _using_combine_contract[] = false - return nothing -end - # # Turn debug checks on and off # diff --git a/src/tensor_operations/tensor_algebra.jl b/src/tensor_operations/tensor_algebra.jl index 900b47cb97..c7739c971c 100644 --- a/src/tensor_operations/tensor_algebra.jl +++ b/src/tensor_operations/tensor_algebra.jl @@ -23,36 +23,6 @@ function _contract(A::ITensor, B::ITensor)::ITensor return C end -_contract(T::ITensor, ::Nothing) = T - -function can_combine_contract(A::ITensor, B::ITensor)::Bool - return hasqns(A) && - hasqns(B) && - !iscombiner(A) && - !iscombiner(B) && - !isdiag(A) && - !isdiag(B) -end - -function combine_contract(A::ITensor, B::ITensor)::ITensor - # Combine first before contracting - C::ITensor = if can_combine_contract(A, B) - uniqueindsA = uniqueinds(A, B) - uniqueindsB = uniqueinds(B, A) - commonindsAB = commoninds(A, B) - combinerA = isempty(uniqueindsA) ? nothing : combiner(uniqueindsA) - combinerB = isempty(uniqueindsB) ? nothing : combiner(uniqueindsB) - combinerAB = isempty(commonindsAB) ? nothing : combiner(commonindsAB) - AC = _contract(_contract(A, combinerA), combinerAB) - BC = _contract(_contract(B, combinerB), dag(combinerAB)) - CC = _contract(AC, BC) - _contract(_contract(CC, dag(combinerA)), dag(combinerB)) - else - _contract(A, B) - end - return C -end - """ A::ITensor * B::ITensor contract(A::ITensor, B::ITensor) @@ -100,10 +70,8 @@ function contract(A::ITensor, B::ITensor)::ITensor return iscombiner(A) ? _contract(A, B) : A[] * B elseif NB == 0 return iscombiner(B) ? _contract(B, A) : B[] * A - else - C = using_combine_contract() ? combine_contract(A, B) : _contract(A, B) - return C end + return _contract(A, B) end function optimal_contraction_sequence(A::Union{Vector{<:ITensor},Tuple{Vararg{ITensor}}}) diff --git a/test/base/test_itensor_combine_contract.jl b/test/base/test_itensor_combine_contract.jl deleted file mode 100644 index ec8ba15956..0000000000 --- a/test/base/test_itensor_combine_contract.jl +++ /dev/null @@ -1,27 +0,0 @@ -using ITensors -using Test -import Random: seed! - -seed!(12345) - -@testset "ITensor combine contract order $(2*N) tensors" for N in 1:5 - d = 1 - i = Index(QN(0) => d, QN(1) => d) - is = IndexSet(ntuple(n -> settags(i, "i$n"), Val(N))) - A = randomITensor(is'..., dag(is)...) - B = randomITensor(is'..., dag(is)...) - - @test !ITensors.using_combine_contract() - - C_contract = A' * B - - ITensors.enable_combine_contract() - @test ITensors.using_combine_contract() - - C_combine_contract = A' * B - - ITensors.disable_combine_contract() - @test !ITensors.using_combine_contract() - - @test C_contract ≈ C_combine_contract -end diff --git a/test/base/utils/TestITensorsExportedNames/TestITensorsExportedNames.jl b/test/base/utils/TestITensorsExportedNames/TestITensorsExportedNames.jl index c7a0f9e9ff..ba63bb2972 100644 --- a/test/base/utils/TestITensorsExportedNames/TestITensorsExportedNames.jl +++ b/test/base/utils/TestITensorsExportedNames/TestITensorsExportedNames.jl @@ -108,7 +108,6 @@ const ITENSORS_EXPORTED_NAMES = [ :dims, :dir, :directsum, - :disable_combine_contract!, :disable_tblis!, :disable_warn_order!, :disk, @@ -120,7 +119,6 @@ const ITENSORS_EXPORTED_NAMES = [ :eigen, :eigs, :emptyITensor, - :enable_combine_contract!, :enable_tblis!, :energies, :entropy, @@ -335,7 +333,6 @@ const ITENSORS_EXPORTED_NAMES = [ :uniqueind, :uniqueindex, :uniqueinds, - :use_combine_contract, :use_debug_checks, :val, :vector,