Mixed site set with quantum number conservation

Hi,

Thanks for all your support so far! I have a (hopefully) quick question about creating a mixed site set involving electrons and bosons. Ideally, I would like to conserve quantum numbers for the electron sites and not conserve qns for the boson sites. I am able to get my code working in the case where I do not conserve qns for either:

sites = [isodd(n) ? siteind("Electron"; addtags="n=$n",conserve_qns=false) : siteind("Boson"; addtags="n=$n",conserve_qns=false, dim=phonon_dim) for n=1:Nsites]

This works fine. However, when I try to setconserve_qns=true for the electron sites, I get the following error message:

ERROR: LoadError: MethodError: no method matching -(::QN, ::Nothing)
Closest candidates are:
  -(::Prod{A}, ::A) where A at /Users/nicole/.julia/packages/ITensors/5CAqA/src/LazyApply/LazyApply.jl:183
  -(::ITensors.LazyApply.Applied{typeof(sum), Tuple{Array{ITensors.LazyApply.Applied{typeof(*), Tuple{C, Prod{A}}, NamedTuple{(), Tuple{}}}, 1}}, NamedTuple{(), Tuple{}}}, ::A) where {C, A} at /Users/nicole/.julia/packages/ITensors/5CAqA/src/LazyApply/LazyApply.jl:244
  -(::Sum{A}, ::A) where {C, A} at /Users/nicole/.julia/packages/ITensors/5CAqA/src/LazyApply/LazyApply.jl:82
  ...
Stacktrace:
  [1] (::ITensors.var"#calcQN#1172"{Vector{Index}, Dict{Pair{String, Int64}, ITensor}})(term::Vector{Op})
    @ ITensors ~/.julia/packages/ITensors/5CAqA/src/physics/autompo/opsum_to_mpo_qn.jl:28
  [2] qn_svdMPO(os::Sum{Scaled{ComplexF64, Prod{Op}}}, sites::Vector{Index}; kwargs::Base.Iterators.Pairs{Union{}, Union{}, Tuple{}, NamedTuple{(), Tuple{}}})
    @ ITensors ~/.julia/packages/ITensors/5CAqA/src/physics/autompo/opsum_to_mpo_qn.jl:50
  [3] qn_svdMPO
    @ ~/.julia/packages/ITensors/5CAqA/src/physics/autompo/opsum_to_mpo_qn.jl:2 [inlined]
  [4] MPO(os::Sum{Scaled{ComplexF64, Prod{Op}}}, sites::Vector{Index}; splitblocks::Bool, kwargs::Base.Iterators.Pairs{Union{}, Union{}, Tuple{}, NamedTuple{(), Tuple{}}})
    @ ITensors ~/.julia/packages/ITensors/5CAqA/src/physics/autompo/opsum_to_mpo_generic.jl:246
  [5] MPO
    @ ~/.julia/packages/ITensors/5CAqA/src/physics/autompo/opsum_to_mpo_generic.jl:239 [inlined]

Please let me know if you would like to see code for the full Hamiltonian. Thanks again for everything! I really appreciate it.

Good question – I think you’re running into a minor, but annoying, limitation of our QN system as it currently stands. We plan to lift this limtation in the future. The good news is that this limitation is easy to work around. (The limitation is that when using QNs all indices must have them, even ones which don’t conserve anything.)

As a workaround, please try the following code for making your sites array:

  sites = Vector{Index}(undef,Nsites)
  for n=1:Nsites
    if isodd(n)
      sites[n] = siteind("Electron"; addtags="n=$n",conserve_qns=true)
    else
      sites[n] = Index([QN() => phonon_dim],"Boson,Site,n=$n")
    end
  end

and please let me know if it works. If not we can keep tweaking it.

3 Likes

Thanks so much! Works like a charm

1 Like

Great! Yes it’s not such an obvious thing, but is easy enough to work around once you know the issue (by asking one of us).