quantumlib / OpenFermion-PySCF

OpenFermion plugin to interface with the electronic structure package PySCF.
Apache License 2.0
105 stars 44 forks source link

RDM calculation not stored correctly in MolecularData #49

Closed rugantio closed 5 years ago

rugantio commented 5 years ago

Hello, I ran a simple test with the H2 molecule at bond distance, this is what I get from the OpenFermion hdf5:

import os
from openfermion.hamiltonians import MolecularData

THIS_DIRECTORY = '.'
filename = os.path.join(THIS_DIRECTORY, 'src','openfermion','data','H2_sto-3g_singlet_0.7414')
molecule = MolecularData([('H', (0,0,0)),('H', (0,0,0.7414))],'sto-3g', 1, filename=filename)
molecule.load()

# FCI RDM
fci_rdm = molecule.get_molecular_rdm(use_fci=True)

print(fci_rdm)

the output is:

((0, 1), (0, 0)) 0.9872699847206565
((1, 1), (1, 0)) 0.9872699847206565
((2, 1), (2, 0)) 0.012730015279343554
((3, 1), (3, 0)) 0.012730015279343554
((0, 1), (1, 1), (0, 0), (1, 0)) -0.9872699847206565
((0, 1), (1, 1), (1, 0), (0, 0)) 0.9872699847206565
((0, 1), (1, 1), (2, 0), (3, 0)) 0.11210692213387734
((0, 1), (1, 1), (3, 0), (2, 0)) -0.11210692213387734
((1, 1), (0, 1), (0, 0), (1, 0)) 0.9872699847206565
((1, 1), (0, 1), (1, 0), (0, 0)) -0.9872699847206565
((1, 1), (0, 1), (2, 0), (3, 0)) -0.11210692213387734
((1, 1), (0, 1), (3, 0), (2, 0)) 0.11210692213387734
((2, 1), (3, 1), (0, 0), (1, 0)) 0.11210692213387734
((2, 1), (3, 1), (1, 0), (0, 0)) -0.11210692213387734
((2, 1), (3, 1), (2, 0), (3, 0)) -0.012730015279343554
((2, 1), (3, 1), (3, 0), (2, 0)) 0.012730015279343554
((3, 1), (2, 1), (0, 0), (1, 0)) -0.11210692213387734
((3, 1), (2, 1), (1, 0), (0, 0)) 0.11210692213387734
((3, 1), (2, 1), (2, 0), (3, 0)) 0.012730015279343554
((3, 1), (2, 1), (3, 0), (2, 0)) -0.012730015279343554

Instead form OpenFermion-PySCF, using the method run_pyscf:

from openfermion.hamiltonians import MolecularData
from openfermionpyscf import run_pyscf

molecule = MolecularData([('H', (0,0,0)),('H', (0,0,0.7414))],'sto-3g', 1)
molecule = run_pyscf(molecule,
                     run_scf=1,
                     run_fci=1)

# FCI RDM
fci_rdm = molecule.get_molecular_rdm(use_fci=True)

print(fci_rdm)

the output is:

((0, 1), (0, 0)) 1.9745399697399248
((1, 1), (1, 0)) 0.025460030260075338
((0, 1), (0, 1), (0, 0), (0, 0)) 1.9745399697399248
((0, 1), (0, 1), (1, 0), (1, 0)) -0.22421384296984592
((1, 1), (1, 1), (0, 0), (0, 0)) -0.22421384296984592
((1, 1), (1, 1), (1, 0), (1, 0)) 0.025460030260075338

The tests have been run with both packages updated to the latest git commit.

babbush commented 5 years ago

Interesting bug, we'll look into this. The RDM you are getting in the first case includes the spin degree of freedom, whereas the RDM in the second case does not.

rugantio commented 5 years ago

This issue is being addressed inside OpenFermion, here: https://github.com/quantumlib/OpenFermion/pull/535