Skip to content

Commit

Permalink
* Added text on problem preparation
Browse files Browse the repository at this point in the history
  • Loading branch information
eggerdj committed Feb 12, 2024
1 parent 4e2ccab commit 5bdb9f7
Showing 1 changed file with 42 additions and 6 deletions.
48 changes: 42 additions & 6 deletions how_tos/qiskit_patterns.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -28,23 +28,32 @@
"We are interested in solving a classical combinatorial optimization problem which has the form\n",
"\n",
"\\begin{align}\n",
"\\max_{x\\in \\{0, 1\\}^n}f(x)\n",
"\\min_{x\\in \\{0, 1\\}^n}f(x)\n",
"\\end{align}\n",
"\n",
"Here, the vector $x$ are the $n$ decision variables. As you can see, there is nothing relating to quantum computing here yet. We therefore need to reformulate this problem into something that a quantum computer can understand. To be more concrete, we will consider a Quadratic Unconstrained Binary Optimization problem with the form\n",
"\n",
"\\begin{align}\n",
"\\max_{x\\in \\{0, 1\\}^n}x^T Q x,\n",
"\\min_{x\\in \\{0, 1\\}^n}x^T Q x,\n",
"\\end{align}\n",
"where $Q$ is a $n\\times n$ matrix of real numbers. To start, we will convert the binary variables $x_i$ to variables $z_i\\in\\{-1, 1\\}$ by doing\n",
"\\begin{align}\n",
"x_i = \\frac{z_i+1}{2}.\n",
"x_i = \\frac{1-z_i}{2}.\n",
"\\end{align}\n",
"Here, for example, we see that if $x_i$ is $0$ then $z_i$ is $-1$. Now, to obtain a quantum formulation of the problem we promot the $z_i$ variables to a Pauli $Z$ matrix, i.e., a $2\\times 2$ matrix of the form\n",
"Here, for example, we see that if $x_i$ is $0$ then $z_i$ is $1$. When we substitute the $x_i$'s for the $z_i$'s in the QUBO above, we obtain the equivalent formulations for our optimization task\n",
"\\begin{align}\n",
"\\min_{x\\in\\{0,1\\}^n} x^TQx\\Longleftrightarrow \\min_{z\\in\\{-1,1\\}^n}z^TQz + b^Tz\n",
"\\end{align}\n",
"The details of the computation are shown in Appendix A below. Here, $b$ depends on $Q$. Note that to obtain $z^TQz + b^Tz$ we dropped an irrelevant factor of 1/4 and a constant offset of $n^2$ which do not play a role in the optimization. Now, to obtain a quantum formulation of the problem we promot the $z_i$ variables to a Pauli $Z$ matrix, i.e., a $2\\times 2$ matrix of the form\n",
"\\begin{align}\n",
"Z_i = \\begin{pmatrix}1 & 0 \\\\ 0 & -1\\end{pmatrix}.\n",
"\\end{align}\n",
"When we substitute these matrices in the QUBO above we obtain\n",
"When we substitute these matrices in the QUBO above we obtain the following Hamiltonian\n",
"\\begin{align}\n",
"H_C=\\sum_{ij}Q_{ij}Z_iZ_j + \\sum_i b_iZ_i.\n",
"\\end{align}\n",
"We refer to this Hamiltonian as the cost function Hamiltonian. It has the property that its gound state corresponds to the solution that minimizes the cost function $f(x)$.\n",
"Therefore, to solve out optimization problem we now need to prepare the ground state of $H_C$ (or a state with a high overlap with it) on the quantum computer. Then, sampling from this state will, with a high probability, yield the solution to $min f(x)$.\n",
"\n",
"**TODO** Load a file with the LP and convert to an Ising Hamiltonian to feed into step 2."
]
Expand Down Expand Up @@ -87,10 +96,37 @@
"## Discussion and conclusion"
]
},
{
"cell_type": "markdown",
"id": "9b6bd37f-973a-48f2-b0df-b5d9172d09b9",
"metadata": {},
"source": [
"## Appendix A: Reformulation in spin variables\n",
"\n",
"Here, we rewrite the QUBO $x^TQx$ in terms of spin-variables $x_i=(1-z_i)/2$.\n",
"\\begin{align}\n",
"x^TQx=\\sum_{ij}Q_{ij}x_ix_j=\\frac{1}{4}\\sum_{ij}Q_{ij}(1-z_i)(1-z_j)=\\frac{1}{4}\\sum_{ij}Q_{ij}z_iz_j-\\frac{1}{4}\\sum_{ij}(Q_{ij}+Q_{ji})z_i + \\frac{n^2}{4}.\n",
"\\end{align}\n",
"If we write $b_i=-\\sum_{j}(Q_{ij}+Q_{ji})$ and remove the prefactor and the constant $n^2$ term we arrive at the two equivalent formulations of the same optimization problem\n",
"\\begin{align}\n",
"\\max_{x\\in\\{0,1\\}^n} x^TQx\\Longleftrightarrow \\max_{z\\in\\{-1,1\\}^n}z^TQz + b^Tz\n",
"\\end{align}"
]
},
{
"cell_type": "markdown",
"id": "d1e0a59c-ba1a-4310-8eb7-cd969e013daa",
"metadata": {},
"source": [
"## Appendix B: Quantum notation\n",
"\n",
"The $Z$ matrices are imbedded in the quantum computer's computational space, i.e., a Hilbert space of size $2^n\\times 2^n$. Therefore, you should understand terms such as $Z_iZ_j$ as the tensor product $Z_i\\otimes Z_j$ imbedded in the $2^n\\times 2^n$ Hilbert space. For example, in a problem with five decision variables the term $Z_1Z_3$ is understood to mean $I\\otimes Z_3\\otimes I\\otimes Z_1\\otimes I$ where $I$ is the $2\\times 2$ identity matrix."
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "8beeffba-7000-48a4-93bf-1e6d5ef8d6d1",
"id": "1e46ab30-47c2-4ec7-b985-a938da95a28a",
"metadata": {},
"outputs": [],
"source": []
Expand Down

0 comments on commit 5bdb9f7

Please sign in to comment.