Skip to content

[ITensors] [BUG] Summation of QN gives incorrect result #1658

@ZhouGD2000

Description

@ZhouGD2000

Description of bug

When adding more than two QN() , or when one of the QN() to be added comes from summation, some of the quantum numbers are not added but just concatenated.

Minimal code demonstrating the bug or unexpected behavior
When running a three channel spinful model with $U(1)_c^3 \times U(1)_s$ symmetry, I meet the following bugs.

julia> qn1 = QN("Sz",0);

julia> qn2 = QN(("Nf1",-1,-1),("Nf2",0,-1),("Nf3",0,-1));

julia> qn3 =  QN(("Nf1",0,-1),("Nf2",0,-1),("Nf3",0,-1),("Sz",0));

julia> qn1 + qn2 + qn3
QN(("Nf2",0,-1),("Nf1",0,-1),("Nf3",0,-1),("Nf2",0,-1)) # wrong result

julia> qn12 = qn1 + qn2
QN(("Nf3",0,-1),("Nf2",0,-1),("Nf1",-1,-1),("Sz",0))

julia> QN(("Nf3",0,-1),("Nf2",0,-1),("Nf1",-1,-1),("Sz",0)) + qn3
QN(("Nf1",-1,-1),("Nf2",0,-1),("Nf3",0,-1),("Sz",0)) # correct result

julia> qn12 + qn3
QN(("Nf2",0,-1),("Nf1",0,-1),("Nf3",0,-1),("Nf2",0,-1)) #wrong result

when using the default maxQNs = 4. I then changed it to maxQNs = 6 and recompile the package, the result becomes

julia> qn1 + qn2 + qn3
QN(("Nf2",0,-1),("Nf1",0,-1),("Nf3",0,-1),("Nf2",0,-1),("Nf1",-1,-1),("Sz",0))

It is still wrong.

There are also some issues of == in QN

julia> qn12 = qn1 + qn2
QN(("Nf3",0,-1),("Nf2",0,-1),("Nf1",-1,-1),("Sz",0))

julia> qn1 + qn2 == QN(("Nf3",0,-1),("Nf2",0,-1),("Nf1",-1,-1),("Sz",0))
false # wrong, should be true

julia> qn12 == qn1 + qn2
true # correct

julia> qn12 == QN(("Nf3",0,-1),("Nf2",0,-1),("Nf1",-1,-1),("Sz",0))
false # wrong, should be true

If I explicitly define all "Nf1,2,3" and "Sz" for each QN, the result will be correct. Whereas, in qn.jl I find the comment that "Adding or subtracting pairs of QN objects performs addition and subtraction element-wise on each of the named values. If a name is missing from the collection, its value is treated as zero."

Version information

  • Output from versioninfo():
julia> versioninfo()
Julia Version 1.10.0-beta3
Commit 404750f8586 (2023-10-03 12:53 UTC)
Build Info:
  Official https://julialang.org/release
Platform Info:
  OS: macOS (arm64-apple-darwin22.4.0)
  CPU: 10 × Apple M2 Pro
  WORD_SIZE: 64
  LIBM: libopenlibm
  LLVM: libLLVM-15.0.7 (ORCJIT, apple-m1)
  Threads: 1 on 6 virtual cores
  • Output from using Pkg; Pkg.status("ITensors"):
julia> using Pkg; Pkg.status("ITensors")
Status `~/.julia/environments/v1.10/Project.toml`
  [9136182c] ITensors v0.9.6

Metadata

Metadata

Assignees

No one assigned

    Labels

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

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions