ITensors.jl icon indicating copy to clipboard operation
ITensors.jl copied to clipboard

[ITensors] [BUG] Fermion two-body operators QN flux type "Nothing"

Open oskar-leimkuhler opened this issue 3 years ago • 1 comments

Description of bug

The issue comes from the inclusion of specific two-body terms in the fermionic Hamiltonian OpSum (of the form c^\dag_p c^\dag_q c_r c_s) where the indices p,q or r,s are identical. Removing them from the OpSum fixes the issue, but these operators should annihilate any quantum state due to the doubled-up creation or annihilation operators, so the Hamiltonian should still technically be QN conserving when they are left in. The problem is coming from line 203 in the file "opsum_to_mpo_qn.jl", where it appears that a subtraction is being performed between incompatible types "::QN" and "::Nothing".

Minimal code demonstrating the bug or unexpected behavior

Minimal runnable code

using ITensors

sites = siteinds("Fermion", 2, conserve_qns=true)

ampo = OpSum()
for p=1:2, q=1:2, r=1:2, s=1:2
    ampo += "c†",p,"c†",q,"c",r,"c",s
end

H = MPO(ampo, sites)

Expected output or behavior

Constructs the Hamiltonian MPO with no output.

Actual output or behavior

Output of minimal runnable code

MethodError: no method matching -(::QN, ::Nothing)
Closest candidates are:
  -(::ChainRulesCore.AbstractThunk, ::Any) at ~/.julia/packages/ChainRulesCore/ctmSK/src/tangent_types/thunks.jl:34
  -(::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 ~/.julia/packages/ITensors/OjQuG/src/LazyApply/LazyApply.jl:243
  -(::Prod{A}, ::A) where A at ~/.julia/packages/ITensors/OjQuG/src/LazyApply/LazyApply.jl:182
  ...

Stacktrace:
 [1] qn_svdMPO(os::Sum{Scaled{ComplexF64, Prod{Op}}}, sites::Vector{Index{Vector{Pair{QN, Int64}}}}; kwargs::Base.Pairs{Symbol, Union{}, Tuple{}, NamedTuple{(), Tuple{}}})
   @ ITensors ~/.julia/packages/ITensors/OjQuG/src/physics/autompo/opsum_to_mpo_qn.jl:203
 [2] qn_svdMPO
   @ ~/.julia/packages/ITensors/OjQuG/src/physics/autompo/opsum_to_mpo_qn.jl:2 [inlined]
 [3] MPO(os::Sum{Scaled{ComplexF64, Prod{Op}}}, sites::Vector{Index{Vector{Pair{QN, Int64}}}}; kwargs::Base.Pairs{Symbol, Union{}, Tuple{}, NamedTuple{(), Tuple{}}})
   @ ITensors ~/.julia/packages/ITensors/OjQuG/src/physics/autompo/opsum_to_mpo_generic.jl:224
 [4] MPO(os::Sum{Scaled{ComplexF64, Prod{Op}}}, sites::Vector{Index{Vector{Pair{QN, Int64}}}})
   @ ITensors ~/.julia/packages/ITensors/OjQuG/src/physics/autompo/opsum_to_mpo_generic.jl:217
 [5] top-level scope
   @ In[38]:10
 [6] eval
   @ ./boot.jl:373 [inlined]
 [7] include_string(mapexpr::typeof(REPL.softscope), mod::Module, code::String, filename::String)
   @ Base ./loading.jl:1196

Version information

  • Output from versioninfo():
julia> versioninfo()
Julia Version 1.7.3
Commit 742b9abb4d (2022-05-06 12:58 UTC)
Platform Info:
  OS: Linux (x86_64-pc-linux-gnu)
  CPU: 12th Gen Intel(R) Core(TM) i5-1235U
  WORD_SIZE: 64
  LIBM: libopenlibm
  LLVM: libLLVM-12.0.1 (ORCJIT, goldmont)
  • Output from using Pkg; Pkg.status("ITensors"):
julia> using Pkg; Pkg.status("ITensors")
      Status `~/.julia/environments/v1.7/Project.toml`
  [9136182c] ITensors v0.3.18

oskar-leimkuhler avatar Aug 10 '22 13:08 oskar-leimkuhler

Thanks for the report @oskar-leimkuhler! Should be a simple fix.

mtfishman avatar Aug 10 '22 18:08 mtfishman