Skip to content
This repository was archived by the owner on Aug 21, 2023. It is now read-only.

Commit 3fbc959

Browse files
adjust sections in chemistry (#1037)
Co-authored-by: Paul Nation <nonhermitian@gmail.com>
1 parent 36493e3 commit 3fbc959

File tree

1 file changed

+61
-22
lines changed

1 file changed

+61
-22
lines changed

tutorials/chemistry/1_programmatic_approach.ipynb

Lines changed: 61 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -4,22 +4,18 @@
44
"cell_type": "markdown",
55
"metadata": {},
66
"source": [
7-
"# _*Qiskit Chemistry, Programmatic Approach*_ \n",
8-
"\n",
9-
"The latest version of this notebook is available on https://github.com/Qiskit/qiskit-tutorial.\n",
10-
"\n",
11-
"***\n",
12-
"## Contributors\n",
13-
"Richard Chen<sup>[1]</sup>, Antonio Mezzacapo<sup>[1]</sup>, Marco Pistoia<sup>[1]</sup>, Stephen Wood<sup>[1]</sup>\n",
14-
"### Affiliation\n",
15-
"- <sup>[1]</sup>IBMQ"
7+
"# _*Qiskit Chemistry, Programmatic Approach*_ \n"
168
]
179
},
1810
{
1911
"cell_type": "markdown",
20-
"metadata": {},
12+
"metadata": {
13+
"pycharm": {
14+
"name": "#%% md\n"
15+
}
16+
},
2117
"source": [
22-
"### Introduction\n",
18+
"## Introduction\n",
2319
"This notebook illustrates how to use Qiskit Chemistry's programmatic APIs.\n",
2420
"\n",
2521
"In this notebook, we decompose the computation of the ground state energy of a molecule into 4 steps:\n",
@@ -36,6 +32,9 @@
3632
"ExecuteTime": {
3733
"end_time": "2020-07-13T23:48:30.973884Z",
3834
"start_time": "2020-07-13T23:48:27.368639Z"
35+
},
36+
"pycharm": {
37+
"name": "#%%\n"
3938
}
4039
},
4140
"outputs": [],
@@ -60,9 +59,13 @@
6059
},
6160
{
6261
"cell_type": "markdown",
63-
"metadata": {},
62+
"metadata": {
63+
"pycharm": {
64+
"name": "#%% md\n"
65+
}
66+
},
6467
"source": [
65-
"### Step 1: Define a molecule\n",
68+
"## Step 1: Define a molecule\n",
6669
"Here, we use LiH in the sto3g basis with the PySCF driver as an example.\n",
6770
"The `molecule` object records the information from the PySCF driver."
6871
]
@@ -74,6 +77,9 @@
7477
"ExecuteTime": {
7578
"end_time": "2020-07-13T23:48:31.129792Z",
7679
"start_time": "2020-07-13T23:48:30.975723Z"
80+
},
81+
"pycharm": {
82+
"name": "#%%\n"
7783
}
7884
},
7985
"outputs": [],
@@ -87,9 +93,13 @@
8793
},
8894
{
8995
"cell_type": "markdown",
90-
"metadata": {},
96+
"metadata": {
97+
"pycharm": {
98+
"name": "#%% md\n"
99+
}
100+
},
91101
"source": [
92-
"### Step 2: Prepare qubit Hamiltonian\n",
102+
"## Step 2: Prepare qubit Hamiltonian\n",
93103
"Here, we setup the **to-be-frozen** and **to-be-removed** orbitals to reduce the problem size when we map to the qubit Hamiltonian. Furthermore, we define the **mapping type** for the qubit Hamiltonian.\n",
94104
"For the particular `parity` mapping, we can further reduce the problem size."
95105
]
@@ -138,6 +148,9 @@
138148
"ExecuteTime": {
139149
"end_time": "2020-07-13T23:48:31.599325Z",
140150
"start_time": "2020-07-13T23:48:31.163492Z"
151+
},
152+
"pycharm": {
153+
"name": "#%%\n"
141154
}
142155
},
143156
"outputs": [
@@ -284,7 +297,11 @@
284297
},
285298
{
286299
"cell_type": "markdown",
287-
"metadata": {},
300+
"metadata": {
301+
"pycharm": {
302+
"name": "#%% md\n"
303+
}
304+
},
288305
"source": [
289306
"We use the classical eigen decomposition to get the smallest eigenvalue as a reference."
290307
]
@@ -296,6 +313,9 @@
296313
"ExecuteTime": {
297314
"end_time": "2020-07-13T23:48:31.684136Z",
298315
"start_time": "2020-07-13T23:48:31.601391Z"
316+
},
317+
"pycharm": {
318+
"name": "#%%\n"
299319
}
300320
},
301321
"outputs": [
@@ -320,7 +340,7 @@
320340
"cell_type": "markdown",
321341
"metadata": {},
322342
"source": [
323-
"### Step 3: Initiate and configure dynamically-loaded instances\n",
343+
"## Step 3: Initiate and configure dynamically-loaded instances\n",
324344
"To run VQE with the UCCSD variational form, we require: \n",
325345
"\n",
326346
"- VQE algorithm\n",
@@ -331,9 +351,13 @@
331351
},
332352
{
333353
"cell_type": "markdown",
334-
"metadata": {},
354+
"metadata": {
355+
"pycharm": {
356+
"name": "#%% md\n"
357+
}
358+
},
335359
"source": [
336-
"### [Optional] Setup token to run the experiment on a real device\n",
360+
"## [Optional] Setup token to run the experiment on a real device\n",
337361
"If you would like to run the experiment on a real device, you need to setup your account first.\n",
338362
"\n",
339363
"Note: If you did not store your token yet, use `IBMQ.save_account('MY_API_TOKEN')` to store it first."
@@ -376,7 +400,10 @@
376400
"end_time": "2020-07-13T23:48:31.837107Z",
377401
"start_time": "2020-07-13T23:48:31.696698Z"
378402
},
379-
"scrolled": true
403+
"scrolled": true,
404+
"pycharm": {
405+
"name": "#%%\n"
406+
}
380407
},
381408
"outputs": [],
382409
"source": [
@@ -399,11 +426,23 @@
399426
"quantum_instance = QuantumInstance(backend=backend)"
400427
]
401428
},
429+
{
430+
"cell_type": "markdown",
431+
"source": [
432+
"## Step 4: Run algorithm and retrieve the results"
433+
],
434+
"metadata": {
435+
"collapsed": false
436+
}
437+
},
402438
{
403439
"cell_type": "markdown",
404440
"metadata": {},
405441
"source": [
406-
"### Step 4: Run algorithm and retrieve the results"
442+
"results = vqe.run(quantum_instance)\n",
443+
"print('The computed ground state energy is: {:.12f}'.format(results.eigenvalue.real))\n",
444+
"print('The total ground state energy is: {:.12f}'.format(results.eigenvalue.real + energy_shift + nuclear_repulsion_energy))\n",
445+
"print(\"Parameters: {}\".format(results.optimal_point))"
407446
]
408447
},
409448
{
@@ -533,4 +572,4 @@
533572
},
534573
"nbformat": 4,
535574
"nbformat_minor": 2
536-
}
575+
}

0 commit comments

Comments
 (0)