|
6 | 6 | "source": [
|
7 | 7 | "## _*H2 ground state energy computation using Quantum Phase Estimation*_\n",
|
8 | 8 | "\n",
|
9 |
| - "This notebook demonstrates using Qiskit Chemistry to compute ground state energy of the Hydrogen (H2) molecule using QPE (Quantum Phase Estimation) algorithm. Let's first look at how to carry out such computation programmatically. Afterwards, we will illustrate how the computation can also be carried out using json configuration dictionaries.\n", |
| 9 | + "This notebook demonstrates using Qiskit Chemistry to compute ground state energy of the Hydrogen (H2) molecule using QPE (Quantum Phase Estimation) algorithm. Let's look at how to carry out such computation programmatically.\n", |
10 | 10 | "\n",
|
11 | 11 | "This notebook has been written to use the PYSCF chemistry driver."
|
12 | 12 | ]
|
|
22 | 22 | "cell_type": "code",
|
23 | 23 | "execution_count": 1,
|
24 | 24 | "metadata": {},
|
25 |
| - "outputs": [], |
| 25 | + "outputs": [ |
| 26 | + { |
| 27 | + "name": "stdout", |
| 28 | + "output_type": "stream", |
| 29 | + "text": [ |
| 30 | + "Couldn't find cython int routine\n", |
| 31 | + "Couldn't find cython int routine\n" |
| 32 | + ] |
| 33 | + } |
| 34 | + ], |
26 | 35 | "source": [
|
27 | 36 | "from collections import OrderedDict\n",
|
28 | 37 | "import time\n",
|
|
37 | 46 | "from qiskit.aqua.algorithms import QPE\n",
|
38 | 47 | "from qiskit.aqua.components.iqfts import Standard\n",
|
39 | 48 | "from qiskit.chemistry import FermionicOperator\n",
|
40 |
| - "from qiskit.chemistry import QiskitChemistry\n", |
41 | 49 | "from qiskit.chemistry.components.initial_states import HartreeFock\n",
|
42 | 50 | "from qiskit.chemistry.drivers import PySCFDriver, UnitsType\n",
|
43 | 51 | "\n",
|
|
67 | 75 | "name": "stdout",
|
68 | 76 | "output_type": "stream",
|
69 | 77 | "text": [
|
70 |
| - "The exact ground state energy is: -1.8572750302023802\n" |
| 78 | + "The exact ground state energy is: -1.857275030202377\n" |
71 | 79 | ]
|
72 | 80 | }
|
73 | 81 | ],
|
|
94 | 102 | "name": "stdout",
|
95 | 103 | "output_type": "stream",
|
96 | 104 | "text": [
|
97 |
| - "The ground state energy as computed by QPE is: -1.8571368753258861\n" |
| 105 | + "The ground state energy as computed by QPE is: -1.8571368753258857\n" |
98 | 106 | ]
|
99 | 107 | }
|
100 | 108 | ],
|
|
123 | 131 | "cell_type": "markdown",
|
124 | 132 | "metadata": {},
|
125 | 133 | "source": [
|
126 |
| - "As can be easily seen, the QPE computed energy is quite close to the groundtruth value we computed earlier.\n", |
127 |
| - "\n", |
128 |
| - "Next we demonstrate how the same computation can be carried out using json dictionaries to drive the qiskit.chemistry stack. Such a dictionary can of course also be manipulated programmatically. An sibling notebook `h2_iqpe` is also provided, which showcases how the ground state energies over a range of inter-atomic distances can be computed and then plotted as well." |
129 |
| - ] |
130 |
| - }, |
131 |
| - { |
132 |
| - "cell_type": "code", |
133 |
| - "execution_count": 4, |
134 |
| - "metadata": {}, |
135 |
| - "outputs": [], |
136 |
| - "source": [ |
137 |
| - "molecule = 'H .0 .0 0; H .0 .0 {}'.format(distance)\n", |
138 |
| - "\n", |
139 |
| - "# Input dictionary to configure Qiskit Chemistry for the chemistry problem.\n", |
140 |
| - "qiskit_chemistry_qpe_dict = {\n", |
141 |
| - " 'driver': {'name': 'PYSCF'},\n", |
142 |
| - " 'PYSCF': {\n", |
143 |
| - " 'atom': molecule, \n", |
144 |
| - " 'basis': 'sto3g'\n", |
145 |
| - " },\n", |
146 |
| - " 'operator': {'name': 'hamiltonian', 'transformation': 'full', 'qubit_mapping': 'parity'},\n", |
147 |
| - " 'algorithm': {\n", |
148 |
| - " 'name': 'QPE',\n", |
149 |
| - " 'num_ancillae': 9,\n", |
150 |
| - " 'num_time_slices': 1,\n", |
151 |
| - " 'expansion_mode': 'suzuki',\n", |
152 |
| - " 'expansion_order': 2,\n", |
153 |
| - " },\n", |
154 |
| - " 'initial_state': {'name': 'HartreeFock'},\n", |
155 |
| - " 'backend': {'shots': 100}\n", |
156 |
| - "}\n", |
157 |
| - "\n", |
158 |
| - "qiskit_chemistry_ees_dict = {\n", |
159 |
| - " 'driver': {'name': 'PYSCF'},\n", |
160 |
| - " 'PYSCF': {'atom': molecule, 'basis': 'sto3g'},\n", |
161 |
| - " 'operator': {'name': 'hamiltonian', 'transformation': 'full', 'qubit_mapping': 'parity'},\n", |
162 |
| - " 'algorithm': {\n", |
163 |
| - " 'name': 'ExactEigensolver',\n", |
164 |
| - " }\n", |
165 |
| - "}" |
166 |
| - ] |
167 |
| - }, |
168 |
| - { |
169 |
| - "cell_type": "markdown", |
170 |
| - "metadata": {}, |
171 |
| - "source": [ |
172 |
| - "With the two algorithms configured, we can then run them and check the results, as follows." |
| 134 | + "As can be easily seen, the QPE computed energy is quite close to the groundtruth value we computed earlier." |
173 | 135 | ]
|
174 |
| - }, |
175 |
| - { |
176 |
| - "cell_type": "code", |
177 |
| - "execution_count": 5, |
178 |
| - "metadata": {}, |
179 |
| - "outputs": [ |
180 |
| - { |
181 |
| - "name": "stdout", |
182 |
| - "output_type": "stream", |
183 |
| - "text": [ |
184 |
| - "The groundtruth total ground state energy is -1.8572750302023793.\n", |
185 |
| - "The total ground state energy as computed by QPE is -1.8571368753258861.\n", |
186 |
| - "In comparison, the Hartree-Fock ground state energy is -1.8369679912029846.\n" |
187 |
| - ] |
188 |
| - } |
189 |
| - ], |
190 |
| - "source": [ |
191 |
| - "result_qpe = QiskitChemistry().run(qiskit_chemistry_qpe_dict, backend=backend)\n", |
192 |
| - "result_ees = QiskitChemistry().run(qiskit_chemistry_ees_dict)\n", |
193 |
| - "\n", |
194 |
| - "print('The groundtruth total ground state energy is {}.'.format(\n", |
195 |
| - " result_ees['energy'] - result_ees['nuclear_repulsion_energy']\n", |
196 |
| - "))\n", |
197 |
| - "print('The total ground state energy as computed by QPE is {}.'.format(\n", |
198 |
| - " result_qpe['energy'] - result_qpe['nuclear_repulsion_energy']\n", |
199 |
| - "))\n", |
200 |
| - "print('In comparison, the Hartree-Fock ground state energy is {}.'.format(\n", |
201 |
| - " result_ees['hf_energy'] - result_ees['nuclear_repulsion_energy']\n", |
202 |
| - "))" |
203 |
| - ] |
204 |
| - }, |
205 |
| - { |
206 |
| - "cell_type": "code", |
207 |
| - "execution_count": null, |
208 |
| - "metadata": {}, |
209 |
| - "outputs": [], |
210 |
| - "source": [] |
211 | 136 | }
|
212 | 137 | ],
|
213 | 138 | "metadata": {
|
|
226 | 151 | "name": "python",
|
227 | 152 | "nbconvert_exporter": "python",
|
228 | 153 | "pygments_lexer": "ipython3",
|
229 |
| - "version": "3.6.8" |
| 154 | + "version": "3.7.4" |
230 | 155 | }
|
231 | 156 | },
|
232 | 157 | "nbformat": 4,
|
|
0 commit comments