Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[ITensors] [BUG] Having four QNs but "Cannot add QNVal, QN already contains maximum number of QNVals" #1341

Open
tingyu-gao opened this issue Feb 24, 2024 · 0 comments
Labels
bug Something isn't working ITensors Issues or pull requests related to the `ITensors` package.

Comments

@tingyu-gao
Copy link

Description of bug

I simulated a Hamiltonian with $U(1) \times U(1) \times U(1) \times U(1)$ symmetry. To utilize such a symmetry, I constructed site indices with four different QNs. But I encountered an error Cannot add QNVal, QN already contains maximum number of QNVals from the qn.jl. The error occurred when I constructed the Hamiltonian MPO. After I increased the constant maxQNs from 4 to 5 (or a larger number), I did not reencounter the same error.

Minimal code demonstrating the bug or unexpected behavior

using ITensors
using ITensorInfiniteMPS
function ITensorInfiniteMPS.unit_cell_terms(::Model"H"; 
        L = nothing, N::Int = 4, 
        J::Real = 1, Delta::Real = 1, Jc::Real)
    """
    We consider four open Heisenberg (XXZ) spin 1/2 chains coupled by nearest-neighbor spin current interaction.
    In the vertical direction, the system is periodic.
    The Hamiltonian commutes with the total magnetization on each chain.
    Therefore, each eigenstate can be labeled by four quantum numbers.
    """
    ipp(i) = mod1(i+1, N) # It gives the next chain index.
    opsum = OpSum()
    for i in 1:N
        # XXZ
        opsum += J/2, "S+", i, "S-", i+N
        opsum += J/2, "S-", i, "S+", i+N
        opsum += Delta, "Sz", i, "Sz", i+N
        # Spin current interaction, J_spin = i/2*(S+ S- - S- S+)
        opsum += -Jc/4, "S+", i+N, "S-", i, "S+", ipp(i)+N, "S-", ipp(i)
        opsum += -Jc/4, "S-", i+N, "S+", i, "S-", ipp(i)+N, "S+", ipp(i)
        opsum +=  Jc/4, "S-", i+N, "S+", i, "S+", ipp(i)+N, "S-", ipp(i)
        opsum +=  Jc/4, "S+", i+N, "S-", i, "S-", ipp(i)+N, "S+", ipp(i)
    end
    return opsum
end

N = 4 # Number of chain
L = 16 # Length of each chain
s = [siteind("S=1/2"; conserve_qns=true, qnname_sz = "Sz$(mod1(j,N))") for j in 1:N*L]
h = MPO(Model("H"), s; Jc = rand())

Expected output or behavior

In the end, I should get a matrix product operator.

Actual output or behavior

Cannot add QNVal, QN already contains maximum number of QNVals

Stacktrace:
  [1] error(s::String)
    @ Base ./error.jl:33
  [2] addqnval(qn::QN, qv_add::ITensors.QNVal)
    @ ITensors ~/.julia/packages/ITensors/N9rhA/src/qn/qn.jl:281
  [3] fillqns_from(qn1::QN, qn2::QN)
    @ ITensors ~/.julia/packages/ITensors/N9rhA/src/qn/qn.jl:298
  [4] fillqns
    @ ~/.julia/packages/ITensors/N9rhA/src/qn/qn.jl:306 [inlined]
  [5] ==(qn1::QN, qn2::QN; assume_filled::Bool)
    @ ITensors ~/.julia/packages/ITensors/N9rhA/src/qn/qn.jl:321
  [6] ==
    @ ~/.julia/packages/ITensors/N9rhA/src/qn/qn.jl:320 [inlined]
  [7] isequal
    @ ./operators.jl:123 [inlined]
  [8] isequal
    @ ./pair.jl:55 [inlined]
  [9] ht_keyindex(h::Dict{Pair{Vector{Op}, QN}, Int64}, key::Pair{Vector{Op}, QN})
    @ Base ./dict.jl:291
 [10] get
    @ ./dict.jl:505 [inlined]
 [11] posInLink!
    @ ~/.julia/packages/ITensors/N9rhA/src/physics/autompo/opsum_to_mpo_generic.jl:115 [inlined]
 [12] qn_svdMPO(os::Sum{Scaled{ComplexF64, Prod{Op}}}, sites::Vector{Index{Vector{Pair{QN, Int64}}}}; kwargs::Base.Iterators.Pairs{Union{}, Union{}, Tuple{}, NamedTuple{(), Tuple{}}})
    @ ITensors ~/.julia/packages/ITensors/N9rhA/src/physics/autompo/opsum_to_mpo_qn.jl:64
 [13] qn_svdMPO
    @ ~/.julia/packages/ITensors/N9rhA/src/physics/autompo/opsum_to_mpo_qn.jl:2 [inlined]
 [14] MPO(os::Sum{Scaled{ComplexF64, Prod{Op}}}, sites::Vector{Index{Vector{Pair{QN, Int64}}}}; splitblocks::Bool, kwargs::Base.Iterators.Pairs{Union{}, Union{}, Tuple{}, NamedTuple{(), Tuple{}}})
    @ ITensors ~/.julia/packages/ITensors/N9rhA/src/physics/autompo/opsum_to_mpo_generic.jl:300
 [15] MPO
    @ ~/.julia/packages/ITensors/N9rhA/src/physics/autompo/opsum_to_mpo_generic.jl:293 [inlined]
 [16] #MPO#160
    @ ~/.julia/packages/ITensorInfiniteMPS/C1o6c/src/models/models.jl:125 [inlined]
 [17] top-level scope
    @ In[7]:29
 [18] eval
    @ ./boot.jl:360 [inlined]
 [19] include_string(mapexpr::typeof(REPL.softscope), mod::Module, code::String, filename::String)
    @ Base ./loading.jl:1116

Version information

  • Output from versioninfo():
julia> versioninfo()
Julia Version 1.6.3
Commit ae8452a9e0 (2021-09-23 17:34 UTC)
Platform Info:
  OS: macOS (x86_64-apple-darwin19.5.0)
  CPU: Apple M1
  WORD_SIZE: 64
  LIBM: libopenlibm
  LLVM: libLLVM-11.0.1 (ORCJIT, westmere)
  • Output from using Pkg; Pkg.status("ITensors"):
julia> using Pkg; Pkg.status("ITensors")
      Status `~/.julia/environments/v1.6/Project.toml`
  [9136182c] ITensors v0.3.38
@tingyu-gao tingyu-gao added bug Something isn't working ITensors Issues or pull requests related to the `ITensors` package. labels Feb 24, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working ITensors Issues or pull requests related to the `ITensors` package.
Projects
None yet
Development

No branches or pull requests

1 participant