From 97328c07123943644f93be2e1929bd0d024b66ad Mon Sep 17 00:00:00 2001 From: HGSilveri Date: Thu, 12 Sep 2024 12:19:57 +0200 Subject: [PATCH 1/2] Clarifications on the QUBO tutorial --- ...QAOA and QAA to solve a QUBO problem.ipynb | 49 ++++++++++++------- 1 file changed, 32 insertions(+), 17 deletions(-) diff --git a/tutorials/applications/QAOA and QAA to solve a QUBO problem.ipynb b/tutorials/applications/QAOA and QAA to solve a QUBO problem.ipynb index bee1d597..9e1248ad 100644 --- a/tutorials/applications/QAOA and QAA to solve a QUBO problem.ipynb +++ b/tutorials/applications/QAOA and QAA to solve a QUBO problem.ipynb @@ -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$$ " ] }, { @@ -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." ] }, { @@ -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$:" ] }, { @@ -125,8 +141,7 @@ "outputs": [], "source": [ "def evaluate_mapping(new_coords, *args):\n", - " \"\"\"Cost function to minimize. Ideally, the pairwise\n", - " distances are conserved\"\"\"\n", + " \"\"\"Cost function to minimize. Ideally, the pairwise distances are conserved.\"\"\"\n", " Q, shape = args\n", " new_coords = np.reshape(new_coords, shape)\n", " new_Q = squareform(\n", @@ -178,6 +193,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": {}, @@ -193,9 +215,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." ] }, { @@ -481,13 +503,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": {}, From 72883b8d3549cdc76d12780b5903b07db809d190 Mon Sep 17 00:00:00 2001 From: HGSilveri Date: Thu, 12 Sep 2024 17:46:33 +0200 Subject: [PATCH 2/2] Clarifying embedding section --- .../QAOA and QAA to solve a QUBO problem.ipynb | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/tutorials/applications/QAOA and QAA to solve a QUBO problem.ipynb b/tutorials/applications/QAOA and QAA to solve a QUBO problem.ipynb index 9e1248ad..624fc894 100644 --- a/tutorials/applications/QAOA and QAA to solve a QUBO problem.ipynb +++ b/tutorials/applications/QAOA and QAA to solve a QUBO problem.ipynb @@ -140,10 +140,10 @@ "metadata": {}, "outputs": [], "source": [ - "def evaluate_mapping(new_coords, *args):\n", + "def evaluate_mapping(new_coords, Q):\n", " \"\"\"Cost function to minimize. Ideally, the pairwise distances are conserved.\"\"\"\n", - " Q, shape = args\n", - " new_coords = np.reshape(new_coords, shape)\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", @@ -156,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",