Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[ITensors] Remove combine-contract codepath #1427

Merged
merged 2 commits into from
May 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name = "ITensors"
uuid = "9136182c-28ba-11e9-034c-db9fb085ebd5"
authors = ["Matthew Fishman <[email protected]>", "Miles Stoudenmire <[email protected]>"]
version = "0.5.8"
version = "0.6.0"

[deps]
Adapt = "79e6a3ab-5dfb-504d-930d-738a2a938a0e"
Expand Down
3 changes: 0 additions & 3 deletions src/deprecated.jl
Original file line number Diff line number Diff line change
@@ -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
Expand Down
18 changes: 0 additions & 18 deletions src/global_variables.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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
#
Expand Down
34 changes: 1 addition & 33 deletions src/tensor_operations/tensor_algebra.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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}}})
Expand Down
27 changes: 0 additions & 27 deletions test/base/test_itensor_combine_contract.jl

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,6 @@ const ITENSORS_EXPORTED_NAMES = [
:dims,
:dir,
:directsum,
:disable_combine_contract!,
:disable_tblis!,
:disable_warn_order!,
:disk,
Expand All @@ -120,7 +119,6 @@ const ITENSORS_EXPORTED_NAMES = [
:eigen,
:eigs,
:emptyITensor,
:enable_combine_contract!,
:enable_tblis!,
:energies,
:entropy,
Expand Down Expand Up @@ -335,7 +333,6 @@ const ITENSORS_EXPORTED_NAMES = [
:uniqueind,
:uniqueindex,
:uniqueinds,
:use_combine_contract,
:use_debug_checks,
:val,
:vector,
Expand Down
Loading