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] Optimize directsum again #1221

Merged
merged 6 commits into from
Oct 27, 2023
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
8 changes: 8 additions & 0 deletions src/itensor.jl
Original file line number Diff line number Diff line change
Expand Up @@ -269,6 +269,14 @@ ITensor(x::RealOrComplex{Int}, is...) = ITensor(float(x), is...)
# EmptyStorage ITensor constructors
#

# TODO: Replace with a simpler and more generic `zeros` constructor
# when the new `UnallocatedZeros` type lands.
# This is only used internally inside the implementation of `directsum`
# right now.
function zeros_itensor(elt::Type{<:Number}, inds::Index...)
return ITensor(elt, zero(elt), inds...)
end

# TODO: Deprecated!
"""
emptyITensor([::Type{ElT} = NDTensors.EmptyNumber, ]inds)
Expand Down
16 changes: 16 additions & 0 deletions src/qn/qnitensor.jl
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,22 @@
return setindex!!(T, x, I...)
end

# TODO: Replace with a simpler and more generic `zeros` constructor
# when the new `UnallocatedZeros` type lands.
# This is needed for now since there is some issue with calling
# `setindex!` on `EmptyTensor`, it's not really worth investigating
# right now since that type will be removed soon anyway in
# https://github.com/ITensor/ITensors.jl/pull/1213.
# This is only used internally inside the implementation of `directsum`
# right now.
function zeros_itensor(elt::Type{<:Number}, inds::QNIndex...)
return itensor(
tensor(
BlockSparse(elt, undef, NDTensors.Dictionary{Block{length(inds)},Int}(), 0), inds
),
)
end

"""
ITensor([::Type{ElT} = Float64, ][flux::QN = QN(), ]inds)
ITensor([::Type{ElT} = Float64, ][flux::QN = QN(), ]inds::Index...)
Expand Down
11 changes: 9 additions & 2 deletions src/tensor_operations/tensor_algebra.jl
Original file line number Diff line number Diff line change
Expand Up @@ -279,8 +279,15 @@ end
function directsum_projectors(
elt1::Type{<:Number}, elt2::Type{<:Number}, i::Index, j::Index, ij::Index
)
D1 = ITensor(elt1, QN(), dag(i), ij)
D2 = ITensor(elt2, QN(), dag(j), ij)
# Ideally we would just use the following but it gives
# an error that `setindex!` isn't defined:
# D1 = ITensor(elt1, dag(i), ij)
# D2 = ITensor(elt1, dag(j), ij)
# Or with new notation:
# D1 = zeros(elt1, dag(i), ij)
# D2 = zeros(elt1, dag(j), ij)
D1 = zeros_itensor(elt1, dag(i), ij)
D2 = zeros_itensor(elt1, dag(j), ij)
directsum_projectors!(tensor(D1), tensor(D2))
return D1, D2
end
Expand Down
Loading