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] [BUG] Sum of MPS involving link dimension zero fails. #76

Open
amilsted opened this issue Jun 16, 2022 · 0 comments
Open

[ITensors] [BUG] Sum of MPS involving link dimension zero fails. #76

amilsted opened this issue Jun 16, 2022 · 0 comments
Labels
bug Something isn't working

Comments

@amilsted
Copy link

Description of bug

If we try to add two MPS, and one of them was created with linkdims of 0, we get a MethodError.

Minimal code demonstrating the bug or unexpected behavior

Minimal runnable code

sinds = [Index(2) for _ in 1:5]
m1 = MPS(sinds; linkdims=1)
m2 = MPS(sinds; linkdims=0)
m1 + m2  # throws a MethodError

Expected output or behavior

Should get a new MPS with bond dimension 1.

Actual output or behavior

MethodError

Output of minimal runnable code

MethodError: similar(::NDTensors.EmptyTensor{Float64, 2, Tuple{ITensors.Index{Int64}, ITensors.Index{Int64}}, NDTensors.EmptyStorage{Float64, NDTensors.Dense{Float64, Vector{Float64}}}}, ::Type{Float64}, ::Tuple{Int64, Int64}) is ambiguous. Candidates:
  similar(a::AbstractArray, ::Type{T}, dims::Tuple{Vararg{Int64, N}}) where {T, N} in Base at abstractarray.jl:794
  similar(a::AbstractArray, ::Type{T}, dims::Tuple{Integer, Vararg{Integer}}) where T in Base at abstractarray.jl:792
  similar(a::AbstractArray, ::Type{T}, dims::Tuple{Union{Integer, Base.OneTo}, Vararg{Union{Integer, Base.OneTo}}}) where T in Base at abstractarray.jl:791
  similar(A::AbstractArray, ::Type{T}, shape::Tuple{Union{Integer, AbstractUnitRange}, Vararg{Union{Integer, AbstractUnitRange}}}) where T in OffsetArrays at /Users/ammilste/.julia/packages/OffsetArrays/qPBwO/src/OffsetArrays.jl:320
  similar(T::NDTensors.Tensor, args...) in NDTensors at /Users/ammilste/.julia/packages/NDTensors/lbVmG/src/tensor.jl:132
Possible fix, define
  similar(::NDTensors.Tensor, ::Type{T}, ::Tuple{Int64, Vararg{Int64, N}}) where {T, N}

Stacktrace:
  [1] qr(::NDTensors.EmptyTensor{Float64, 2, Tuple{ITensors.Index{Int64}, ITensors.Index{Int64}}, NDTensors.EmptyStorage{Float64, NDTensors.Dense{Float64, Vector{Float64}}}}, ::Tuple{Int64}, ::Vararg{Tuple{Int64}}; kwargs::Base.Pairs{Symbol, ITensors.TagSet, Tuple{Symbol}, NamedTuple{(:tags,), Tuple{ITensors.TagSet}}})
    @ LinearAlgebra /Applications/Julia-1.7.app/Contents/Resources/julia/share/julia/stdlib/v1.7/LinearAlgebra/src/qr.jl:418
  [2] qr(A::ITensors.ITensor, Linds::Vector{ITensors.Index{Int64}}; kwargs::Base.Pairs{Symbol, ITensors.TagSet, Tuple{Symbol}, NamedTuple{(:tags,), Tuple{ITensors.TagSet}}})
    @ ITensors ~/.julia/packages/ITensors/5dcHw/src/decomp.jl:355
  [3] factorize_qr(A::ITensors.ITensor, Linds::Vector{ITensors.Index{Int64}}; kwargs::Base.Pairs{Symbol, ITensors.TagSet, Tuple{Symbol}, NamedTuple{(:tags,), Tuple{ITensors.TagSet}}})
    @ ITensors ~/.julia/packages/ITensors/5dcHw/src/decomp.jl:389
  [4] factorize(A::ITensors.ITensor, Linds::Vector{ITensors.Index{Int64}}; kwargs::Base.Pairs{Symbol, ITensors.TagSet, Tuple{Symbol}, NamedTuple{(:tags,), Tuple{ITensors.TagSet}}})
    @ ITensors ~/.julia/packages/ITensors/5dcHw/src/decomp.jl:533
  [5] orthogonalize!(M::ITensors.MPS, j::Int64; kwargs::Base.Pairs{Symbol, Union{}, Tuple{}, NamedTuple{(), Tuple{}}})
    @ ITensors ~/.julia/packages/ITensors/5dcHw/src/mps/abstractmps.jl:1551
  [6] orthogonalize!
    @ ~/.julia/packages/ITensors/5dcHw/src/mps/abstractmps.jl:1536 [inlined]
  [7] #orthogonalize#701
    @ ~/.julia/packages/ITensors/5dcHw/src/mps/abstractmps.jl:1586 [inlined]
  [8] orthogonalize
    @ ~/.julia/packages/ITensors/5dcHw/src/mps/abstractmps.jl:1585 [inlined]
  [9] _broadcast_getindex_evalf
    @ ./broadcast.jl:670 [inlined]
 [10] _broadcast_getindex
    @ ./broadcast.jl:643 [inlined]
 [11] ITensor/ITensors.jl#29
    @ ./broadcast.jl:1075 [inlined]
 [12] ntuple
    @ ./ntuple.jl:49 [inlined]
 [13] copy
    @ ./broadcast.jl:1075 [inlined]
 [14] materialize(bc::Base.Broadcast.Broadcasted{Base.Broadcast.Style{Tuple}, Nothing, typeof(ITensors.orthogonalize), Tuple{Tuple{ITensors.MPS, ITensors.MPS}, Int64}})
    @ Base.Broadcast ./broadcast.jl:860
 [15] +(::ITensors.Algorithm{:densitymatrix}, ::ITensors.MPS, ::Vararg{ITensors.MPS}; cutoff::Float64, kwargs::Base.Pairs{Symbol, Union{}, Tuple{}, NamedTuple{(), Tuple{}}})
    @ ITensors ~/.julia/packages/ITensors/5dcHw/src/mps/abstractmps.jl:1408
 [16] +(::ITensors.Algorithm{:densitymatrix}, ::ITensors.MPS, ::ITensors.MPS)
    @ ITensors ~/.julia/packages/ITensors/5dcHw/src/mps/abstractmps.jl:1384
 [17] +(::ITensors.MPS, ::Vararg{ITensors.MPS}; alg::ITensors.Algorithm{:densitymatrix}, kwargs::Base.Pairs{Symbol, Union{}, Tuple{}, NamedTuple{(), Tuple{}}})
    @ ITensors ~/.julia/packages/ITensors/5dcHw/src/mps/abstractmps.jl:1488
 [18] +(::ITensors.MPS, ::ITensors.MPS)
    @ ITensors ~/.julia/packages/ITensors/5dcHw/src/mps/abstractmps.jl:1488
 [19] top-level scope
    @ In[425]:1
 [20] eval
    @ ./boot.jl:373 [inlined]
 [21] include_string(mapexpr::typeof(REPL.softscope), mod::Module, code::String, filename::String)
    @ Base ./loading.jl:1196

Version information

  • Output from versioninfo():
julia> versioninfo()
Julia Version 1.7.3
Commit 742b9abb4d (2022-05-06 12:58 UTC)
Platform Info:
  OS: macOS (x86_64-apple-darwin21.4.0)
  CPU: Intel(R) Core(TM) i7-9750H CPU @ 2.60GHz
  WORD_SIZE: 64
  LIBM: libopenlibm
  LLVM: libLLVM-12.0.1 (ORCJIT, skylake)
  • Output from using Pkg; Pkg.status("ITensors"):
julia> using Pkg; Pkg.status("ITensors")
[9136182c] ITensors v0.3.16
@amilsted amilsted added the bug Something isn't working label Jun 16, 2022
@mtfishman mtfishman transferred this issue from ITensor/ITensors.jl Oct 25, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant