quantumlib / OpenFermion

The electronic structure package for quantum computers.
Apache License 2.0
1.51k stars 372 forks source link

slight modification to function generate_hamiltonian ? #856

Open michaelkaicher opened 8 months ago

michaelkaicher commented 8 months ago

Hi,

when playing with some active space Hamiltonians with pyscf and generating them as FermionOperator objects (or rather InteractionOperator objects), I found that the resulting Hamiltonian included a lot of unnecessary terms: namely, operators such as

h_{kklm} a_k^dag a_k^dag a_l a_m,

where h_{kklm} was different than zero and the operator thus included (but the operator a_k^dag a_k^dag a_l am is zero, so one should just set h{kklm} to zero right away (k,l,m are here spinorbital indices).

Maybe this problem could be solved by just adding: if not (p==q or r==s): before # Same spin two_body_coefficients[2 * p, 2 * q, 2 * r, 2 * s] = (two_body_integrals[p, q, r, s] / 2.) two_body_coefficients[2 * p + 1, 2 * q + 1, 2 * r + 1, 2 * s + 1] = (two_body_integrals[p, q, r, s] / 2.) in line 272 of https://github.com/quantumlib/OpenFermion/blob/v1.6.0/src/openfermion/hamiltonians/hartree_fock.py#L245-L291

Would this cause any problems?

Cheers, Michael.