Skip to content

[ITensors] [BUG] Fail to permute the indices of an ITensor when using BigFloat #1690

Description

@ZhouGD2000

Description of bug

When permuting certain indices of ITensor, I find that for the sample code, as long as I change the type of elements in MPO/MPS from Float64 to BigFloat, the program fails.

I met this when doing DMRG with BigFloat, and the indices of MPO and MPS are needed to be permuted there. The minimal example was also reconstructed from there.

Minimal code demonstrating the bug or unexpected behavior

Minimal runnable code

using ITensors:QN,Index,prime,dag,permute,ITensor

i1 = Index([
    QN("Nf",0,1) => 1,
    QN("Nf",0,-1) => 1,
    QN("Nf",-1,-1) => 1,
    QN("Nf",1,-1) => 1,
    QN("Nf",0,-1) => 1,
]; tags="Link,l=1")

i3 = Index([
    QN("Nf",0,-1) => 1,
    QN("Nf",1,-1) => 1
]; tags="Fermion,Site,n=1")

# i1 = Index(5);
# i3 = Index(2);

i2 = prime(i3)
i3 = dag(i3)

# ITensor with BigFloat
T = ITensor(BigFloat, i1, i2, i3)
T[i1=>3, i2=>2, i3=>1] = BigFloat(1)
T[i1=>4, i2=>1, i3=>2] = -BigFloat(1)
T[i1=>5, i2=>1, i3=>1] = BigFloat(1)
T[i1=>5, i2=>2, i3=>2] = BigFloat(1)

# ITensor with Float64
# T = ITensor(Float64, i1, i2, i3)
# T[i1=>3, i2=>2, i3=>1] = 1.0;
# T[i1=>4, i2=>1, i3=>2] = -1.0;
# T[i1=>5, i2=>1, i3=>1] = 1.0;
# T[i1=>5, i2=>2, i3=>2] = 1.0;

T1 = permute(T,(i2,i3,i1))

Expected and actual output or behavior

I want to permute the indices of ITensor with QN, and the elements of it are BigFloat. However, the following error occurred when I ran the code above. I found that if I did not use the QN then the program will be fine, and if I use Float64 instead of BigFloat ( the commented out part in the example) there was not error too.

Besides, I have checked that using GenericLinearAlgebra does not make a difference.

Output of minimal runnable code

