Skip to content

Commit 58fb2ac

Browse files
author
Richard Chen
committed
fix the deprecated warning
1 parent 5342da6 commit 58fb2ac

File tree

4 files changed

+114
-69
lines changed

4 files changed

+114
-69
lines changed

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,

0 commit comments

Comments
 (0)