Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,7 @@
{
"cell_type": "markdown",
"id": "9d91ea6c-9f4c-4c9e-9e33-f4333482eee5",
"metadata": {
"jp-MarkdownHeadingCollapsed": true
},
"metadata": {},
"source": [
"# Integer Linear Programming"
]
Expand All @@ -15,44 +13,35 @@
"id": "877ae3cf-10cc-4e51-a428-eb57687d8d18",
"metadata": {},
"source": [
"## Introduction\n",
"\n",
"In Integer Linear Programming (ILP), we seek to find a vector of integer numbers that maximizes (or minimizes) a linear cost function under a set of linear equality or inequality constraints [[1]](#ILP). In other words, it is an optimization problem where the cost function to be optimized and all the constraints are linear and the decision variables are integer.\n",
"\n",
"Integer Linear Programming (ILP) seeks a vector of integer numbers that maximizes (or minimizes) a linear cost function under a set of linear equality or inequality constraints [[1]](#ILP). In other words, it is an optimization problem where the cost function to optimize and all the constraints are linear and the decision variables are integers.\n",
"\n",
"\n",
"## Mathematical Formulation\n",
"The ILP problem can be formulated as follows:\n",
"\n",
"Given an $n$-dimensional vector $\\vec{c} = (c_1, c_2, \\ldots, c_n)$, an $m \\times n$ matrix $A = (a_{ij})$ with $i=1,\\ldots,m$ and $j=1,\\ldots,n$, and an $m$-dimensional vector $\\vec{b} = (b_1, b_2, \\ldots, b_m)$, find an $n$-dimensional vector $\\vec{x} = (x_1, x_2, \\ldots, x_n)$ with integer entries that maximizes (or minimizes) the cost function:\n",
"The ILP problem can be formulated as follows: given an $n$-dimensional vector $\\vec{c} = (c_1, c_2, \\ldots, c_n)$, an $m \\times n$ matrix $A = (a_{ij})$ with $i=1,\\ldots,m$ and $j=1,\\ldots,n$, and an $m$-dimensional vector $\\vec{b} = (b_1, b_2, \\ldots, b_m)$, find an $n$-dimensional vector $\\vec{x} = (x_1, x_2, \\ldots, x_n)$ with integer entries that maximizes (or minimizes) the cost function:\n",
"\n",
"\\begin{align*}\n",
"\\vec{c} \\cdot \\vec{x} = c_1x_1 + c_2x_2 + \\ldots + c_nx_n\n",
"\\end{align*}\n",
"\n",
"subject to the constraints:\n",
"subject to these constraints:\n",
"\n",
"\\begin{align*}\n",
"A \\vec{x} & \\leq \\vec{b} \\\\\n",
"x_j & \\geq 0, \\quad j = 1, 2, \\ldots, n \\\\\n",
"x_j & \\in \\mathbb{Z}, \\quad j = 1, 2, \\ldots, n\n",
"\\end{align*}\n",
"\n",
"\n",
"\n",
"# Solving with the Classiq platform\n",
"\n",
"We go through the steps of solving the problem with the Classiq platform, using QAOA algorithm [[2](#QAOA)]. The solution is based on defining a Pyomo model for the optimization problem we would like to solve."
"This tutorial guides you through the steps of solving the problem with the Classiq platform, using QAOA [[2](#QAOA)]. The solution is based on defining a Pyomo model for the optimization problem to solve."
]
},
{
"cell_type": "markdown",
"id": "8517ef73-faf6-4fd8-9db8-4088551398e0",
"metadata": {},
"source": [
"## Building the Pyomo model from a graph input\n",
"## Building the Pyomo Model from a Graph Input\n",
"\n",
"We proceed by defining the Pyomo model that will be used on the Classiq platform, using the mathematical formulation defined above:"
"Define the Pyomo model to use on the Classiq platform, using the mathematical formulation defined above:"
]
},
{
Expand Down Expand Up @@ -179,7 +168,7 @@
"source": [
"## Setting Up the Classiq Problem Instance\n",
"\n",
"In order to solve the Pyomo model defined above, we use the `CombinatorialProblem` quantum object. Under the hood it tranlastes the Pyomo model to a quantum model of the QAOA algorithm, with cost hamiltonian translated from the Pyomo model. We can choose the number of layers for the QAOA ansatz using the argument `num_layers`, and the `penalty_factor`, which will be the coefficient of the constraints term in the cost hamiltonian."
"To solve the Pyomo model defined above, use the `CombinatorialProblem` quantum object. Under the hood it translates the Pyomo model to a quantum model of QAOA, with the cost Hamiltonian translated from the Pyomo model. Choose the number of layers for the QAOA ansatz using the `num_layers` argument. The `penalty_factor` is the coefficient of the constraints term in the cost Hamiltonian."
]
},
{
Expand Down Expand Up @@ -216,7 +205,7 @@
"source": [
"## Synthesizing the QAOA Circuit and Solving the Problem\n",
"\n",
"We can now synthesize and view the QAOA circuit (ansatz) used to solve the optimization problem:"
"Synthesize and view the QAOA circuit (ansatz) used to solve the optimization problem:"
]
},
{
Expand Down Expand Up @@ -248,7 +237,7 @@
"id": "b119464b-9d46-4ea0-ba4a-1734f3e0e3e5",
"metadata": {},
"source": [
"We also set the quantum backend we want to execute on:"
"Set the quantum backend on which to execute:"
]
},
{
Expand All @@ -270,7 +259,7 @@
"id": "07621d7c-0e54-4adb-9c47-8fd99a346e29",
"metadata": {},
"source": [
"We now solve the problem by calling the `optimize` method of the `CombinatorialProblem` object. For the classical optimization part of the QAOA algorithm we define the maximum number of classical iterations (`maxiter`) and the $\\alpha$-parameter (`quantile`) for running CVaR-QAOA, an improved variation of the QAOA algorithm [[3](#cvar)]:"
"Solve the problem by calling the `optimize` method of the `CombinatorialProblem` object. For the classical optimization part of QAOA, define the maximum number of classical iterations (`maxiter`) and the $\\alpha$-parameter (`quantile`) for running CVaR-QAOA, an improved variation of QAOA [[3](#cvar)]:"
]
},
{
Expand Down Expand Up @@ -298,7 +287,7 @@
"id": "620ea6a0-cd05-41a9-a2ed-9631c680d2e6",
"metadata": {},
"source": [
"We can check the convergence of the run:"
"Check the convergence of the run:"
]
},
{
Expand Down Expand Up @@ -346,23 +335,23 @@
"tags": []
},
"source": [
"# Optimization Results"
"## Optimization Results"
]
},
{
"cell_type": "markdown",
"id": "670eddd3-2da7-4a88-b571-7884ef24f60c",
"metadata": {},
"source": [
"We can also examine the statistics of the algorithm. The optimization is always defined as a minimzation problem, so the positive maximization objective was tranlated to a negative minimization one by the Pyomo to qmod translator."
"Examine the statistics of the algorithm. The optimization is always defined as a minimization problem, so the positive maximization objective is translated to negative minimization by the Pyomo-to-Qmod translator."
]
},
{
"cell_type": "markdown",
"id": "c99a7e3e-5203-4893-b970-dc23739f6df2",
"metadata": {},
"source": [
"In order to get samples with the optimized parameters, we call the `sample` method:"
"To get samples with the optimized parameters, call the `sample` method:"
]
},
{
Expand Down Expand Up @@ -463,7 +452,7 @@
"id": "f08c8085-b50a-41a1-9359-46413f60739c",
"metadata": {},
"source": [
"We also want to compare the optimized results to uniformly sampled results:"
"Compare the optimized results to uniformly sampled results:"
]
},
{
Expand Down Expand Up @@ -531,7 +520,7 @@
"id": "a3a890a1-c5d4-409d-b9a3-d7ffd4fdd6c0",
"metadata": {},
"source": [
"Let us plot the solution:"
"Plot the solution:"
]
},
{
Expand Down Expand Up @@ -565,15 +554,15 @@
"id": "149932e1-bfa8-4c27-b5f9-037e74eba400",
"metadata": {},
"source": [
"## Comparison to a classical solver"
"## Comparing to a Classical Solver"
]
},
{
"cell_type": "markdown",
"id": "dde1905d-aeff-4297-a9d3-ad14910e6161",
"metadata": {},
"source": [
"Lastly, we can compare to the classical solution of the problem:"
"Compare to the classical solution of the problem:"
]
},
{
Expand Down Expand Up @@ -617,11 +606,11 @@
"\n",
"## References\n",
"\n",
"<a id='MVC'>[1]</a>: [Integer Programming (Wikipedia).](https://en.wikipedia.org/wiki/Integer_programming)\n",
"<a id='MVC'>[1]</a> [Integer Programming (Wikipedia).](https://en.wikipedia.org/wiki/Integer_programming)\n",
"\n",
"<a id='QAOA'>[2]</a>: [Farhi, Edward, Jeffrey Goldstone, and Sam Gutmann. \"A quantum approximate optimization algorithm.\" arXiv preprint arXiv:1411.4028 (2014).](https://arxiv.org/abs/1411.4028)\n",
"<a id='QAOA'>[2]</a> [Farhi, Edward, Jeffrey Goldstone, and Sam Gutmann. (2014). \"A quantum approximate optimization algorithm.\" arXiv preprint arXiv:1411.4028.](https://arxiv.org/abs/1411.4028)\n",
"\n",
"<a id='cvar'>[3]</a>: [Barkoutsos, Panagiotis Kl, et al. \"Improving variational quantum optimization using CVaR.\" Quantum 4 (2020): 256.](https://arxiv.org/abs/1907.04769)\n"
"<a id='cvar'>[3]</a> [Barkoutsos, Panagiotis Kl, et al. (2020). \"Improving variational quantum optimization using CVaR.\" Quantum 4: 256.](https://arxiv.org/abs/1907.04769)\n"
]
}
],
Expand Down
Loading