Qiskit Aqua Chemistry, H2O ground state computation

This notebook demonstrates how to use Qiskit Aqua Chemistry to compute the ground state energy of a water (H2O) molecule using VQE and UCCSD.

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

# Input dictionary to configure Qiskit Aqua Chemistry for the chemistry problem.
aqua_chemistry_dict = {
    'problem': {'random_seed': 50},
    'driver': {'name': 'PYSCF'},
    'PYSCF': {'atom': 'O 0.0 0.0 0.0; H 0.757 0.586 0.0; H -0.757 0.586 0.0', 'basis': 'sto-3g'},
    'operator': {'name': 'hamiltonian', 'freeze_core': True},
    'algorithm': {'name': 'ExactEigensolver'}
}

With the above input problem dictionary for water we now create an AquaChemistry object and call run on it passing in the dictionary to get a result. We use ExactEigensolver first as a reference.


In [2]:
solver = AquaChemistry()
result = solver.run(aqua_chemistry_dict)

The run method returns a result dictionary. Some notable fields include 'energy' which is the computed ground state energy.


In [3]:
print('Ground state energy: {}'.format(result['energy']))


Ground state energy: -75.01235928580498

There is also a 'printable' field containing a complete ready to print readable result


In [4]:
for line in result['printable']:
    print(line)


* Electronic ground state energy: -84.20627244642836
  - computed part:      -23.544497240436005
  - frozen energy part: -60.661775205992356
  - particle hole part: 0.0
~ Nuclear repulsion energy: 9.193913160623385
> Total ground state energy: -75.01235928580498
  Measured:: Num particles: 8.000, S: 0.000, M: 0.00000
* Electronic dipole moment: [0.         1.57867263 0.        ]
  - computed part:      [0.         1.57778798 0.        ]
  - frozen energy part: [0.         0.00088465 0.        ]
  - particle hole part: [0. 0. 0.]
~ Nuclear dipole moment: [0.         2.21475902 0.        ]
> Dipole moment: [0.         0.63608639 0.        ]  Total: 0.6360863875724845

We update the dictionary, for VQE with UCCSD, and run the computation again.


In [5]:
aqua_chemistry_dict['algorithm']['name'] = 'VQE'
aqua_chemistry_dict['optimizer'] = {'name': 'COBYLA', 'maxiter': 25000}
aqua_chemistry_dict['variational_form'] = {'name': 'UCCSD'}
aqua_chemistry_dict['initial_state'] = {'name': 'HartreeFock'}

solver = AquaChemistry()
result = solver.run(aqua_chemistry_dict)

print('Ground state energy: {}'.format(result['energy']))

for line in result['printable']:
    print(line)


Ground state energy: -75.01136277625662
* Electronic ground state energy: -84.20527593688
  - computed part:      -23.543500730887647
  - frozen energy part: -60.661775205992356
  - particle hole part: 0.0
~ Nuclear repulsion energy: 9.193913160623385
> Total ground state energy: -75.01136277625662
  Measured:: Num particles: 8.000, S: 0.002, M: 0.00000
* Electronic dipole moment: [-3.30862414e-06  1.57868676e+00 -1.64045876e-05]
  - computed part:      [-3.30862414e-06  1.57780210e+00 -1.64045876e-05]
  - frozen energy part: [0.         0.00088465 0.        ]
  - particle hole part: [0. 0. 0.]
~ Nuclear dipole moment: [0.         2.21475902 0.        ]
> Dipole moment: [3.30862414e-06 6.36072265e-01 1.64045876e-05]  Total: 0.6360722651436584

In [10]:
print('Actual VQE evaluations taken: {}'.format(result['algorithm_retvals']['eval_count']))


Actual VQE evaluations taken: 2422

In [ ]: