-
Notifications
You must be signed in to change notification settings - Fork 126
Description
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
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