Skip to content

Commit f320777

Browse files
author
Richard Chen
committed
update to aqua 0.6
1 parent 6ef6fce commit f320777

File tree

1 file changed

+37
-39
lines changed

1 file changed

+37
-39
lines changed

chemistry/LiH_with_qubit_tapering_and_uccsd.ipynb

Lines changed: 37 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,8 @@
2525
"\n",
2626
"from qiskit import BasicAer\n",
2727
"\n",
28-
"from qiskit.aqua import Operator, set_qiskit_aqua_logging, QuantumInstance\n",
28+
"from qiskit.aqua import set_qiskit_aqua_logging, QuantumInstance\n",
29+
"from qiskit.aqua.operators import Z2Symmetries, WeightedPauliOperator\n",
2930
"from qiskit.aqua.algorithms.adaptive import VQE\n",
3031
"from qiskit.aqua.algorithms.classical import ExactEigensolver\n",
3132
"from qiskit.aqua.components.optimizers import COBYLA\n",
@@ -40,7 +41,7 @@
4041
},
4142
{
4243
"cell_type": "code",
43-
"execution_count": 3,
44+
"execution_count": 2,
4445
"metadata": {},
4546
"outputs": [],
4647
"source": [
@@ -52,7 +53,7 @@
5253
},
5354
{
5455
"cell_type": "code",
55-
"execution_count": 4,
56+
"execution_count": 3,
5657
"metadata": {},
5758
"outputs": [
5859
{
@@ -82,7 +83,7 @@
8283
},
8384
{
8485
"cell_type": "code",
85-
"execution_count": 5,
86+
"execution_count": 4,
8687
"metadata": {},
8788
"outputs": [
8889
{
@@ -96,28 +97,28 @@
9697
"IIIIIIXI\n",
9798
"IIIIIXII\n",
9899
"cliffords found:\n",
99-
"ZIZIZIZI\t0.7071067811865475\n",
100-
"IIIIIIXI\t0.7071067811865475\n",
100+
"ZIZIZIZI\t(0.7071067811865475+0j)\n",
101+
"IIIIIIXI\t(0.7071067811865475+0j)\n",
101102
"\n",
102-
"ZZIIZZII\t0.7071067811865475\n",
103-
"IIIIIXII\t0.7071067811865475\n",
103+
"ZZIIZZII\t(0.7071067811865475+0j)\n",
104+
"IIIIIXII\t(0.7071067811865475+0j)\n",
104105
"\n",
105106
"single-qubit list: [1, 2]\n"
106107
]
107108
}
108109
],
109110
"source": [
110-
"[symmetries, sq_paulis, cliffords, sq_list] = qubit_op.find_Z2_symmetries()\n",
111+
"z2_symmetries = Z2Symmetries.find_Z2_symmetries(qubit_op)\n",
111112
"print('Z2 symmetries found:')\n",
112-
"for symm in symmetries:\n",
113+
"for symm in z2_symmetries.symmetries:\n",
113114
" print(symm.to_label())\n",
114115
"print('single qubit operators found:')\n",
115-
"for sq in sq_paulis:\n",
116+
"for sq in z2_symmetries.sq_paulis:\n",
116117
" print(sq.to_label())\n",
117118
"print('cliffords found:')\n",
118-
"for clifford in cliffords:\n",
119-
" print(clifford.print_operators())\n",
120-
"print('single-qubit list: {}'.format(sq_list))"
119+
"for clifford in z2_symmetries.cliffords:\n",
120+
" print(clifford.print_details())\n",
121+
"print('single-qubit list: {}'.format(z2_symmetries.sq_list))"
121122
]
122123
},
123124
{
@@ -129,7 +130,7 @@
129130
},
130131
{
131132
"cell_type": "code",
132-
"execution_count": 6,
133+
"execution_count": 5,
133134
"metadata": {},
134135
"outputs": [
135136
{
@@ -144,10 +145,8 @@
144145
}
145146
],
146147
"source": [
147-
"tapered_ops = []\n",
148-
"for coeff in itertools.product([1, -1], repeat=len(sq_list)):\n",
149-
" tapered_op = Operator.qubit_tapering(qubit_op, cliffords, sq_list, list(coeff))\n",
150-
" tapered_ops.append((list(coeff), tapered_op))\n",
148+
"tapered_ops = z2_symmetries.taper(qubit_op)\n",
149+
"for tapered_op in tapered_ops:\n",
151150
" print(\"Number of qubits of tapered qubit operator: {}\".format(tapered_op.num_qubits))"
152151
]
153152
},
@@ -160,7 +159,7 @@
160159
},
161160
{
162161
"cell_type": "code",
163-
"execution_count": 7,
162+
"execution_count": 6,
164163
"metadata": {
165164
"scrolled": true
166165
},
@@ -196,7 +195,7 @@
196195
},
197196
{
198197
"cell_type": "code",
199-
"execution_count": 8,
198+
"execution_count": 7,
200199
"metadata": {},
201200
"outputs": [
202201
{
@@ -215,15 +214,15 @@
215214
"smallest_eig_value = 99999999999999\n",
216215
"smallest_idx = -1\n",
217216
"for idx in range(len(tapered_ops)):\n",
218-
" ee = ExactEigensolver(tapered_ops[idx][1], k=1)\n",
217+
" ee = ExactEigensolver(tapered_ops[idx], k=1)\n",
219218
" curr_value = ee.run()['energy']\n",
220219
" if curr_value < smallest_eig_value:\n",
221220
" smallest_eig_value = curr_value\n",
222221
" smallest_idx = idx\n",
223222
" print(\"Lowest eigenvalue of the {}-th tapered operator (computed part) is {:.12f}\".format(idx, curr_value))\n",
224223
" \n",
225-
"the_tapered_op = tapered_ops[smallest_idx][1]\n",
226-
"the_coeff = tapered_ops[smallest_idx][0]\n",
224+
"the_tapered_op = tapered_ops[smallest_idx]\n",
225+
"the_coeff = tapered_ops[smallest_idx].z2_symmetries.tapering_values\n",
227226
"print(\"The {}-th tapered operator matches original ground state energy, with corresponding symmetry sector of {}\".format(smallest_idx, the_coeff))"
228227
]
229228
},
@@ -237,29 +236,28 @@
237236
},
238237
{
239238
"cell_type": "code",
240-
"execution_count": 9,
239+
"execution_count": 8,
241240
"metadata": {},
242241
"outputs": [],
243242
"source": [
244243
"# setup initial state\n",
245244
"init_state = HartreeFock(num_qubits=the_tapered_op.num_qubits, num_orbitals=core._molecule_info['num_orbitals'],\n",
246245
" qubit_mapping=core._qubit_mapping, two_qubit_reduction=core._two_qubit_reduction,\n",
247-
" num_particles=core._molecule_info['num_particles'], sq_list=sq_list)\n",
246+
" num_particles=core._molecule_info['num_particles'], sq_list=the_tapered_op.z2_symmetries.sq_list)\n",
248247
"\n",
249248
"# setup variationl form\n",
250249
"var_form = UCCSD(num_qubits=the_tapered_op.num_qubits, depth=1,\n",
251250
" num_orbitals=core._molecule_info['num_orbitals'], \n",
252251
" num_particles=core._molecule_info['num_particles'],\n",
253252
" active_occupied=None, active_unoccupied=None, initial_state=init_state,\n",
254253
" qubit_mapping=core._qubit_mapping, two_qubit_reduction=core._two_qubit_reduction, \n",
255-
" num_time_slices=1,\n",
256-
" cliffords=cliffords, sq_list=sq_list, tapering_values=the_coeff, symmetries=symmetries)\n",
254+
" num_time_slices=1, z2_symmetries=the_tapered_op.z2_symmetries)\n",
257255
"\n",
258256
"# setup optimizer\n",
259257
"optimizer = COBYLA(maxiter=1000)\n",
260258
"\n",
261259
"# set vqe\n",
262-
"algo = VQE(the_tapered_op, var_form, optimizer, 'matrix')\n",
260+
"algo = VQE(the_tapered_op, var_form, optimizer)\n",
263261
"\n",
264262
"# setup backend\n",
265263
"backend = BasicAer.get_backend('statevector_simulator')\n",
@@ -268,7 +266,7 @@
268266
},
269267
{
270268
"cell_type": "code",
271-
"execution_count": 10,
269+
"execution_count": 9,
272270
"metadata": {},
273271
"outputs": [],
274272
"source": [
@@ -277,7 +275,7 @@
277275
},
278276
{
279277
"cell_type": "code",
280-
"execution_count": 11,
278+
"execution_count": 10,
281279
"metadata": {},
282280
"outputs": [
283281
{
@@ -286,15 +284,15 @@
286284
"text": [
287285
"=== GROUND STATE ENERGY ===\n",
288286
" \n",
289-
"* Electronic ground state energy (Hartree): -8.874303856889\n",
290-
" - computed part: -1.078084288118\n",
287+
"* Electronic ground state energy (Hartree): -8.874303841496\n",
288+
" - computed part: -1.078084272725\n",
291289
" - frozen energy part: -7.796219568771\n",
292290
" - particle hole part: 0.0\n",
293291
"~ Nuclear repulsion energy (Hartree): 0.992207270475\n",
294-
"> Total ground state energy (Hartree): -7.882096586414\n",
292+
"> Total ground state energy (Hartree): -7.882096571021\n",
295293
"The parameters for UCCSD are:\n",
296-
"[ 0.03815735 0.00366554 0.03827111 0.00369737 -0.03604811 0.0594364\n",
297-
" -0.02741369 -0.02735108 0.05956488 -0.11497243]\n"
294+
"[ 0.03803094 0.00360661 0.0382837 0.00369849 -0.03608325 0.05942172\n",
295+
" -0.02729715 -0.02732059 0.05965191 -0.11498381]\n"
298296
]
299297
}
300298
],
@@ -316,9 +314,9 @@
316314
],
317315
"metadata": {
318316
"kernelspec": {
319-
"display_name": "Python 3",
317+
"display_name": "Quantum (Dev)",
320318
"language": "python",
321-
"name": "python3"
319+
"name": "quantum-dev"
322320
},
323321
"language_info": {
324322
"codemirror_mode": {
@@ -330,7 +328,7 @@
330328
"name": "python",
331329
"nbconvert_exporter": "python",
332330
"pygments_lexer": "ipython3",
333-
"version": "3.6.1"
331+
"version": "3.7.3"
334332
}
335333
},
336334
"nbformat": 4,

0 commit comments

Comments
 (0)