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']))
There is also a 'printable' field containing a complete ready to print readable result
In [4]:
for line in result['printable']:
print(line)
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)
In [10]:
print('Actual VQE evaluations taken: {}'.format(result['algorithm_retvals']['eval_count']))
In [ ]: