BeH2 plots of various orbital reduction results

This notebook demonstrates using the Qiskit Aqua Chemistry to plot graphs of the ground state energy of the Beryllium Dihydride (BeH2) molecule over a range of inter-atomic distances using ExactEigensolver. Freeze core reduction is true and different virtual orbital removals are tried as a comparison.

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 and this is indeed the case here where we alter the molecule supplied to the driver in each loop as well as the orbital reductions.

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]:
import numpy as np
import pylab
from qiskit_aqua_chemistry import AquaChemistry

# Input dictionary to configure Qiskit Aqua Chemistry for the chemistry problem.
aqua_chemistry_dict = {
    'driver': {'name': 'PYSCF'},
    'PYSCF': {'atom': '', 'basis': 'sto3g'},
    'operator': {'name': 'hamiltonian', 'qubit_mapping': 'parity',
                 'two_qubit_reduction': True, 'freeze_core': True, 'orbital_reduction': []},
    'algorithm': {'name': 'ExactEigensolver'}
}
molecule = 'H .0 .0 -{0}; Be .0 .0 .0; H .0 .0 {0}'
reductions = [[], [-2, -1], [-3, -2], [-4, -3], [-1], [-2], [-3], [-4]]

pts  = [x * 0.1  for x in range(6, 20)]
pts += [x * 0.25 for x in range(8, 16)]
pts += [4.0]
energies = np.empty([len(reductions), len(pts)])
distances = np.empty(len(pts))

print('Processing step __', end='')
for i, d in enumerate(pts):
    print('\b\b{:2d}'.format(i), end='', flush=True)
    aqua_chemistry_dict['PYSCF']['atom'] = molecule.format(d) 
    for j in range(len(reductions)):
        aqua_chemistry_dict['operator']['orbital_reduction'] = reductions[j] 
        solver = AquaChemistry()
        result = solver.run(aqua_chemistry_dict)
        energies[j][i] = result['energy']
    distances[i] = d
print(' --- complete')

print('Distances: ', distances)
print('Energies:', energies)


Processing step 22 --- complete
Distances:  [0.6  0.7  0.8  0.9  1.   1.1  1.2  1.3  1.4  1.5  1.6  1.7  1.8  1.9
 2.   2.25 2.5  2.75 3.   3.25 3.5  3.75 4.  ]
Energies: [[-14.40506494 -14.87097555 -15.17246656 -15.36382343 -15.48142306
  -15.54931874 -15.58348421 -15.59471016 -15.59040023 -15.57570561
  -15.55427855 -15.52877867 -15.50120585 -15.47311573 -15.44576103
  -15.38711226 -15.35149108 -15.33892161 -15.33645938 -15.33627749
  -15.3363915  -15.33646725 -15.33649467]
 [-14.38537971 -14.8529641  -15.15532997 -15.34648965 -15.46287098
  -15.52863269 -15.5598192  -15.56723345 -15.55823699 -15.53789746
  -15.50975433 -15.476334   -15.43948849 -15.40061366 -15.38534487
  -15.30406975 -15.24876708 -15.23982192 -15.25303723 -15.27323362
  -15.2904802  -15.29973676 -15.30358774]
 [-14.38085785 -14.8496625  -15.152928   -15.34484824 -15.46196656
  -15.52847583 -15.56042602 -15.5686254  -15.5604457  -15.54096661
  -15.51373779 -15.48129162 -15.44548034 -15.4076929  -15.43902234
  -15.3765858  -15.33291996 -15.31217227 -15.30666589 -15.30583829
  -15.30584735 -15.3059168  -15.30595   ]
 [-14.38996835 -14.8596731  -15.16341905 -15.35613956 -15.47463297
  -15.54315397 -15.57776757 -15.5893081  -15.58520037 -15.57060331
  -15.54916622 -15.52353471 -15.49568133 -15.46711643 -15.36899435
  -15.27329325 -15.18543733 -15.10983622 -15.04887848 -15.00693603
  -14.98538738 -14.97555545 -14.97045281]
 [-14.39432437 -14.86110116 -15.16286759 -15.3537537  -15.47017403
  -15.53627247 -15.56808784 -15.57642757 -15.5686708  -15.54991949
  -15.52376812 -15.49282421 -15.45905583 -15.42402529 -15.38905694
  -15.31000383 -15.2593924  -15.25594154 -15.26939038 -15.28973515
  -15.30706594 -15.31636055 -15.32022639]
 [-14.38815095 -14.85518765 -15.15741167 -15.34871007 -15.46542593
  -15.53165667 -15.56340888 -15.57146946 -15.5631985  -15.54366894
  -15.51642669 -15.48400243 -15.44824819 -15.41055403 -15.44242866
  -15.38184785 -15.34232036 -15.32636956 -15.32282134 -15.32241852
  -15.32249786 -15.32257244 -15.32260238]
 [-14.39782704 -14.8655071  -15.16806701 -15.36007661 -15.47810675
  -15.54630491 -15.58068771 -15.59206637 -15.58785438 -15.57320634
  -15.55177264 -15.52620548 -15.49849044 -15.47015952 -15.44242866
  -15.38184785 -15.34232036 -15.32636956 -15.32282134 -15.32241852
  -15.32249786 -15.32257244 -15.32260238]
 [-14.39782704 -14.8655071  -15.16806701 -15.36007661 -15.47810675
  -15.54630491 -15.58068771 -15.59206637 -15.58785438 -15.57320634
  -15.55177264 -15.52620548 -15.49849044 -15.47015952 -15.37198719
  -15.27680792 -15.18982171 -15.11557267 -15.0565821  -15.01697352
  -14.99729007 -14.98854807 -14.98398255]]

