H2 ground state energy computation using Quantum Phase Estimation

This notebook demonstrates using Qiskit Aqua Chemistry to compute ground state energy of the Hydrogen (H2) molecule using QPE (Quantum Phase Estimation) algorithm. It is compared to the same energy as computed by the ExactEigensolver

This notebook populates a dictionary, that is a progammatic representation of an input file, in order to drive the qiskit_aqua_chemistry stack. Such a dictionary can be manipulated programmatically. An sibling notebook h2_iqpe is also provided, which showcases how the ground state energies over a range of inter-atomic distances can be computed and then plotted as well.

This notebook has been written to use the PYSCF chemistry driver. See the PYSCF chemistry driver readme if you need to install the external PySCF library that this driver requires.


In [1]:
from qiskit_aqua_chemistry import AquaChemistry
import time

distance = 0.735
molecule = 'H .0 .0 0; H .0 .0 {}'.format(distance)

# Input dictionary to configure Qiskit Aqua Chemistry for the chemistry problem.
aqua_chemistry_qpe_dict = {
    'driver': {'name': 'PYSCF'},
    'PYSCF': {
        'atom': molecule, 
        'basis': 'sto3g'
    },
    'operator': {'name': 'hamiltonian', 'transformation': 'full', 'qubit_mapping': 'parity'},
    'algorithm': {
        'name': 'QPE',
        'num_ancillae': 9,
        'num_time_slices': 50,
        'expansion_mode': 'suzuki',
        'expansion_order': 2,
    },
    'initial_state': {'name': 'HartreeFock'},
    'backend': {
        'name': 'qasm_simulator',
        'shots': 100,
    }
}

aqua_chemistry_ees_dict = {
    'driver': {'name': 'PYSCF'},
    'PYSCF': {'atom': molecule, 'basis': 'sto3g'},
    'operator': {'name': 'hamiltonian', 'transformation': 'full', 'qubit_mapping': 'parity'},
    'algorithm': {
        'name': 'ExactEigensolver',
    },
}

With the two algorithms configured, we can then run them and check the results, as follows.


In [2]:
start_time = time.time()
result_qpe = AquaChemistry().run(aqua_chemistry_qpe_dict)
result_ees = AquaChemistry().run(aqua_chemistry_ees_dict)
print("--- computation completed in %s seconds ---" % (time.time() - start_time))


--- computation completed in 55.49299883842468 seconds ---

In [3]:
print('The groundtruth total ground state energy is           {}.'.format(
    result_ees['energy']
))
print('The total ground state energy as computed by QPE is    {}.'.format(
    result_qpe['energy']
))
print('In comparison, the Hartree-Fock ground state energy is {}.'.format(
    result_ees['hf_energy']
))


The groundtruth total ground state energy is           -1.137306035753399.
The total ground state energy as computed by QPE is    -1.1371678808769068.
In comparison, the Hartree-Fock ground state energy is -1.1169989967540044.