Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Replace qiskit.algorithms with qiskit_algorithms #537

Merged
merged 15 commits into from
Sep 5, 2023
Merged
7 changes: 4 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -68,10 +68,11 @@ from docplex.mp.model import Model
from qiskit_optimization.algorithms import MinimumEigenOptimizer
from qiskit_optimization.translators import from_docplex_mp

from qiskit.utils import algorithm_globals
from qiskit.primitives import Sampler
from qiskit.algorithms.minimum_eigensolvers import QAOA
from qiskit.algorithms.optimizers import SPSA

from qiskit_algorithms.utils import algorithm_globals
from qiskit_algorithms.minimum_eigensolvers import QAOA
t-imamichi marked this conversation as resolved.
Show resolved Hide resolved
from qiskit_algorithms.optimizers import SPSA

# Generate a graph of 4 nodes
n = 4
Expand Down
1 change: 1 addition & 0 deletions docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,7 @@
"networkx": ("https://networkx.org/documentation/stable", None),
"docplex.mp": ("https://ibmdecisionoptimization.github.io/docplex-doc/mp", None),
"qiskit": ("https://qiskit.org/documentation/", None),
"qiskit_algorithms": ("https://qiskit.org/ecosystem/algorithms", None),
}

html_context = {"analytics_enabled": True}
6 changes: 3 additions & 3 deletions docs/tutorials/01_quadratic_program.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@
"cell_type": "markdown",
"metadata": {},
"source": [
"In this tutorial, we briefly introduce how to build optimization problems using Qiskit's optimization module.\n",
"Qiskit introduces the `QuadraticProgram` class to make a model of an optimization problem.\n",
"In this tutorial, we briefly introduce how to build optimization problems using Qiskit optimization module.\n",
"Qiskit optimization introduces the `QuadraticProgram` class to make a model of an optimization problem.\n",
"More precisely, it deals with quadratically constrained quadratic programs given as follows:\n",
"\n",
"$$\n",
Expand Down Expand Up @@ -70,7 +70,7 @@
"cell_type": "markdown",
"metadata": {},
"source": [
"Qiskit's optimization module supports the conversion from Docplex model. You can easily make a model of an optimization problem with Docplex.\n",
"Qiskit optimization module supports the conversion from Docplex model. You can easily make a model of an optimization problem with Docplex.\n",
"You can find the documentation of Docplex at https://ibmdecisionoptimization.github.io/docplex-doc/mp/index.html\n",
"\n",
"You can load a Docplex model to `QuadraticProgram` by using `from_docplex_mp` function."
Expand Down
6 changes: 3 additions & 3 deletions docs/tutorials/02_converters_for_quadratic_programs.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,11 @@
"cell_type": "markdown",
"metadata": {},
"source": [
"Optimization problems in Qiskit's optimization module are represented with the `QuadraticProgram` class, which is a generic and powerful representation for optimization problems. In general, optimization algorithms are defined for a certain formulation of a quadratic program, and we need to convert our problem to the right type.\n",
"Optimization problems in Qiskit optimization module are represented with the `QuadraticProgram` class, which is a generic and powerful representation for optimization problems. In general, optimization algorithms are defined for a certain formulation of a quadratic program, and we need to convert our problem to the right type.\n",
"\n",
"For instance, Qiskit provides several optimization algorithms that can handle [Quadratic Unconstrained Binary Optimization](https://en.wikipedia.org/wiki/Quadratic_unconstrained_binary_optimization) (QUBO) problems. These are mapped to Ising Hamiltonians, for which Qiskit uses the `qiskit.opflow` module, and then their ground state is approximated. For this optimization, commonly known algorithms such as VQE or QAOA can be used as underlying routine. See the following tutorial about the [Minimum Eigen Optimizer](./03_minimum_eigen_optimizer.ipynb) for more detail. Note that also other algorithms exist that work differently, such as the `GroverOptimizer`.\n",
"For instance, Qiskit optimization provides several optimization algorithms that can handle [Quadratic Unconstrained Binary Optimization](https://en.wikipedia.org/wiki/Quadratic_unconstrained_binary_optimization) (QUBO) problems. These are mapped to Ising Hamiltonians, for which Qiskit uses the `qiskit.quantum_info` module, and then their ground state is approximated. For this optimization, commonly known algorithms such as VQE or QAOA can be used as underlying routine. See the following tutorial about the [Minimum Eigen Optimizer](./03_minimum_eigen_optimizer.ipynb) for more detail. Note that also other algorithms exist that work differently, such as the `GroverOptimizer`.\n",
"\n",
"To map a problem to the correct input format, the optimization module of Qiskit offers a variety of converters. In this tutorial we're providing an overview on this functionality. Currently, Qiskit contains the following converters.\n",
"To map a problem to the correct input format, the optimization module of Qiskit optimization offers a variety of converters. In this tutorial we're providing an overview on this functionality. Currently, Qiskit optimization contains the following converters.\n",
"\n",
"- `InequalityToEquality`: convert inequality constraints into equality constraints with additional slack variables.\n",
"- `IntegerToBinary`: convert integer variables into binary variables and corresponding coefficients.\n",
Expand Down
26 changes: 13 additions & 13 deletions docs/tutorials/03_minimum_eigen_optimizer.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -24,25 +24,25 @@
"An interesting class of optimization problems to be addressed by quantum computing are Quadratic Unconstrained Binary Optimization (QUBO) problems.\n",
"Finding the solution to a QUBO is equivalent to finding the ground state of a corresponding Ising Hamiltonian, which is an important problem not only in optimization, but also in quantum chemistry and physics. For this translation, the binary variables taking values in $\\{0, 1\\}$ are replaced by spin variables taking values in $\\{-1, +1\\}$, which allows one to replace the resulting spin variables by Pauli Z matrices, and thus, an Ising Hamiltonian. For more details on this mapping we refer to [1].\n",
"\n",
"Qiskit provides automatic conversion from a suitable `QuadraticProgram` to an Ising Hamiltonian, which then allows leveraging all the `SamplingMinimumEigensolver` implementations, such as\n",
"Qiskit optimization provides automatic conversion from a suitable `QuadraticProgram` to an Ising Hamiltonian, which then allows leveraging all the `SamplingMinimumEigensolver` implementations, such as\n",
"\n",
"- `SamplingVQE`,\n",
"- `QAOA`, or\n",
"- `NumpyMinimumEigensolver` (classical exact method).\n",
"\n",
"Note 1: `MinimumEigenOptimizer` does not support `qiskit.algorithms.minimum_eigensolver.VQE`. But `qiskit.algorithms.minimum_eigensolver.SamplingVQE`\n",
"Note 1: `MinimumEigenOptimizer` does not support `qiskit_algorithms.minimum_eigensolver.VQE`. But `qiskit_algorithms.minimum_eigensolver.SamplingVQE`\n",
"can be used instead.\n",
"\n",
"Note 2: `MinimumEigenOptimizer` can use `NumpyMinimumEigensolver` as an exception case though it inherits `MinimumEigensolver` (not `SamplingMinimumEigensolver`).\n",
"\n",
"Qiskit Optimization provides a the `MinimumEigenOptimizer` class, which wraps the translation to an Ising Hamiltonian (in Qiskit Terra also called `Operator`), the call to a `MinimumEigensolver`, and the translation of the results back to an `OptimizationResult`.\n",
"Qiskit optimization provides a the `MinimumEigenOptimizer` class, which wraps the translation to an Ising Hamiltonian (in Qiskit Terra also called `SparsePauliOp`), the call to a `MinimumEigensolver`, and the translation of the results back to an `OptimizationResult`.\n",
"\n",
"In the following we first illustrate the conversion from a `QuadraticProgram` to an `Operator` and then show how to use the `MinimumEigenOptimizer` with different `MinimumEigensolver`s to solve a given `QuadraticProgram`.\n",
"The algorithms in Qiskit automatically try to convert a given problem to the supported problem class if possible, for instance, the `MinimumEigenOptimizer` will automatically translate integer variables to binary variables or add linear equality constraints as a quadratic penalty term to the objective. It should be mentioned that a `QiskitOptimizationError` will be thrown if conversion of a quadratic program with integer variables is attempted.\n",
"In the following we first illustrate the conversion from a `QuadraticProgram` to an `SparsePauliOp` and then show how to use the `MinimumEigenOptimizer` with different `MinimumEigensolver`s to solve a given `QuadraticProgram`.\n",
"The algorithms in Qiskit optimization automatically try to convert a given problem to the supported problem class if possible, for instance, the `MinimumEigenOptimizer` will automatically translate integer variables to binary variables or add linear equality constraints as a quadratic penalty term to the objective. It should be mentioned that a `QiskitOptimizationError` will be thrown if conversion of a quadratic program with integer variables is attempted.\n",
"\n",
"The circuit depth of `QAOA` potentially has to be increased with the problem size, which might be prohibitive for near-term quantum devices.\n",
"A possible workaround is Recursive QAOA, as introduced in [2].\n",
"Qiskit generalizes this concept to the `RecursiveMinimumEigenOptimizer`, which is introduced at the end of this tutorial.\n",
"Qiskit optimization generalizes this concept to the `RecursiveMinimumEigenOptimizer`, which is introduced at the end of this tutorial.\n",
"\n",
"### References\n",
"[1] [A. Lucas, *Ising formulations of many NP problems,* Front. Phys., 12 (2014).](https://arxiv.org/abs/1302.5843)\n",
Expand All @@ -55,7 +55,7 @@
"cell_type": "markdown",
"metadata": {},
"source": [
"## Converting a QUBO to an Operator"
"## Converting a QUBO to an SparsePauliOp"
]
},
{
Expand All @@ -64,9 +64,9 @@
"metadata": {},
"outputs": [],
"source": [
"from qiskit.utils import algorithm_globals\n",
"from qiskit.algorithms.minimum_eigensolvers import QAOA, NumPyMinimumEigensolver\n",
"from qiskit.algorithms.optimizers import COBYLA\n",
"from qiskit_algorithms.utils import algorithm_globals\n",
"from qiskit_algorithms.minimum_eigensolvers import QAOA, NumPyMinimumEigensolver\n",
"from qiskit_algorithms.optimizers import COBYLA\n",
"from qiskit.primitives import Sampler\n",
"from qiskit_optimization.algorithms import (\n",
" MinimumEigenOptimizer,\n",
Expand Down Expand Up @@ -118,7 +118,7 @@
"cell_type": "markdown",
"metadata": {},
"source": [
"Next we translate this QUBO into an Ising operator. This results not only in an `Operator` but also in a constant offset to be taken into account to shift the resulting value."
"Next we translate this QUBO into an Ising operator. This results not only in an `SparsePauliOp` but also in a constant offset to be taken into account to shift the resulting value."
]
},
{
Expand Down Expand Up @@ -149,7 +149,7 @@
"cell_type": "markdown",
"metadata": {},
"source": [
"Sometimes a `QuadraticProgram` might also directly be given in the form of an `Operator`. For such cases, Qiskit also provides a translator from an `Operator` back to a `QuadraticProgram`, which we illustrate in the following."
"Sometimes a `QuadraticProgram` might also directly be given in the form of an `SparsePauliOp`. For such cases, Qiskit optimization also provides a translator from an `SparsePauliOp` back to a `QuadraticProgram`, which we illustrate in the following."
]
},
{
Expand Down Expand Up @@ -186,7 +186,7 @@
"cell_type": "markdown",
"metadata": {},
"source": [
"This translator allows, for instance, one to translate an `Operator` to a `QuadraticProgram` and then solve the problem with other algorithms that are not based on the Ising Hamiltonian representation, such as the `GroverOptimizer`."
"This translator allows, for instance, one to translate an `SparsePauliOp` to a `QuadraticProgram` and then solve the problem with other algorithms that are not based on the Ising Hamiltonian representation, such as the `GroverOptimizer`."
]
},
{
Expand Down
10 changes: 5 additions & 5 deletions docs/tutorials/04_grover_optimizer.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,9 @@
"</div>\n",
"<br>\n",
"\n",
"```GroverOptimizer``` uses ```QuadraticProgramToNegativeValueOracle``` to construct $A_y$ such that it prepares a $n$-qubit register to represent the equal superposition of all $|x\\rangle_n$ and a $m$-qubit register to (approximately) represent the corresponding $|Q(x)-y\\rangle_m$. Then, all states with $(Q(x) - y)$ negative should be flagged by $O_y$. Note that in the implementation discussed, the oracle operator is actually independent of $y$, but this is not a requirement. For clarity, we will refer to the oracle as $O$ when the oracle is independent of $y$.\n",
"`GroverOptimizer` uses `QuadraticProgramToNegativeValueOracle` to construct $A_y$ such that it prepares a $n$-qubit register to represent the equal superposition of all $|x\\rangle_n$ and a $m$-qubit register to (approximately) represent the corresponding $|Q(x)-y\\rangle_m$. Then, all states with $(Q(x) - y)$ negative should be flagged by $O_y$. Note that in the implementation discussed, the oracle operator is actually independent of $y$, but this is not a requirement. For clarity, we will refer to the oracle as $O$ when the oracle is independent of $y$.\n",
"\n",
"Put formally, ```QuadraticProgramToNegativeValueOracle``` constructs an $A_y$ and $O$ such that:\n",
"Put formally, `QuadraticProgramToNegativeValueOracle` constructs an $A_y$ and $O$ such that:\n",
"\n",
"<br>\n",
"<div>\n",
Expand All @@ -69,7 +69,7 @@
"\\min_{x \\in \\{0, 1\\}^3} -2x_0x_2 - x_1x_2 - 1x_0 + 2x_1 - 3x_2.\n",
"\\end{eqnarray}\n",
"\n",
"For our initial steps, we create a docplex model that defines the problem above, and then use the ```from_docplex_mp()``` function to convert the model to a ```QuadraticProgram```, which can be used to represent a QUBO in Qiskit Optimization."
"For our initial steps, we create a docplex model that defines the problem above, and then use the `from_docplex_mp()` function to convert the model to a `QuadraticProgram`, which can be used to represent a QUBO in Qiskit Optimization."
]
},
{
Expand All @@ -78,7 +78,7 @@
"metadata": {},
"outputs": [],
"source": [
"from qiskit.algorithms.minimum_eigensolvers import NumPyMinimumEigensolver\n",
"from qiskit_algorithms.minimum_eigensolvers import NumPyMinimumEigensolver\n",
"from qiskit.primitives import Sampler\n",
"from qiskit_optimization.algorithms import GroverOptimizer, MinimumEigenOptimizer\n",
"from qiskit_optimization.translators import from_docplex_mp\n",
Expand Down Expand Up @@ -173,7 +173,7 @@
"source": [
"## Check that GroverOptimizer finds the correct value\n",
"\n",
"We can verify that the algorithm is working correctly using the `MinimumEigenOptimizer` in Qiskit."
"We can verify that the algorithm is working correctly using the `MinimumEigenOptimizer` in Qiskit optimization."
]
},
{
Expand Down
6 changes: 3 additions & 3 deletions docs/tutorials/05_admm_optimizer.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -87,8 +87,8 @@
"\n",
"from docplex.mp.model import Model\n",
"\n",
"from qiskit.algorithms.minimum_eigensolvers import QAOA, NumPyMinimumEigensolver\n",
"from qiskit.algorithms.optimizers import COBYLA\n",
"from qiskit_algorithms.minimum_eigensolvers import QAOA, NumPyMinimumEigensolver\n",
"from qiskit_algorithms.optimizers import COBYLA\n",
"from qiskit.primitives import Sampler\n",
"from qiskit_optimization.algorithms import CobylaOptimizer, MinimumEigenOptimizer\n",
"from qiskit_optimization.algorithms.admm_optimizer import ADMMParameters, ADMMOptimizer\n",
Expand Down Expand Up @@ -205,7 +205,7 @@
"source": [
"## Classical Solution\n",
"\n",
"3-ADMM-H needs a QUBO optimizer to solve the QUBO subproblem, and a continuous optimizer to solve the continuous convex constrained subproblem. We first solve the problem classically: we use the `MinimumEigenOptimizer` with the `NumPyMinimumEigenSolver` as a classical and exact QUBO solver and we use the `CobylaOptimizer` as a continuous convex solver. 3-ADMM-H supports any other suitable solver available in Qiskit. For instance, `SamplingVQE`, `QAOA`, and `GroverOptimizer` can be invoked as quantum solvers, as demonstrated later.\n",
"3-ADMM-H needs a QUBO optimizer to solve the QUBO subproblem, and a continuous optimizer to solve the continuous convex constrained subproblem. We first solve the problem classically: we use the `MinimumEigenOptimizer` with the `NumPyMinimumEigenSolver` as a classical and exact QUBO solver and we use the `CobylaOptimizer` as a continuous convex solver. 3-ADMM-H supports any other suitable solver available in Qiskit optimization. For instance, `SamplingVQE`, `QAOA`, and `GroverOptimizer` can be invoked as quantum solvers, as demonstrated later.\n",
"If CPLEX is installed, the `CplexOptimizer` can also be used as both, a QUBO and convex solver."
]
},
Expand Down
12 changes: 6 additions & 6 deletions docs/tutorials/06_examples_max_cut_and_tsp.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
"\n",
"Maximization: profit, value, output, return, yield, utility, efficiency, capacity, number of objects \n",
"\n",
"We consider here max-cut problems of practical interest in many fields, and show how they can be mapped on quantum computers manually and how Qiskit's optimization module supports this.\n",
"We consider here max-cut problems of practical interest in many fields, and show how they can be mapped on quantum computers manually and how Qiskit optimization module supports this.\n",
"\n",
"\n",
"### Weighted Max-Cut\n",
Expand All @@ -50,7 +50,7 @@
"\n",
"$$ H = \\sum_i w_i Z_i + \\sum_{i<j} w_{ij} Z_iZ_j.$$\n",
"\n",
"Qiskit's optimization module can generate the Ising Hamiltonian for the first profit function $\\tilde{C}$.\n",
"Qiskit optimization module can generate the Ising Hamiltonian for the first profit function $\\tilde{C}$.\n",
"To this extent, function $\\tilde{C}$ can be modeled as a `QuadraticProgram`, which provides the `to_ising()` method.\n",
"\n",
"\n",
Expand Down Expand Up @@ -118,9 +118,9 @@
"from qiskit.tools.visualization import plot_histogram\n",
"from qiskit.circuit.library import TwoLocal\n",
"from qiskit_optimization.applications import Maxcut, Tsp\n",
"from qiskit.algorithms.minimum_eigensolvers import SamplingVQE, NumPyMinimumEigensolver\n",
"from qiskit.algorithms.optimizers import SPSA\n",
"from qiskit.utils import algorithm_globals\n",
"from qiskit_algorithms.minimum_eigensolvers import SamplingVQE, NumPyMinimumEigensolver\n",
"from qiskit_algorithms.optimizers import SPSA\n",
"from qiskit_algorithms.utils import algorithm_globals\n",
"from qiskit.primitives import Sampler\n",
"from qiskit_optimization.algorithms import MinimumEigenOptimizer"
]
Expand Down Expand Up @@ -281,7 +281,7 @@
"cell_type": "markdown",
"metadata": {},
"source": [
"Qiskit provides functionality to generate `QuadraticProgram` from the problem specification as well as create the corresponding Ising Hamiltonian.\n"
"Qiskit optimization provides functionality to generate `QuadraticProgram` from the problem specification as well as create the corresponding Ising Hamiltonian.\n"
]
},
{
Expand Down
8 changes: 4 additions & 4 deletions docs/tutorials/07_examples_vehicle_routing.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@
"c = 2An +2AK^2.\n",
"$$\n",
"\n",
"The QP formulation of the Ising Hamiltonian is ready for the use of VQE. We will solve the QP using optimization stack available in Qiskit.\n",
"The QP formulation of the Ising Hamiltonian is ready for the use of VQE. We will solve the QP using optimization stack available in Qiskit optimization.\n",
"\n",
"\n",
"\n",
Expand Down Expand Up @@ -188,9 +188,9 @@
" print(\"Warning: Cplex not found.\")\n",
"import math\n",
"\n",
"from qiskit.utils import algorithm_globals\n",
"from qiskit.algorithms.minimum_eigensolvers import SamplingVQE\n",
"from qiskit.algorithms.optimizers import SPSA\n",
"from qiskit_algorithms.utils import algorithm_globals\n",
"from qiskit_algorithms.minimum_eigensolvers import SamplingVQE\n",
"from qiskit_algorithms.optimizers import SPSA\n",
"from qiskit.circuit.library import RealAmplitudes\n",
"from qiskit.primitives import Sampler"
]
Expand Down
Loading