In [2]:
pylab.rcParams['figure.figsize'] = (12, 8)
for j in range(len(reductions)):
    pylab.plot(distances, energies[j], label=reductions[j])
pylab.xlabel('Interatomic distance')
pylab.ylabel('Energy')
pylab.title('BeH2 Ground State Energy')
pylab.legend(loc='upper right')


Out[2]:
<matplotlib.legend.Legend at 0x113d2a2b0>

In [3]:
pylab.rcParams['figure.figsize'] = (12, 8)
for j in range(len(reductions)):
    pylab.plot(distances, np.subtract(energies[j], energies[0]), label=reductions[j])
pylab.xlabel('Interatomic distance')
pylab.ylabel('Energy')
pylab.title('Energy difference compared to no reduction []')
pylab.legend(loc='upper left')


Out[3]:
<matplotlib.legend.Legend at 0x10d8774e0>

In [4]:
pylab.rcParams['figure.figsize'] = (6, 4)
for j in range(1, len(reductions)):
    pylab.plot(distances, np.subtract(energies[j], energies[0]), color=[1.0, 0.6, 0.2], label=reductions[j])
    pylab.ylim(0, 0.4)
    pylab.xlabel('Interatomic distance')
    pylab.ylabel('Energy')
    pylab.title('Energy difference compared to no reduction []')
    pylab.legend(loc='upper left')
    pylab.show()



In [5]:
e_nofreeze = np.empty(len(pts))
aqua_chemistry_dict['operator']['orbital_reduction'] = [] 
aqua_chemistry_dict['operator']['freeze_core'] = False 
for i, d in enumerate(pts):
    print('\b\b{:2d}'.format(i), end='', flush=True)
    aqua_chemistry_dict['PYSCF']['atom'] = molecule.format(d) 
    solver = AquaChemistry()
    result = solver.run(aqua_chemistry_dict)
    e_nofreeze[i] = result['energy']

print(e_nofreeze)


22[-14.40564902 -14.87132975 -15.17280541 -15.36415094 -15.48174107
 -15.54963817 -15.58381205 -15.59504708 -15.59074335 -15.57605125
 -15.55462369 -15.52912134 -15.50154509 -15.47345142 -15.44609374
 -15.38744402 -15.35183431 -15.33927179 -15.33680424 -15.33661362
 -15.33672146 -15.33679474 -15.33682151]

In [6]:
pylab.rcParams['figure.figsize'] = (8, 6)
pylab.plot(distances, energies[0], label='Freeze Core: True')
pylab.plot(distances, e_nofreeze, label='Freeze Core: False')
pylab.xlabel('Interatomic distance')
pylab.ylabel('Energy')
pylab.title('Energy difference, no reduction [], freeze core true/false')
pylab.legend(loc='upper right')
pylab.show()
pylab.title('Energy difference of freeze core True from False')
pylab.plot(distances, np.subtract(energies[0], e_nofreeze), label='Freeze Core: False')
pylab.show()