This repository was archived by the owner on Apr 14, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
[BUG] Issues slicing dense arrays by graded unit ranges #9
Copy link
Copy link
Closed
ITensor/BlockSparseArrays.jl
#36Labels
bugSomething isn't workingSomething isn't working
Description
Ideally, we could do something like this:
using GradedUnitRanges
using SymmetrySectors
a = [0 1; 0 0]
r = gradedrange([U1(0) => 1, U1(1) => 1])
b = a[r, dual(r)]and b would be a BlockSparseArray with axes (r, dual(r)) and one stored block.
In practice the output is:
julia> b = a[r, dual(r)]
2×2-blocked 2×2 BlockArrays.BlockedMatrix{Int64, Matrix{Int64}, Tuple{GradedUnitRanges.GradedOneTo{LabelledNumbers.LabelledInteger{Int64, U1{Int64}}, Vector{LabelledNumbers.LabelledInteger{Int64, U1{Int64}}}}, GradedUnitRanges.GradedOneTo{LabelledNumbers.LabelledInteger{Int64, U1{Int64}}, Vector{LabelledNumbers.LabelledInteger{Int64, U1{Int64}}}}}}:
0 │ 1
───┼───
0 │ 0
julia> axes(b)
(GradedOneTo[U(1)[0] => 1:1, U(1)[1] => 2:2], GradedOneTo[U(1)[0] => 1:1, U(1)[1] => 2:2])which has a few issues:
- It is a
BlockArrays.BlockedMatrix, not aBlockSparseArrays.BlockSparseMatrix(because it is falling back to genericBlockArrays.jlindexing code). - The dual information is dropped.
Fixing this would be very helpful for writing generic code for constructing dense or (abelian) symmetry states/operators, see ITensor/QuantumOperatorDefinitions.jl#17.
There is also an issue slicing BitVector by GradedOneTo (at least in Julia 1.11, it doesn't appear in Julia 1.10):
julia> BitMatrix([0 1; 0 0])[r, dual(r)]
2×2-blocked 2×2 BlockArrays.BlockMatrix{Bool, Matrix{Matrix{Bool}}, Tuple{GradedUnitRanges.GradedOneTo{LabelledNumbers.LabelledInteger{Int64, U1{Int64}}, Vector{LabelledNumbers.LabelledInteger{Int64, U1{Int64}}}}, GradedUnitRanges.GradedOneTo{LabelledNumbers.LabelledInteger{Int64, U1{Int64}}, Vector{LabelledNumbers.LabelledInteger{Int64, U1{Int64}}}}}}:
0 │ 1
───┼───
0 │ 0
julia> BitVector([1, 0])[r]
ERROR: MethodError: no method matching LabelledNumbers.LabelledInteger{Int64, U1{Int64}}(::Int64)
The type `LabelledNumbers.LabelledInteger{Int64, U1{Int64}}` exists, but no method is defined for this combination of argument types when trying to construct it.
Closest candidates are:
(::Type{LabelledNumbers.LabelledInteger{Value, Label}} where {Value<:Integer, Label})(::Any, ::Any)
@ LabelledNumbers ~/.julia/packages/LabelledNumbers/xPJrg/src/labelledinteger.jl:2
(::Type{T})(::T) where T<:Number
@ Core boot.jl:900
(::Type{T})(::BigFloat) where T<:Integer
@ Base mpfr.jl:403
...
Stacktrace:
[1] convert(::Type{LabelledNumbers.LabelledInteger{Int64, U1{Int64}}}, x::Int64)
@ Base ./number.jl:7
[2] _prechecked_iterate(iter::GradedUnitRanges.GradedOneTo{…}, i::LabelledNumbers.LabelledInteger{…})
@ Base ./multidimensional.jl:893
[3] _unsafe_getindex!
@ ./multidimensional.jl:937 [inlined]
[4] _unsafe_getindex(::IndexLinear, A::BitVector, I::GradedUnitRanges.GradedOneTo{LabelledNumbers.LabelledInteger{…}, Vector{…}})
@ Base ./multidimensional.jl:929
[5] _getindex
@ ./multidimensional.jl:915 [inlined]
[6] getindex(A::BitVector, I::GradedUnitRanges.GradedOneTo{LabelledNumbers.LabelledInteger{Int64, U1{…}}, Vector{LabelledNumbers.LabelledInteger{…}}})
@ Base ./abstractarray.jl:1312
[7] top-level scope
@ REPL[12]:1
Some type information was truncated. Use `show(err)` to see complete types.Metadata
Metadata
Assignees
Labels
bugSomething isn't workingSomething isn't working