Skip to content

Commit

Permalink
Clarifications on the QUBO tutorial (#731)
Browse files Browse the repository at this point in the history
* Clarifications on the QUBO tutorial

* Clarifying embedding section
  • Loading branch information
HGSilveri authored Sep 24, 2024
1 parent a7c4765 commit a90dec0
Showing 1 changed file with 37 additions and 23 deletions.
60 changes: 37 additions & 23 deletions tutorials/applications/QAOA and QAA to solve a QUBO problem.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,7 @@
"QUBO has been extensively studied [Glover, et al., 2018](https://arxiv.org/pdf/1811.11538.pdf) and is used to model and solve numerous categories of optimization problems including important instances of network flows, scheduling, max-cut, max-clique, vertex cover and other graph and management science problems, integrating them into a unified modeling framework.\n",
"\n",
"Mathematically, a QUBO instance consists of a symmetric matrix $Q$ of size $(N \\times N)$, and the optimization problem associated with it is to find the bitstring $z=(z_1, \\dots, z_N) \\in \\{0, 1 \\}^N$ that minimizes the quantity\n",
"$$f(z) = z^{T}Qz$$ \n",
"\n",
"\n",
"In this tutorial, we will demonstrate how a QUBO instance can be mapped and solved using neutral atoms."
"$$f(z) = z^{T}Qz$$ "
]
},
{
Expand Down Expand Up @@ -74,7 +71,17 @@
"cell_type": "markdown",
"metadata": {},
"source": [
"Because the QUBO is small, we can classically check all solutions and mark the optimal ones. This will help us later in the tutorial to visualize the quality of our quantum approach."
"In this tutorial, we will demonstrate how this QUBO instance can be mapped and solved using neutral atoms. For reasons that will become apparent further along, this QUBO instance is particularly amenable to embedding on a neutral-atom device since:\n",
"\n",
"1. All the off-diagonal terms are positive.\n",
"2. The diagonal terms are all equal."
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Furthermore, because the QUBO is small, we can classically check all solutions and mark the optimal ones. This will help us later in the tutorial to visualize the quality of our quantum approach."
]
},
{
Expand Down Expand Up @@ -115,7 +122,16 @@
"source": [
"We now illustrate how to use Pulser to embbed the QUBO matrix $Q$ on a neutral-atom device.\n",
"\n",
"The key idea is to encode the off-diagonal terms of $Q$ by using the Rydberg interaction between atoms. As the interaction $U$ depends on the pairwise distance ($U=C_6/r_{ij}^6$) between atoms $i$ and $j$, we attempt to find the optimal positions of the atoms in the Register that replicate best the off-diagonal terms of $Q$:"
"The key idea is to encode the off-diagonal terms of $Q$ by using the Rydberg interaction between atoms. Recalling that the interaction between two atoms is given by \n",
"$$\n",
"U_{ij}=C_6/r_{ij}^6,\n",
"$$\n",
"we note that \n",
"\n",
"1. The term is strictly positive, which is why it matters that our off-diagonal terms are too.\n",
"2. Its magnitude depends on the pairwise distance between atoms $i$ and $j$, $r_{ij}$. \n",
"\n",
"As such, we attempt a simple minimization procedure to find the optimal positions of the atoms in the Register that replicate best the off-diagonal terms of $Q$:"
]
},
{
Expand All @@ -124,11 +140,10 @@
"metadata": {},
"outputs": [],
"source": [
"def evaluate_mapping(new_coords, *args):\n",
" \"\"\"Cost function to minimize. Ideally, the pairwise\n",
" distances are conserved\"\"\"\n",
" Q, shape = args\n",
" new_coords = np.reshape(new_coords, shape)\n",
"def evaluate_mapping(new_coords, Q):\n",
" \"\"\"Cost function to minimize. Ideally, the pairwise distances are conserved.\"\"\"\n",
" new_coords = np.reshape(new_coords, (len(Q), 2))\n",
" # computing the matrix of the distances between all coordinate pairs\n",
" new_Q = squareform(\n",
" DigitalAnalogDevice.interaction_coeff / pdist(new_coords) ** 6\n",
" )\n",
Expand All @@ -141,14 +156,13 @@
"metadata": {},
"outputs": [],
"source": [
"shape = (len(Q), 2)\n",
"costs = []\n",
"np.random.seed(0)\n",
"x0 = np.random.random(shape).flatten()\n",
"x0 = np.random.random(len(Q) * 2)\n",
"res = minimize(\n",
" evaluate_mapping,\n",
" x0,\n",
" args=(Q, shape),\n",
" args=(Q,),\n",
" method=\"Nelder-Mead\",\n",
" tol=1e-6,\n",
" options={\"maxiter\": 200000, \"maxfev\": None},\n",
Expand Down Expand Up @@ -178,6 +192,13 @@
")"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"In this case, this simple procedure was enough to give a good and valid embedding but it will not always be so. For QUBO instances that are not as easy to embbed as this one, more complex embedding strategies are required."
]
},
{
"cell_type": "markdown",
"metadata": {},
Expand All @@ -193,9 +214,9 @@
"\n",
"$$ H_Q= \\sum_{i=1}^N \\frac{\\hbar\\Omega}{2} \\sigma_i^x - \\sum_{i=1}^N \\frac{\\hbar \\delta}{2} \\sigma_i^z+\\sum_{j \\lt i}\\frac{C_6}{|\\textbf{r}_i-\\textbf{r}_j|^{6}} n_i n_j. $$\n",
"\n",
"In the case where our mapping of the atoms is perfect, the last sum replicates exactly the off-diagonal terms of $Q$. In that case, the next step is to prepare the ground-state of $H_Q$ to output the optimal bitstrings.\n",
"In the case where our mapping of the atoms is perfect, the last sum replicates exactly the off-diagonal terms of $Q$. Additionally, since the diagonal terms are all the same, we can use a Rydberg global beam with an approriate detuning $\\delta$ (otherwise, some kind of local addressability capabilities would be necessary).\n",
"\n",
"To do so we present two different approaches, namely the Quantum Approximation Optimization Algorithm (QAOA) and the Quantum Adiabatic Algorithm (QAA) that have been introduced to prepare ground-states of Hamiltonians."
"As such, the next step is to prepare the ground-state of $H_Q$ to output the optimal bitstrings. To do so we present two different approaches, namely the Quantum Approximation Optimization Algorithm (QAOA) and the Quantum Adiabatic Algorithm (QAA) that have been introduced to prepare ground-states of Hamiltonians."
]
},
{
Expand Down Expand Up @@ -481,13 +502,6 @@
"In our case, we continuously vary the parameters $\\Omega(t), \\delta(t)$ in time, starting with $\\Omega(0)=0, \\delta(0)<0$ and ending with $\\Omega(0)=0, \\delta>0$. The ground-state of $H(0)$ corresponds to the initial state $|00000\\rangle$ and the ground-state of $H(t_f)$ corresponds to the ground-state of $H_Q$."
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"The Rydberg blockade radius is directly linked to the Rabi frequency $\\Omega$ and is obtained using `DigitalAnalogDevice.rydberg_blockade_radius()`. In this notebook, $\\Omega$ is initially fixed to a frequency of 1 rad/µs. We can therefore build the adjacency matrix $A$ of $G$ in the following way:"
]
},
{
"cell_type": "markdown",
"metadata": {},
Expand Down

0 comments on commit a90dec0

Please sign in to comment.