Skip to content

Commit

Permalink
remove runtime program and quantum instance
Browse files Browse the repository at this point in the history
  • Loading branch information
t-imamichi committed Aug 30, 2023
1 parent e2855f2 commit b3bbd53
Show file tree
Hide file tree
Showing 20 changed files with 102 additions and 2,895 deletions.
6 changes: 0 additions & 6 deletions docs/apidocs/qiskit_optimization.runtime.rst

This file was deleted.

152 changes: 40 additions & 112 deletions docs/migration/01_migration_guide_to_v0.5.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -103,27 +103,19 @@
]
},
{
"cell_type": "code",
"execution_count": 2,
"cell_type": "markdown",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"fval=1.0, x=1.0, y=0.0, status=SUCCESS\n"
]
}
],
"source": [
"```python\n",
"from qiskit.algorithms import NumPyMinimumEigensolver\n",
"\n",
"from qiskit_optimization.algorithms import MinimumEigenOptimizer\n",
"\n",
"mes = NumPyMinimumEigensolver()\n",
"meo = MinimumEigenOptimizer(min_eigen_solver=mes)\n",
"result = meo.solve(problem)\n",
"print(result)"
"print(result)\n",
"```"
]
},
{
Expand All @@ -135,7 +127,7 @@
},
{
"cell_type": "code",
"execution_count": 3,
"execution_count": 2,
"metadata": {},
"outputs": [
{
Expand All @@ -144,6 +136,14 @@
"text": [
"fval=1.0, x=1.0, y=0.0, status=SUCCESS\n"
]
},
{
"name": "stderr",
"output_type": "stream",
"text": [
"/var/folders/lp/wqsk49dx0y595_730yr48twh0000gn/T/ipykernel_41632/3429859093.py:1: DeprecationWarning: ``qiskit.algorithms`` has been migrated to an independent package: https://github.com/qiskit-community/qiskit-algorithms. The ``qiskit.algorithms`` import path is deprecated as of qiskit-terra 0.25.0 and will be removed no earlier than 3 months after the release date. Please run ``pip install qiskit_algorithms`` and use ``import qiskit_algorithms`` instead.\n",
" from qiskit.algorithms.minimum_eigensolvers import NumPyMinimumEigensolver\n"
]
}
],
"source": [
Expand All @@ -167,19 +167,10 @@
]
},
{
"cell_type": "code",
"execution_count": 4,
"cell_type": "markdown",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"fval=1.0, x=1.0, y=0.0, status=SUCCESS\n"
]
}
],
"source": [
"```python\n",
"from qiskit import BasicAer\n",
"from qiskit.algorithms import QAOA\n",
"from qiskit.algorithms.optimizers import COBYLA\n",
Expand All @@ -193,7 +184,8 @@
"mes = QAOA(optimizer=COBYLA(), quantum_instance=qins)\n",
"meo = MinimumEigenOptimizer(min_eigen_solver=mes)\n",
"result = meo.solve(problem)\n",
"print(result)"
"print(result)\n",
"```"
]
},
{
Expand All @@ -205,7 +197,7 @@
},
{
"cell_type": "code",
"execution_count": 5,
"execution_count": 3,
"metadata": {},
"outputs": [
{
Expand Down Expand Up @@ -240,19 +232,10 @@
]
},
{
"cell_type": "code",
"execution_count": 6,
"cell_type": "markdown",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"fval=1.0, x=1.0, y=0.0, status=SUCCESS\n"
]
}
],
"source": [
"```python\n",
"from qiskit import BasicAer\n",
"from qiskit.algorithms import VQE\n",
"from qiskit.algorithms.optimizers import COBYLA\n",
Expand All @@ -267,7 +250,8 @@
"mes = VQE(ansatz=RealAmplitudes(), optimizer=COBYLA(), quantum_instance=qins)\n",
"meo = MinimumEigenOptimizer(min_eigen_solver=mes)\n",
"result = meo.solve(problem)\n",
"print(result)"
"print(result)\n",
"```"
]
},
{
Expand All @@ -279,7 +263,7 @@
},
{
"cell_type": "code",
"execution_count": 7,
"execution_count": 4,
"metadata": {},
"outputs": [
{
Expand Down Expand Up @@ -313,7 +297,7 @@
},
{
"cell_type": "code",
"execution_count": 8,
"execution_count": 5,
"metadata": {},
"outputs": [
{
Expand Down Expand Up @@ -361,19 +345,10 @@
]
},
{
"cell_type": "code",
"execution_count": 9,
"cell_type": "markdown",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"fval=1.0, x=1.0, y=0.0, status=SUCCESS\n"
]
}
],
"source": [
"```python\n",
"from qiskit import BasicAer\n",
"from qiskit.algorithms import QAOA\n",
"from qiskit.algorithms.optimizers import COBYLA\n",
Expand All @@ -389,7 +364,8 @@
" pre_solver=SlsqpOptimizer(), relax_for_pre_solver=True, qaoa=qaoa, epsilon=0.25\n",
")\n",
"result = optimizer.solve(problem)\n",
"print(result)"
"print(result)\n",
"```"
]
},
{
Expand All @@ -401,7 +377,7 @@
},
{
"cell_type": "code",
"execution_count": 10,
"execution_count": 6,
"metadata": {},
"outputs": [
{
Expand Down Expand Up @@ -438,7 +414,7 @@
"cell_type": "markdown",
"metadata": {},
"source": [
"`GroverOptimizer` supports both `QuantumInstance` and `BaseSampler`. But users must specify one of them."
"`GroverOptimizer` supports `BaseSampler` instead of `QuantumInstance`."
]
},
{
Expand All @@ -449,19 +425,10 @@
]
},
{
"cell_type": "code",
"execution_count": 11,
"cell_type": "markdown",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"fval=1.0, x=1.0, y=0.0, status=SUCCESS\n"
]
}
],
"source": [
"```python\n",
"from qiskit import BasicAer\n",
"from qiskit.algorithms.optimizers import COBYLA\n",
"from qiskit.utils import QuantumInstance\n",
Expand All @@ -473,7 +440,8 @@
"qins = QuantumInstance(backend=backend, shots=shots)\n",
"optimizer = GroverOptimizer(num_value_qubits=3, num_iterations=3, quantum_instance=qins)\n",
"result = optimizer.solve(problem)\n",
"print(result)"
"print(result)\n",
"```"
]
},
{
Expand All @@ -485,14 +453,14 @@
},
{
"cell_type": "code",
"execution_count": 12,
"execution_count": 7,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"fval=0.0, x=0.0, y=0.0, status=SUCCESS\n"
"fval=1.0, x=1.0, y=0.0, status=SUCCESS\n"
]
}
],
Expand All @@ -507,55 +475,15 @@
"print(result)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"An error occurs because both `quantum_instance` and `sampler` are set. You can set only one of them."
]
},
{
"cell_type": "code",
"execution_count": 13,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Only one of quantum_instance or sampler can be passed, not both!\n"
]
}
],
"source": [
"from qiskit import BasicAer\n",
"from qiskit.algorithms.optimizers import COBYLA\n",
"from qiskit.utils import QuantumInstance\n",
"from qiskit.primitives import Sampler\n",
"\n",
"from qiskit_optimization.algorithms import GroverOptimizer\n",
"\n",
"backend = BasicAer.get_backend(\"qasm_simulator\")\n",
"shots = 1000\n",
"qins = QuantumInstance(backend=backend, shots=shots)\n",
"try:\n",
" optimizer = GroverOptimizer(\n",
" num_value_qubits=3, num_iterations=3, quantum_instance=qins, sampler=Sampler()\n",
" )\n",
" # raises an error because both quantum_instance and sampler are set.\n",
"except ValueError as ex:\n",
" print(ex)"
]
},
{
"cell_type": "code",
"execution_count": 14,
"execution_count": 8,
"metadata": {},
"outputs": [
{
"data": {
"text/html": [
"<h3>Version Information</h3><table><tr><th>Qiskit Software</th><th>Version</th></tr><tr><td><code>qiskit-terra</code></td><td>0.23.0</td></tr><tr><td><code>qiskit-aer</code></td><td>0.11.1</td></tr><tr><td><code>qiskit-optimization</code></td><td>0.5.0</td></tr><tr><td><code>qiskit-machine-learning</code></td><td>0.6.0</td></tr><tr><th>System information</th></tr><tr><td>Python version</td><td>3.9.15</td></tr><tr><td>Python compiler</td><td>Clang 14.0.0 (clang-1400.0.29.102)</td></tr><tr><td>Python build</td><td>main, Oct 11 2022 22:27:25</td></tr><tr><td>OS</td><td>Darwin</td></tr><tr><td>CPUs</td><td>4</td></tr><tr><td>Memory (Gb)</td><td>16.0</td></tr><tr><td colspan='2'>Tue Dec 06 22:08:13 2022 JST</td></tr></table>"
"<h3>Version Information</h3><table><tr><th>Software</th><th>Version</th></tr><tr><td><code>qiskit</code></td><td>None</td></tr><tr><td><code>qiskit-terra</code></td><td>0.45.0.dev0+0a0e262</td></tr><tr><td><code>qiskit_optimization</code></td><td>0.6.0</td></tr><tr><th colspan='2'>System information</th></tr><tr><td>Python version</td><td>3.10.13</td></tr><tr><td>Python compiler</td><td>Clang 14.0.3 (clang-1403.0.22.14.1)</td></tr><tr><td>Python build</td><td>main, Aug 24 2023 22:36:46</td></tr><tr><td>OS</td><td>Darwin</td></tr><tr><td>CPUs</td><td>10</td></tr><tr><td>Memory (Gb)</td><td>64.0</td></tr><tr><td colspan='2'>Wed Aug 30 23:18:15 2023 JST</td></tr></table>"
],
"text/plain": [
"<IPython.core.display.HTML object>"
Expand All @@ -567,7 +495,7 @@
{
"data": {
"text/html": [
"<div style='width: 100%; background-color:#d5d9e0;padding-left: 10px; padding-bottom: 10px; padding-right: 10px; padding-top: 5px'><h3>This code is a part of Qiskit</h3><p>&copy; Copyright IBM 2017, 2022.</p><p>This code is licensed under the Apache License, Version 2.0. You may<br>obtain a copy of this license in the LICENSE.txt file in the root directory<br> of this source tree or at http://www.apache.org/licenses/LICENSE-2.0.<p>Any modifications or derivative works of this code must retain this<br>copyright notice, and modified files need to carry a notice indicating<br>that they have been altered from the originals.</p></div>"
"<div style='width: 100%; background-color:#d5d9e0;padding-left: 10px; padding-bottom: 10px; padding-right: 10px; padding-top: 5px'><h3>This code is a part of Qiskit</h3><p>&copy; Copyright IBM 2017, 2023.</p><p>This code is licensed under the Apache License, Version 2.0. You may<br>obtain a copy of this license in the LICENSE.txt file in the root directory<br> of this source tree or at http://www.apache.org/licenses/LICENSE-2.0.<p>Any modifications or derivative works of this code must retain this<br>copyright notice, and modified files need to carry a notice indicating<br>that they have been altered from the originals.</p></div>"
],
"text/plain": [
"<IPython.core.display.HTML object>"
Expand All @@ -591,5 +519,5 @@
}
},
"nbformat": 4,
"nbformat_minor": 2
"nbformat_minor": 4
}
Loading

0 comments on commit b3bbd53

Please sign in to comment.