Skip to content

Commit 3c93686

Browse files
author
Abraham Asfaw
authored
Merge pull request #17 from manoelmarques/aqua0.6
Fixes Aqua notebooks for upcoming Aqua 0.6 Release
2 parents e055470 + f320777 commit 3c93686

16 files changed

+240
-194
lines changed

.gitignore

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
2+
__pycache__/
3+
.cache/
4+
5+
.ipynb_checkpoints/
6+
7+
Qconfig.py
8+
9+
# editor files
10+
.vscode/
11+
.idea/
12+
13+
# Distribution / packaging
14+
*.egg-info/
15+
16+
# Spyder project settings
17+
.spyderproject
18+
.spyproject
19+
20+
.DS_Store

aqua/algorithm_introduction_with_vqe.ipynb

Lines changed: 15 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -25,11 +25,11 @@
2525
},
2626
{
2727
"cell_type": "code",
28-
"execution_count": 13,
28+
"execution_count": 1,
2929
"metadata": {},
3030
"outputs": [],
3131
"source": [
32-
"from qiskit.aqua import Operator"
32+
"from qiskit.aqua.operators import WeightedPauliOperator"
3333
]
3434
},
3535
{
@@ -43,7 +43,7 @@
4343
},
4444
{
4545
"cell_type": "code",
46-
"execution_count": 14,
46+
"execution_count": 2,
4747
"metadata": {},
4848
"outputs": [],
4949
"source": [
@@ -56,7 +56,7 @@
5656
" ]\n",
5757
"}\n",
5858
"\n",
59-
"qubit_op = Operator.load_from_dict(pauli_dict)"
59+
"qubit_op = WeightedPauliOperator.from_dict(pauli_dict)"
6060
]
6161
},
6262
{
@@ -74,14 +74,14 @@
7474
},
7575
{
7676
"cell_type": "code",
77-
"execution_count": 15,
77+
"execution_count": 3,
7878
"metadata": {},
7979
"outputs": [
8080
{
8181
"name": "stdout",
8282
"output_type": "stream",
8383
"text": [
84-
"-1.857275030202378\n"
84+
"-1.8572750302023797\n"
8585
]
8686
}
8787
],
@@ -106,14 +106,14 @@
106106
},
107107
{
108108
"cell_type": "code",
109-
"execution_count": 17,
109+
"execution_count": 4,
110110
"metadata": {},
111111
"outputs": [
112112
{
113113
"name": "stdout",
114114
"output_type": "stream",
115115
"text": [
116-
"-1.8572750302023808\n"
116+
"-1.8572750302023813\n"
117117
]
118118
}
119119
],
@@ -149,19 +149,11 @@
149149
},
150150
{
151151
"cell_type": "code",
152-
"execution_count": 22,
152+
"execution_count": null,
153153
"metadata": {
154154
"scrolled": true
155155
},
156-
"outputs": [
157-
{
158-
"name": "stdout",
159-
"output_type": "stream",
160-
"text": [
161-
"-1.8572750302012253\n"
162-
]
163-
}
164-
],
156+
"outputs": [],
165157
"source": [
166158
"aqua_cfg_dict = {\n",
167159
" 'algorithm': {\n",
@@ -199,17 +191,9 @@
199191
},
200192
{
201193
"cell_type": "code",
202-
"execution_count": 29,
194+
"execution_count": null,
203195
"metadata": {},
204-
"outputs": [
205-
{
206-
"name": "stdout",
207-
"output_type": "stream",
208-
"text": [
209-
"-1.8572750301886618\n"
210-
]
211-
}
212-
],
196+
"outputs": [],
213197
"source": [
214198
"from qiskit import BasicAer\n",
215199
"from qiskit.aqua.algorithms import VQE\n",
@@ -233,17 +217,9 @@
233217
},
234218
{
235219
"cell_type": "code",
236-
"execution_count": 31,
220+
"execution_count": null,
237221
"metadata": {},
238-
"outputs": [
239-
{
240-
"name": "stdout",
241-
"output_type": "stream",
242-
"text": [
243-
"-1.8572750302012366\n"
244-
]
245-
}
246-
],
222+
"outputs": [],
247223
"source": [
248224
"from qiskit.aqua import QuantumInstance\n",
249225
"from qiskit.transpiler import PassManager\n",
@@ -290,7 +266,7 @@
290266
"name": "python",
291267
"nbconvert_exporter": "python",
292268
"pygments_lexer": "ipython3",
293-
"version": "3.6.1"
269+
"version": "3.6.8"
294270
}
295271
},
296272
"nbformat": 4,

aqua/eoh.ipynb

Lines changed: 23 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -10,29 +10,38 @@
1010
"\n",
1111
"Further information may be found for the algorithms in the online [Aqua documentation](https://qiskit.org/documentation/aqua/algorithms.html).\n",
1212
"\n",
13-
"For this particular demonstration, we illustrate the `EOH` algorithm. First, two `Operator` instances we created are randomly generated Hamiltonians."
13+
"For this particular demonstration, we illustrate the `EOH` algorithm. First, two `WeightedPauliOperator` instances we created are randomly generated Hamiltonians."
1414
]
1515
},
1616
{
1717
"cell_type": "code",
1818
"execution_count": 1,
1919
"metadata": {},
20-
"outputs": [],
20+
"outputs": [
21+
{
22+
"name": "stderr",
23+
"output_type": "stream",
24+
"text": [
25+
"Converting time from a MatrixOperator to a Pauli-type Operator grows exponentially. If you are converting a system with large number of qubits, it will take time. You can turn on DEBUG logging to check the progress.\n",
26+
"Converting time from a MatrixOperator to a Pauli-type Operator grows exponentially. If you are converting a system with large number of qubits, it will take time. You can turn on DEBUG logging to check the progress.\n"
27+
]
28+
}
29+
],
2130
"source": [
2231
"import numpy as np\n",
2332
"from qiskit import BasicAer\n",
2433
"from qiskit.transpiler import PassManager\n",
2534
"from qiskit.aqua import run_algorithm, QuantumInstance\n",
26-
"from qiskit.aqua.operator import Operator\n",
35+
"from qiskit.aqua.operators import MatrixOperator, op_converter\n",
2736
"from qiskit.aqua.algorithms import EOH\n",
2837
"from qiskit.aqua.components.initial_states import Custom\n",
2938
"from qiskit.aqua.input import EnergyInput\n",
3039
"\n",
3140
"num_qubits = 2\n",
3241
"temp = np.random.random((2 ** num_qubits, 2 ** num_qubits))\n",
33-
"qubit_op = Operator(matrix=temp + temp.T)\n",
42+
"qubit_op = op_converter.to_weighted_pauli_operator(MatrixOperator(matrix=temp + temp.T))\n",
3443
"temp = np.random.random((2 ** num_qubits, 2 ** num_qubits))\n",
35-
"evo_op = Operator(matrix=temp + temp.T)"
44+
"evo_op = op_converter.to_weighted_pauli_operator(MatrixOperator(matrix=temp + temp.T))"
3645
]
3746
},
3847
{
@@ -51,7 +60,7 @@
5160
"evo_time = 1\n",
5261
"num_time_slices = 1\n",
5362
"state_in = Custom(qubit_op.num_qubits, state='uniform')\n",
54-
"eoh = EOH(qubit_op, state_in, evo_op, 'paulis', evo_time, num_time_slices)"
63+
"eoh = EOH(qubit_op, state_in, evo_op, evo_time=evo_time, num_time_slices=num_time_slices)"
5564
]
5665
},
5766
{
@@ -71,13 +80,13 @@
7180
"output_type": "stream",
7281
"text": [
7382
"The result is\n",
74-
"{'avg': (3.469125838650009-1.002992831056778e-16j), 'std_dev': 0.0}\n"
83+
"{'avg': (3.024786762103841-1.1976592430219064e-16j), 'std_dev': 0.0}\n"
7584
]
7685
}
7786
],
7887
"source": [
7988
"backend = BasicAer.get_backend('statevector_simulator')\n",
80-
"quantum_instance = QuantumInstance(backend, pass_manager=PassManager())\n",
89+
"quantum_instance = QuantumInstance(backend)\n",
8190
"\n",
8291
"ret = eoh.run(quantum_instance)\n",
8392
"print('The result is\\n{}'.format(ret))"
@@ -92,7 +101,7 @@
92101
},
93102
{
94103
"cell_type": "code",
95-
"execution_count": 7,
104+
"execution_count": 4,
96105
"metadata": {},
97106
"outputs": [],
98107
"source": [
@@ -126,15 +135,15 @@
126135
},
127136
{
128137
"cell_type": "code",
129-
"execution_count": 9,
138+
"execution_count": 5,
130139
"metadata": {},
131140
"outputs": [
132141
{
133142
"name": "stdout",
134143
"output_type": "stream",
135144
"text": [
136145
"The result is\n",
137-
"{'avg': (3.469125838650008-3.2364937588818136e-16j), 'std_dev': 0.0}\n"
146+
"{'avg': (3.024786762103841-1.1976592430219064e-16j), 'std_dev': 0.0}\n"
138147
]
139148
}
140149
],
@@ -153,9 +162,9 @@
153162
],
154163
"metadata": {
155164
"kernelspec": {
156-
"display_name": "Python 3",
165+
"display_name": "Quantum (Dev)",
157166
"language": "python",
158-
"name": "python3"
167+
"name": "quantum-dev"
159168
},
160169
"language_info": {
161170
"codemirror_mode": {
@@ -167,7 +176,7 @@
167176
"name": "python",
168177
"nbconvert_exporter": "python",
169178
"pygments_lexer": "ipython3",
170-
"version": "3.6.1"
179+
"version": "3.7.3"
171180
}
172181
},
173182
"nbformat": 4,

aqua/evolution.ipynb

Lines changed: 56 additions & 23 deletions
Large diffs are not rendered by default.

aqua/simulations_with_noise_and_measurement_error_mitigation.ipynb

Lines changed: 28 additions & 25 deletions
Large diffs are not rendered by default.

aqua/vqe2iqpe.ipynb

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,11 @@
2020
"import numpy as np\n",
2121
"from qiskit import BasicAer\n",
2222
"from qiskit.transpiler import PassManager\n",
23-
"from qiskit.aqua import Operator, QuantumInstance, run_algorithm\n",
23+
"from qiskit.aqua import QuantumInstance, run_algorithm\n",
2424
"from qiskit.aqua.input import EnergyInput\n",
2525
"from qiskit.aqua.algorithms import VQE\n",
2626
"from qiskit.aqua.algorithms import IQPE\n",
27+
"from qiskit.aqua.operators import WeightedPauliOperator\n",
2728
"from qiskit.aqua.components.variational_forms import RYRZ\n",
2829
"from qiskit.aqua.components.optimizers import SPSA\n",
2930
"from qiskit.aqua.components.initial_states.var_form_based import VarFormBased"
@@ -51,7 +52,7 @@
5152
" ]\n",
5253
"}\n",
5354
"\n",
54-
"qubit_op = Operator.load_from_dict(pauli_dict)"
55+
"qubit_op = WeightedPauliOperator.from_dict(pauli_dict)"
5556
]
5657
},
5758
{
@@ -105,7 +106,7 @@
105106
"name": "stdout",
106107
"output_type": "stream",
107108
"text": [
108-
"VQE estimated the ground energy to be -1.6715595657632292.\n"
109+
"VQE estimated the ground energy to be -1.8244194269951426.\n"
109110
]
110111
}
111112
],
@@ -120,8 +121,7 @@
120121
"spsa_max_trials=10\n",
121122
"optimizer = SPSA(max_trials=spsa_max_trials)\n",
122123
"\n",
123-
"vqe_mode = 'paulis'\n",
124-
"vqe = VQE(algo_input.qubit_op, var_form, optimizer, vqe_mode)\n",
124+
"vqe = VQE(algo_input.qubit_op, var_form, optimizer)\n",
125125
"\n",
126126
"quantum_instance = QuantumInstance(backend)\n",
127127
"result_vqe = vqe.run(quantum_instance)\n",
@@ -160,18 +160,18 @@
160160
"name": "stdout",
161161
"output_type": "stream",
162162
"text": [
163-
"Continuing with VQE's result, IQPE estimated the ground energy to be -1.8531516030612387.\n"
163+
"Continuing with VQE's result, IQPE estimated the ground energy to be -1.8491663307965913.\n"
164164
]
165165
}
166166
],
167167
"source": [
168-
"num_time_slices = 50\n",
169-
"num_iterations = 11\n",
168+
"num_time_slices = 1\n",
169+
"num_iterations = 6\n",
170170
"\n",
171171
"iqpe = IQPE(algo_input.qubit_op, state_in, num_time_slices, num_iterations,\n",
172172
" expansion_mode='suzuki', expansion_order=2,\n",
173173
" shallow_circuit_concat=True)\n",
174-
"quantum_instance = QuantumInstance(backend, shots=100, seed=random_seed, pass_manager=PassManager(), seed_transpiler=random_seed)\n",
174+
"quantum_instance = QuantumInstance(backend, shots=100, seed_simulator=random_seed, seed_transpiler=random_seed)\n",
175175
"result_iqpe = iqpe.run(quantum_instance)\n",
176176
"print(\"Continuing with VQE's result, IQPE estimated the ground energy to be {}.\".format(\n",
177177
" result_iqpe['energy']))"
@@ -187,9 +187,9 @@
187187
],
188188
"metadata": {
189189
"kernelspec": {
190-
"display_name": "Python 3",
190+
"display_name": "Quantum (Dev)",
191191
"language": "python",
192-
"name": "python3"
192+
"name": "quantum-dev"
193193
},
194194
"language_info": {
195195
"codemirror_mode": {
@@ -201,7 +201,7 @@
201201
"name": "python",
202202
"nbconvert_exporter": "python",
203203
"pygments_lexer": "ipython3",
204-
"version": "3.7.2"
204+
"version": "3.7.3"
205205
}
206206
},
207207
"nbformat": 4,

0 commit comments

Comments
 (0)