ERROR: LoadError: UndefRefError: access to undefined reference
Stacktrace:
  [1] getindex
    @ ./essentials.jl:917 [inlined]
  [2] getindex
    @ ./subarray.jl:343 [inlined]
  [3] _getindex
    @ ./abstractarray.jl:1341 [inlined]
  [4] getindex
    @ ./abstractarray.jl:1312 [inlined]
  [5] getindex
    @ ~/.julia/packages/NDTensors/Q9Zpu/src/lib/Expose/src/functions/abstractarray.jl:6 [inlined]
  [6] getindex
    @ ~/.julia/packages/NDTensors/Q9Zpu/src/dense/densetensor.jl:93 [inlined]
  [7] permutedims!(R::NDTensors.DenseTensor{BigFloat, 3, Tuple{Int64, Int64, Int64}, NDTensors.Dense{BigFloat, SubArray{BigFloat, 1, Vector{BigFloat}, Tuple{UnitRange{Int64}}, true}}}, T::NDTensors.DenseTensor{BigFloat, 3, Tuple{Int64, Int64, Int64}, NDTensors.Dense{BigFloat, SubArray{BigFloat, 1, Vector{BigFloat}, Tuple{UnitRange{Int64}}, true}}}, perm::Tuple{Int64, Int64, Int64}, f::NDTensors.var"#170#173")
    @ NDTensors ~/.julia/packages/NDTensors/Q9Zpu/src/dense/densetensor.jl:260
  [8] permutedims!(R::NDTensors.BlockSparseTensor{BigFloat, 3, Tuple{Index{Vector{Pair{QN, Int64}}}, Index{Vector{Pair{QN, Int64}}}, Index{Vector{Pair{QN, Int64}}}}, NDTensors.BlockSparse{BigFloat, Vector{BigFloat}, 3}}, T::NDTensors.BlockSparseTensor{BigFloat, 3, Tuple{Index{Vector{Pair{QN, Int64}}}, Index{Vector{Pair{QN, Int64}}}, Index{Vector{Pair{QN, Int64}}}}, NDTensors.BlockSparse{BigFloat, Vector{BigFloat}, 3}}, perm::Tuple{Int64, Int64, Int64}, f::NDTensors.var"#170#173")
    @ NDTensors ~/.julia/packages/NDTensors/Q9Zpu/src/blocksparse/blocksparsetensor.jl:830
  [9] permutedims!
    @ ~/.julia/packages/NDTensors/Q9Zpu/src/blocksparse/blocksparsetensor.jl:801 [inlined]
 [10] permutedims(T::NDTensors.BlockSparseTensor{BigFloat, 3, Tuple{Index{Vector{Pair{QN, Int64}}}, Index{Vector{Pair{QN, Int64}}}, Index{Vector{Pair{QN, Int64}}}}, NDTensors.BlockSparse{BigFloat, Vector{BigFloat}, 3}}, perm::Tuple{Int64, Int64, Int64})
    @ NDTensors ~/.julia/packages/NDTensors/Q9Zpu/src/blocksparse/blocksparsetensor.jl:439
 [11] permutedims
    @ ~/.julia/packages/ITensors/AOPBm/src/tensor_operations/permutations.jl:64 [inlined]
 [12] _permute(as::NDTensors.NeverAlias, T::NDTensors.BlockSparseTensor{BigFloat, 3, Tuple{Index{Vector{Pair{QN, Int64}}}, Index{Vector{Pair{QN, Int64}}}, Index{Vector{Pair{QN, Int64}}}}, NDTensors.BlockSparse{BigFloat, Vector{BigFloat}, 3}}, new_inds::Tuple{Index{Vector{Pair{QN, Int64}}}, Index{Vector{Pair{QN, Int64}}}, Index{Vector{Pair{QN, Int64}}}})
    @ ITensors ~/.julia/packages/ITensors/AOPBm/src/tensor_operations/permutations.jl:69
 [13] permute(as::NDTensors.NeverAlias, T::ITensor, new_inds::Tuple{Index{Vector{Pair{QN, Int64}}}, Index{Vector{Pair{QN, Int64}}}, Index{Vector{Pair{QN, Int64}}}})
    @ ITensors ~/.julia/packages/ITensors/AOPBm/src/tensor_operations/permutations.jl:73
 [14] #permute#253
    @ ~/.julia/packages/ITensors/AOPBm/src/tensor_operations/permutations.jl:54 [inlined]
 [15] permute(T::ITensor, new_inds::Tuple{Index{Vector{Pair{QN, Int64}}}, Index{Vector{Pair{QN, Int64}}}, Index{Vector{Pair{QN, Int64}}}})
    @ ITensors ~/.julia/packages/ITensors/AOPBm/src/tensor_operations/permutations.jl:38
 [16] top-level scope
    @ ~/research/2025/DMRG/test/test_bigfloat.jl:34

Version information

  • Output from versioninfo():
julia> versioninfo()
Julia Version 1.11.5
Commit 760b2e5b739 (2025-04-14 06:53 UTC)
Build Info:
  Official https://julialang.org/ release
Platform Info:
  OS: macOS (arm64-apple-darwin24.0.0)
  CPU: 10 × Apple M2 Pro
  WORD_SIZE: 64
  LLVM: libLLVM-16.0.6 (ORCJIT, apple-m2)
Threads: 1 default, 0 interactive, 1 GC (on 6 virtual cores)
Environment:
  LD_LIBRARY_PATH = /Users/software/boost_1_83_0/stage/lib:/opt/local/libexec/llvm-17/lib:/opt/local/lib/openmpi-clang17:
  JULIA_PKG_SERVER = https://mirrors.pku.edu.cn/julia
  JULIA_EDITOR = code
  JULIA_NUM_THREADS = 
  • Output from using Pkg; Pkg.status("ITensors"):
julia> using Pkg; Pkg.status("ITensors")
Status `~/.julia/environments/v1.11/Project.toml`
  [9136182c] ITensors v0.9.15

Metadata

Metadata

Assignees

No one assigned

    Labels

    ITensorsIssues or pull requests related to the `ITensors` package.bugSomething isn't working

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions