From e3965efa2c0b55bb1e7c16739690d8769d02636e Mon Sep 17 00:00:00 2001 From: LHerviou Date: Mon, 26 Jun 2023 10:11:38 +0200 Subject: [PATCH 1/2] Testing with newest ITensor --- src/ITensors.jl | 14 +++++++------- src/infinitempo.jl | 10 ---------- src/infinitempomatrix.jl | 24 ++++++++++++------------ 3 files changed, 19 insertions(+), 29 deletions(-) diff --git a/src/ITensors.jl b/src/ITensors.jl index 1eca3907..61d4f856 100644 --- a/src/ITensors.jl +++ b/src/ITensors.jl @@ -183,13 +183,13 @@ end # Handle orthogonality center correctly Base.getindex(ψ::MPS, r::UnitRange{Int}) = MPS([ψ[n] for n in r]) -Base.zero(T::ITensor) = false * T - -function ITensors.NDTensors.datatype( - ::ITensors.EmptyStorage{Float64,ITensors.NDTensors.BlockSparse{Float64,Vector{Float64},N}} -) where {N} - return Vector{Float64} -end +# Base.zero(T::ITensor) = false * T +# +# function ITensors.NDTensors.datatype( +# ::ITensors.EmptyStorage{Float64,ITensors.NDTensors.BlockSparse{Float64,Vector{Float64},N}} +# ) where {N} +# return Vector{Float64} +# end # # function ITensors.NDTensors.datatype(T::ITensors.NDTensors.TensorStorage{Float64}) # return typeof(data(T)) diff --git a/src/infinitempo.jl b/src/infinitempo.jl index fd8c7776..abf89670 100644 --- a/src/infinitempo.jl +++ b/src/infinitempo.jl @@ -44,11 +44,6 @@ function cat_to_itensor(Hm::Matrix{ITensor}) end append!(input, [Hm[x, ly] * onehot(T, right_links[ly] => 1) => right_links[ly]]) H, ir = directsum(input...; tags="Link, right") - # H, ir = directsum( - # [((y == 1 || y == ly) ? Hm[x, y] * onehot(T, right_links[y] => 1) : Hm[x, y]) => - # right_links[y] for y in 1:ly]...; - # tags="Link, right", - # ) if x == 1 append!(new_rs, [ir]) else @@ -62,11 +57,6 @@ function cat_to_itensor(Hm::Matrix{ITensor}) end append!(input, [Ls[lx] * onehot(T, left_links[lx] => 1) => left_links[lx]]) H, new_l = directsum(input...; tags="Link, left") - # H, new_l = directsum( - # [((x == 1 || x == lx) ? Ls[x] * onehot(T, left_links[x] => 1) : Ls[x]) => left_links[x] for - # x in 1:lx]...; - # tags="Link, left", - # ) return H, new_l, new_rs[1] end # diff --git a/src/infinitempomatrix.jl b/src/infinitempomatrix.jl index 25eaf8cf..2522af84 100644 --- a/src/infinitempomatrix.jl +++ b/src/infinitempomatrix.jl @@ -220,15 +220,15 @@ function apply_tensor(A::Array{ITensor,N}, B::ITensor...) where {N} return new_A end -import ITensors._add -function ITensors._add( - A::T1, B::T2 -) where {T1<:ITensors.NDTensors.EmptyTensor,T2<:ITensors.NDTensors.EmptyTensor} - ndims(A) != ndims(B) && throw( - ITensors.DimensionMismatch("cannot add ITensors with different numbers of indices") - ) - indices = inds(A) - length(commoninds(indices, B)) != length(inds(B)) && - error("cannot add ITensors with different indices") - return ITensor(promote_type(eltype(A), eltype(B)), indices) -end +# import ITensors._add +# function ITensors._add( +# A::T1, B::T2 +# ) where {T1<:ITensors.NDTensors.EmptyTensor,T2<:ITensors.NDTensors.EmptyTensor} +# ndims(A) != ndims(B) && throw( +# ITensors.DimensionMismatch("cannot add ITensors with different numbers of indices") +# ) +# indices = inds(A) +# length(commoninds(indices, B)) != length(inds(B)) && +# error("cannot add ITensors with different indices") +# return ITensor(promote_type(eltype(A), eltype(B)), indices) +# end From d9bdba50b0fc69a82d2fe2d9383c127691c324d1 Mon Sep 17 00:00:00 2001 From: LHerviou Date: Mon, 26 Jun 2023 11:08:55 +0200 Subject: [PATCH 2/2] Testing the fix --- src/ITensors.jl | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/ITensors.jl b/src/ITensors.jl index 61d4f856..ec8310bd 100644 --- a/src/ITensors.jl +++ b/src/ITensors.jl @@ -194,3 +194,5 @@ Base.getindex(ψ::MPS, r::UnitRange{Int}) = MPS([ψ[n] for n in r]) # function ITensors.NDTensors.datatype(T::ITensors.NDTensors.TensorStorage{Float64}) # return typeof(data(T)) # end + +Base.fill!(::NDTensors.NoData, ::Any) = 0