JuliaAtoms / EnergyExpressions.jl

Other
1 stars 1 forks source link

Creating NBodyMatrixElements for zero-body operators fails #8

Open jagot opened 5 years ago

jagot commented 5 years ago

Trying to create an NBodyMatrixElement of a zero-body operator fails with the following error:

julia> using EnergyExpressions

julia> import EnergyExpressions: NBodyMatrixElement

julia> a=SlaterDeterminant([:a,:b])
a(1)b(2) - a(2)b(1)

julia> NBodyMatrixElement(a, IdentityOperator{0}(), a, overlap_matrix(a,a))
ERROR: UndefVarError: A not defined
Stacktrace:
 [1] EnergyExpressions.OrbitalMatrixElement(::Tuple{}, ::IdentityOperator{0}, ::Tuple{}) at /home/jagot/.julia/dev/EnergyExpressions/src/nbody_matrix_elements.jl:85
 [2] NBodyMatrixElement(::SlaterDeterminant{Symbol}, ::IdentityOperator{0}, ::SlaterDeterminant{Symbol}, ::SparseArrays.SparseMatrixCSC{EnergyExpressions.NBodyTerm,Int64}) at /home/jagot/.julia/dev/EnergyExpressions/src/nbody_matrix_elements.jl:442
 [3] top-level scope at none:0
 [4] run_backend(::REPL.REPLBackend) at /home/jagot/.julia/packages/Revise/gStbk/src/Revise.jl:771
 [5] (::getfield(Revise, Symbol("##58#60")){REPL.REPLBackend})() at ./task.jl:259

This is because the type cannot be inferred for the tuples of zero length. However, the OrbitalMatrixElement should not be necessary for zero-body operators, since the full energy expression consists solely of OrbitalOverlaps.

jagot commented 5 years ago

The same example above, now produces this non-sensical result:

julia> NBodyMatrixElement(a, IdentityOperator{0}(), a, overlap_matrix(a,a))
⟨𝐈₀⟩

julia> dump(NBodyMatrixElement(a, IdentityOperator{0}(), a, overlap_matrix(a,a)))
NBodyMatrixElement
  terms: Array{EnergyExpressions.NBodyTerm}((1,))
    1: EnergyExpressions.NBodyTerm
      factors: Array{EnergyExpressions.NBodyTermFactor}((1,))
        1: EnergyExpressions.OrbitalMatrixElement{0,Symbol,IdentityOperator{0},Symbol}
          a: Array{Symbol}((0,))
          o: IdentityOperator{0} 𝐈₀
          b: Array{Symbol}((0,))
      coeff: Int64 1