Skip to content

[NDTensors] [BUG] denseblocks on DiagBlockSparse does not conserve QNs #1619

@AFeuerpfeil

Description

@AFeuerpfeil

Description of bug

When performing denseblocks on a DiagBlockSparse tensor, the output is a tensor, which in general does not conserve QNs and thus has no well-defined flux.

Minimal code demonstrating the bug or unexpected behavior

julia> i=Index([QN()=>2])
julia> j=Index([QN(("N",0))=>1,QN(("N",1))=>1])
julia> T=delta(dag(i),j)
julia> x=random_itensor(i)
julia> @show norm(x*T-x*denseblocks(T))

Expected output or behavior

The code should output 0.

Actual output or behavior

The output, however, is nonzero.
The reason for that is that T conserves the QNs. However, denseblocks(T) does not, which can be seen from the block-structure. ITensors, however, still asigns denseblocks(T) and x a flux QN(), even though their flux is not well-defined.

I suspect the problem is related to how NDTensors stores a diagblocksparse tensor internally, as it only stores one matrix element. When performing denseblocks, it probably does not check which flux was used in the constructor delta([::Type{ElT} = Float64, ][flux::QN = QN(), ]is)

julia> @show norm(x*T-x*denseblocks(T))
1.0470682860833809
julia> @show flux(T)
QN("N",0)
julia> @show flux(denseblocks(T))
QN("N",0)
julia> @show flux(x*denseblocks(T))
QN("N",0)
julia> @show ITensors.matrix(T)
[1.0 0.0; 0.0 1.0]
julia> @show ITensors.matrix(denseblocks(T))
[1.0 0.0; 0.0 1.0]

Version information

  • Output from versioninfo():
julia> versioninfo()
Julia Version 1.11.3
Commit d63adeda50d (2025-01-21 19:42 UTC)
Build Info:
  Official https://julialang.org/ release
Platform Info:
  OS: Linux (x86_64-linux-gnu)
  CPU: 12 × 13th Gen Intel(R) Core(TM) i7-1360P
  WORD_SIZE: 64
  LLVM: libLLVM-16.0.6 (ORCJIT, goldmont)
Threads: 12 default, 0 interactive, 6 GC (on 12 virtual cores)
Environment:
  JULIA_EDITOR = code
  JULIA_NUM_THREADS = 12
  JULIA_PKG_SERVER = https://juliahub.com/
  • Output from using Pkg; Pkg.status("ITensors"):
julia> using Pkg; Pkg.status("ITensors")
Status `~/.julia/environments/v1.11/Project.toml`
  [9136182c] ITensors v0.8.0

Metadata

Metadata

Assignees

No one assigned

    Labels

    NDTensorsRequires changes to the NDTensors.jl library.bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions