ITensor / ITensor/ITensorMPS.jl
[ITensors] [BUG] Sum of MPS involving link dimension zero fails.
Nobody has claimed this yet.
- Dominant language
- Julia
- Stars
- 85
- Forks
- 27
- Avg merge
- 22m
- Merged PRs (30d)
- 1
Description
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
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Reproduce the failure with the minimal Julia example, then trace the addition through orthogonalize! in abstractmps.jl and the QR path in decomp.jl. Inspect the similar dispatch for the EmptyTensor type shown in the MethodError, and verify that adding linkdims=1 and linkdims=0 MPS returns an MPS with bond dimension 1.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- julia
- Domain
- backend
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Clearly specified
- Newbie friendliness
- 45/100