The latest version of this notebook is available on https://github.com/Qiskit/qiskit-tutorial.
Richard Chen[1], Antonio Mezzacapo[1], Marco Pistoia[1], Stephen Wood[1]
This notebook demonstrates how to use Qiskit Aqua Chemistry to compute the ground state energy of a Hydrogen (H2) molecule using VQE and UCCSD.
This notebook has been written to use the HDF5 chemistry driver. This driver uses molecular data that has been saved from a prior computation so that this notebook can be run with no additional driver installation requirements. See the HDF5 chemistry driver readme for more detail.
First we import AquaChemistry, which is the object that will carry out the computation for us
In [1]:
from qiskit_aqua_chemistry import AquaChemistry
Next, we create a Python dictionary to specify the problem we want to solve. There are defaults for many additional values that are not show here for simpicity. Indeed we take advantage of using sensisble defaults that the qischem stack provides to help us here. Please notice that the Qiskit Aqua Chemistry GUI allows for automatic extraction of the Python dictionary reflecting the current configuration. Once the Python dictionary has been extracted, it can be pasted into a Python program or a Jupyter Notebook and, if necessary, edited.
The first entry names a chemistry driver. This example uses HDF5 and the next line configures the driver for an hdf5 file that contains data from a prior computation for an H2 molecule with basis set sto-3g. The operator line would default but I have added it here to show it and to say that this is where the problem is converted into a quantum qubit form. We then have a VQE algorithm, using the COBYLA optimizer with a UCCSD variatonal form and initial state of HartreeFock. VQE is Variational Quantum Eigensolver and as its name suggests uses a variational method to find the mimimum eigenvalue of the problem, which in this case is the ground state energy of the molecule.
In [2]:
from qiskit import IBMQ
IBMQ.load_accounts()
In [3]:
# Input dictionary to configure Qiskit AQUA Chemistry for the chemistry problem.
aqua_chemistry_dict = {
'driver': {'name': 'HDF5'},
'HDF5': {'hdf5_input': 'H2/0.7_sto-3g.hdf5'},
'operator': {'name': 'hamiltonian'},
'algorithm': {'name': 'VQE'},
'optimizer': {'name': 'COBYLA'},
'variational_form': {'name': 'UCCSD'},
'initial_state': {'name': 'HartreeFock'},
'backend': {'name': 'statevector_simulator'}
}
We can now create a AquaChemistry object and call run on it passing in the problem dictionary to get a result. This may take a short time and it will use a local quantum simulator to carry out the quantum computation that the VQE algorithm uses.
In [4]:
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. We can print it.
In [5]:
print('Ground state energy: {}'.format(result['energy']))
There is also a 'printable' field containing a complete ready to print readable result
In [6]:
for line in result['printable']:
print(line)
This was a very simple example showing how to get started. There are more elaborate notebooks here as well documentation describing the various components and their configurations to help you to experiment with quantum computing and its application to solving chemistry problems.