Why the constant maxQNs is set to 4?

Hi all,

I recently tried to simulate a system with U(1) \times U(1) \times U(1) \times U(1) symmetry but 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.

I have three questions related to this error. First, why the constant is set particularly to 4? Is there any reason for choosing this specific number? Second, is it possible not to define such a number if the answer to my first question is no? Finally, why do I encounter the error even though my system has precisely four conserved quantities? I have attached the infinite version of my Hamiltonian below. Nevertheless, my simulation was done for DMRG rather than VUMPS.

function ITensorInfiniteMPS.unit_cell_terms(::Model"Four_Heisenberg_chains"; 
	L = nothing, N::Int = 4, J::Real = 1, Delta::Real = 1, Jc::Real)
    ipp(i) = mod1(i+1, N)
    
    opsum = OpSum()
    # XXZ
    for i in 1:N
        opsum += J/2, "S+", i, "S-", i+N
        opsum += J/2, "S-", i, "S+", i+N
        opsum += Delta, "Sz", i, "Sz", i+N
    end

    # CC
    for i in 1:N
        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

Thanks! :slight_smile:

Choosing maxQNs=4 is a pretty arbitrary choice, and having a maximum value at all is mostly a consequence of the data structure we use for storing QNs. Internally, the data structure always has maxQNs entries, even if you only need fewer symmetries, so there is a tradeoff in choosing it too large and having some potential memory/performance overhead for all QN calculations, even if you only need a small number of them.

But the design is definitely unfortunate and we are aware it is not ideal. We have a completely new design in the works as part of our development of non-abelian symmetries, where you can have any number of symmetries, and even store them in a custom data structure in the case of having a very large number of symmetries.

As for why using 4 symmetries fails even if maxQNs is set to 4, I’m not sure why that is, that sounds like a bug. Could you make a minimal reproducible code for that and report it as an issue on Github: Issues · ITensor/ITensors.jl · GitHub?

Sure. I just posted it. https://github.com/ITensor/ITensors.jl/issues/1341