Skip to content
This repository was archived by the owner on Aug 21, 2023. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
71 changes: 43 additions & 28 deletions qiskit/aqua/chemistry/declarative_approach.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@
"cell_type": "markdown",
"metadata": {},
"source": [
"# _*Qiskit Aqua: Chemistry, writing in declarative approach*_ \n",
"# _*Qiskit Chemistry, Declarative Approach*_ \n",
"\n",
"The latest version of this notebook is available on https://github.com/Qiskit/qiskit-tutorial.\n",
"The latest version of this notebook is available at https://github.com/Qiskit/qiskit-tutorials.\n",
"\n",
"***\n",
"### Contributors\n",
Expand All @@ -22,17 +22,24 @@
"- <sup>[1]</sup>IBMQ"
]
},
{
"cell_type": "raw",
"metadata": {},
"source": []
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### Introduction\n",
"\n",
"This notebook demonstrates how to use Qiskit Aqua Chemistry to compute the ground state energy of a Hydrogen (H2) molecule using VQE and UCCSD.\n",
"This notebook demonstrates how to use Qiskit Chemistry to compute the ground state energy of molecular Hydrogen (H$_2$) using the Variational Quantum Eigensolver (VQE) algorithm and the Unitary Coupled Cluster Singles and Doubles (UCCSD) variational form. This notebook uses the so called *declarative approach*: a Python dictionary automatically generated via the Qiskit Chemistry GUI wizard summarizes the entire experiment declaratively. That dictionary is simply then passed as a paramter to the `run` method of the `AquaChemistry` solver to get the result of the experiment, also in the form of a Python dictionary.\n",
"\n",
"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.\n",
"Users who are more interested in learning the Qiskit Aqua and Qiskit Chemistry APIs and/or in contributing new algorithmic components can look at the same experiment executed [programmatically](https://github.com/Qiskit/qiskit-tutorials/blob/master/qiskit/aqua/chemistry/programmatic_approach.ipynb).\n",
"\n",
"First we import AquaChemistry, which is the object that will carry out the computation for us"
"This notebook has been written to use the HDF5 chemistry driver. This driver uses molecular data that has been serialized from a prior computation. This allows this notebook to be executed with no additional driver installation requirements. See the Qiskit Chemistry driver documentation for more detail.\n",
"\n",
"First, we import `QiskitChemistry`, which is the object that will carry out the computation for us"
]
},
{
Expand All @@ -41,17 +48,17 @@
"metadata": {},
"outputs": [],
"source": [
"from qiskit_aqua_chemistry import AquaChemistry\n",
"from qiskit_chemistry import QiskitChemistry\n",
"from qiskit import Aer"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"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.\n",
"Next, we create a Python dictionary to specify the problem we want to solve. There are defaults for many additional values that are not shown here for simpicity. Indeed, we take advantage of using sensisble defaults that the Qiskit Chemistry stack provides. As mentioned above, the Qiskit Chemistry GUI wizard 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.\n",
"\n",
"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."
"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 H$_2$ molecule with basis set `sto-3g`. The operator line would be automatically set by default, but we have added it here to show it and to emphasize where the problem input is converted into a quantum qubit form. We then indicate to the `QiskitChemistry` solver that the VQE algorithm should be used in this experiment, using the COBYLA optimizer with a UCCSD variatonal form and initial state of HartreeFock. VQE uses the variational method to find the mimimum eigenvalue of a problem, which in this case is the ground state energy of the molecule."
]
},
{
Expand All @@ -61,7 +68,7 @@
"### [Optional] Setup token to run the experiment on a real device\n",
"If you would like to run the experiement on a real device, you need to setup your account first.\n",
"\n",
"Note: If you do not store your token yet, use `IBMQ.save_accounts()` to store it first."
"Note: If you have not stored your token yet, use `IBMQ.save_accounts()` to store it first."
]
},
{
Expand All @@ -70,8 +77,8 @@
"metadata": {},
"outputs": [],
"source": [
"from qiskit import IBMQ\n",
"IBMQ.load_accounts()\n",
"# from qiskit import IBMQ\n",
"# IBMQ.load_accounts()\n",
"# backend = IBMQ.get_backend('ibmq_16_melbourne')"
]
},
Expand All @@ -81,6 +88,7 @@
"metadata": {},
"outputs": [],
"source": [
"from qiskit import Aer\n",
"backend = Aer.get_backend('statevector_simulator')"
]
},
Expand All @@ -94,7 +102,7 @@
"source": [
"# Input dictionary to configure Qiskit AQUA Chemistry for the chemistry problem.\n",
"\n",
"aqua_chemistry_dict = {\n",
"qiskit_chemistry_dict = {\n",
" 'driver': {'name': 'HDF5'},\n",
" 'HDF5': {'hdf5_input': 'H2/0.7_sto-3g.hdf5'},\n",
" 'operator': {'name': 'hamiltonian'},\n",
Expand All @@ -109,7 +117,7 @@
"cell_type": "markdown",
"metadata": {},
"source": [
"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."
"We can now create an `QiskitChemistry` 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."
]
},
{
Expand All @@ -118,15 +126,15 @@
"metadata": {},
"outputs": [],
"source": [
"solver = AquaChemistry()\n",
"result = solver.run(aqua_chemistry_dict, backend=backend)"
"solver = QiskitChemistry()\n",
"result = solver.run(qiskit_chemistry_dict, backend=backend)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"The run method returns a result dictionary. Some notable fields include 'energy' which is the computed ground state energy. We can print it."
"The `run` method returns a result dictionary. Some notable fields include `energy`, which is the computed ground state energy. We can print it."
]
},
{
Expand All @@ -138,7 +146,7 @@
"name": "stdout",
"output_type": "stream",
"text": [
"Ground state energy: -1.1361894321408132\n"
"Ground state energy: -1.1361894423809882\n"
]
}
],
Expand All @@ -150,7 +158,7 @@
"cell_type": "markdown",
"metadata": {},
"source": [
"There is also a 'printable' field containing a complete ready to print readable result"
"There is also a `printable` field containing a complete ready to print readable result."
]
},
{
Expand All @@ -164,23 +172,23 @@
"text": [
"=== GROUND STATE ENERGY ===\n",
" \n",
"* Electronic ground state energy (Hartree): -1.892156876312\n",
" - computed part: -1.892156876312\n",
"* Electronic ground state energy (Hartree): -1.892156886552\n",
" - computed part: -1.892156886552\n",
" - frozen energy part: 0.0\n",
" - particle hole part: 0.0\n",
"~ Nuclear repulsion energy (Hartree): 0.755967444171\n",
"> Total ground state energy (Hartree): -1.136189432141\n",
"> Total ground state energy (Hartree): -1.136189442381\n",
" Measured:: Num particles: 2.000, S: 0.000, M: 0.00000\n",
" \n",
"=== DIPOLE MOMENT ===\n",
" \n",
"* Electronic dipole moment (a.u.): [0.0 0.0 0.00029555]\n",
" - computed part: [0.0 0.0 0.00029555]\n",
"* Electronic dipole moment (a.u.): [0.0 0.0 -0.00006376]\n",
" - computed part: [0.0 0.0 -0.00006376]\n",
" - frozen energy part: [0.0 0.0 0.0]\n",
" - particle hole part: [0.0 0.0 0.0]\n",
"~ Nuclear dipole moment (a.u.): [0.0 0.0 0.0]\n",
"> Dipole moment (a.u.): [0.0 0.0 -0.00029555] Total: 0.00029555\n",
" (debye): [0.0 0.0 -0.00075122] Total: 0.00075122\n"
"> Dipole moment (a.u.): [0.0 0.0 0.00006376] Total: 0.00006376\n",
" (debye): [0.0 0.0 0.00016206] Total: 0.00016206\n"
]
}
],
Expand All @@ -195,13 +203,20 @@
"source": [
"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."
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
"kernelspec": {
"display_name": "Quantum py37",
"display_name": "Python 3",
"language": "python",
"name": "quantum-dev-37"
"name": "python3"
},
"language_info": {
"codemirror_mode": {
Expand All @@ -213,7 +228,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.7.1"
"version": "3.6.4"
}
},
"nbformat": 4,
Expand Down
Loading