quantumlib / OpenFermion

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

occupied_indices and active_indices in function get_molecular_hamiltonian #508

Open sunqm opened 5 years ago

sunqm commented 5 years ago

https://github.com/quantumlib/OpenFermion/blob/6fb280c9d223522ed5ce5e90f5cd809beda7f177/src/openfermion/hamiltonians/_molecular_data.py#L790

May be helpful to check consistency between the active indices and occupied indices. Something like:

if active_indices and not occupied_indices:
    raise RuntimeError("Forget to specify core orbitals?")

It's easy to make mistakes if one does not familiar with quantum chemistry. For example, the curve scanning below produces a wrong results, which is so close to the correct values that almost no way to realize the problem

import numpy as np
from openfermion.hamiltonians import MolecularData
from openfermion.transforms import get_fermion_operator, jordan_wigner
from pyscf import mp,ci,cc,fci
from openfermionpyscf import run_pyscf
from openfermion.transforms import get_sparse_operator
for r in np.arange(0.7, 1.8, .1):
    geometry = [['H', [0, 0, 0]], ['Li', [r, 0, 0]]]
    lih = run_pyscf(MolecularData(geometry, basis='sto3g', multiplicity=1, charge=0))
    h_jw = jordan_wigner(get_fermion_operator(lih.get_molecular_hamiltonian(active_indices=[0,1])))
    E = np.linalg.eigvalsh(get_sparse_operator(h_jw).todense())[0]
    print(E.real)

# -7.4859448705472795
# -7.615770161232098
# -7.7057533401361145
# -7.767362135748563
# -7.80874317649341
# -7.83561582555692
# -7.851953857956232
# -7.860538661020689
# -7.863357621535113
# -7.861864769808646
# -7.85714496020382

# reference curve
from pyscf import gto, scf, mcscf
mol = gto.M(atom='Li 0 0 0; H 0 0 .5', verbose=0, basis='sto3g')
mc = mcscf.CASCI(scf.RHF(mol), 2, 2)
mcs = mc.as_scanner() 
for r in np.arange(.7, 1.8, .1):
    print(mcs('Li, 0 0 0; H 0 0 %f'%r))

# -7.486115229508926
# -7.61591576244245
# -7.705888919644435
# -7.767496700973462
# -7.808883178076792
# -7.835766806920713
# -7.8521214918651925
# -7.860729506568592
# -7.863579821659645
# -7.862128833331029
# -7.857464750551729
lcr1103 commented 5 years ago

I am not familiar with quantum chemistry so apart from the energy, in the Hamiltonian what does every qubti stand for? and how to decide the occupied_indices and active_indices?

babbush commented 5 years ago

@lcr1103 we've responded to your question in the issue you opened (#508) in the main OpenFermion repo.