|
10 | 10 | "\n",
|
11 | 11 | "Further information may be found for the algorithms in the online [Aqua documentation](https://qiskit.org/documentation/aqua/algorithms.html).\n",
|
12 | 12 | "\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." |
14 | 14 | ]
|
15 | 15 | },
|
16 | 16 | {
|
17 | 17 | "cell_type": "code",
|
18 | 18 | "execution_count": 1,
|
19 | 19 | "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 | + ], |
21 | 30 | "source": [
|
22 | 31 | "import numpy as np\n",
|
23 | 32 | "from qiskit import BasicAer\n",
|
24 | 33 | "from qiskit.transpiler import PassManager\n",
|
25 | 34 | "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", |
27 | 36 | "from qiskit.aqua.algorithms import EOH\n",
|
28 | 37 | "from qiskit.aqua.components.initial_states import Custom\n",
|
29 | 38 | "from qiskit.aqua.input import EnergyInput\n",
|
30 | 39 | "\n",
|
31 | 40 | "num_qubits = 2\n",
|
32 | 41 | "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", |
34 | 43 | "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))" |
36 | 45 | ]
|
37 | 46 | },
|
38 | 47 | {
|
|
51 | 60 | "evo_time = 1\n",
|
52 | 61 | "num_time_slices = 1\n",
|
53 | 62 | "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)" |
55 | 64 | ]
|
56 | 65 | },
|
57 | 66 | {
|
|
71 | 80 | "output_type": "stream",
|
72 | 81 | "text": [
|
73 | 82 | "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" |
75 | 84 | ]
|
76 | 85 | }
|
77 | 86 | ],
|
78 | 87 | "source": [
|
79 | 88 | "backend = BasicAer.get_backend('statevector_simulator')\n",
|
80 |
| - "quantum_instance = QuantumInstance(backend, pass_manager=PassManager())\n", |
| 89 | + "quantum_instance = QuantumInstance(backend)\n", |
81 | 90 | "\n",
|
82 | 91 | "ret = eoh.run(quantum_instance)\n",
|
83 | 92 | "print('The result is\\n{}'.format(ret))"
|
|
92 | 101 | },
|
93 | 102 | {
|
94 | 103 | "cell_type": "code",
|
95 |
| - "execution_count": 7, |
| 104 | + "execution_count": 4, |
96 | 105 | "metadata": {},
|
97 | 106 | "outputs": [],
|
98 | 107 | "source": [
|
|
126 | 135 | },
|
127 | 136 | {
|
128 | 137 | "cell_type": "code",
|
129 |
| - "execution_count": 9, |
| 138 | + "execution_count": 5, |
130 | 139 | "metadata": {},
|
131 | 140 | "outputs": [
|
132 | 141 | {
|
133 | 142 | "name": "stdout",
|
134 | 143 | "output_type": "stream",
|
135 | 144 | "text": [
|
136 | 145 | "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" |
138 | 147 | ]
|
139 | 148 | }
|
140 | 149 | ],
|
|
153 | 162 | ],
|
154 | 163 | "metadata": {
|
155 | 164 | "kernelspec": {
|
156 |
| - "display_name": "Python 3", |
| 165 | + "display_name": "Quantum (Dev)", |
157 | 166 | "language": "python",
|
158 |
| - "name": "python3" |
| 167 | + "name": "quantum-dev" |
159 | 168 | },
|
160 | 169 | "language_info": {
|
161 | 170 | "codemirror_mode": {
|
|
167 | 176 | "name": "python",
|
168 | 177 | "nbconvert_exporter": "python",
|
169 | 178 | "pygments_lexer": "ipython3",
|
170 |
| - "version": "3.6.1" |
| 179 | + "version": "3.7.3" |
171 | 180 | }
|
172 | 181 | },
|
173 | 182 | "nbformat": 4,
|
|
0 commit comments