|
| 1 | +{ |
| 2 | + "cells": [ |
| 3 | + { |
| 4 | + "cell_type": "markdown", |
| 5 | + "id": "ee412c69", |
| 6 | + "metadata": { |
| 7 | + "cq.autogen": "title_cell" |
| 8 | + }, |
| 9 | + "source": [ |
| 10 | + "# Algorithm: Planted Noisy kXOR" |
| 11 | + ] |
| 12 | + }, |
| 13 | + { |
| 14 | + "cell_type": "code", |
| 15 | + "execution_count": null, |
| 16 | + "id": "df5a7866", |
| 17 | + "metadata": { |
| 18 | + "cq.autogen": "top_imports" |
| 19 | + }, |
| 20 | + "outputs": [], |
| 21 | + "source": [ |
| 22 | + "from qualtran import Bloq, CompositeBloq, BloqBuilder, Signature, Register\n", |
| 23 | + "from qualtran import QBit, QInt, QUInt, QAny\n", |
| 24 | + "from qualtran.drawing import show_bloq, show_call_graph, show_counts_sigma\n", |
| 25 | + "from typing import *\n", |
| 26 | + "import numpy as np\n", |
| 27 | + "import sympy\n", |
| 28 | + "import cirq" |
| 29 | + ] |
| 30 | + }, |
| 31 | + { |
| 32 | + "cell_type": "markdown", |
| 33 | + "id": "36559e8d", |
| 34 | + "metadata": { |
| 35 | + "cq.autogen": "PlantedNoisyKXOR.bloq_doc.md" |
| 36 | + }, |
| 37 | + "source": [ |
| 38 | + "## `PlantedNoisyKXOR`\n", |
| 39 | + "Algorithm for Planted Noisy kXOR.\n", |
| 40 | + "\n", |
| 41 | + "Problem (Problem 2.6 of Ref [1]):\n", |
| 42 | + "\n", |
| 43 | + "Given a noisy-kXOR instance $\\hat{\\mathcal{I}}$ which is drawn either:\n", |
| 44 | + "\n", |
| 45 | + "1. with planted advantage $\\rho$, from $\\tilde\\mathcal{P}^{z}_{n, k}(m, \\rho)$.\n", |
| 46 | + "2. at random, from $\\tilde\\mathcal{R}_{n, k}(m)$.\n", |
| 47 | + "\n", |
| 48 | + "output a single bit such that it is whp `1` in case 1, and `0` in case 2.\n", |
| 49 | + "\n", |
| 50 | + "Algorithm (Section 4.4, Theorem 4.18):\n", |
| 51 | + "We first split the instance into $\\hat{\\mathcal{I}} = \\mathcal{I} \\cup \\mathcal{I}_\\text{guide}$,\n", |
| 52 | + "by placing each constraint independently in $\\mathcal{I}$ with prob. $1 - \\zeta$,\n", |
| 53 | + "otherwise in $\\mathcal{I}_\\text{guide}$.\n", |
| 54 | + "$\\zeta$ is picked to be $1 / \\ln n$.\n", |
| 55 | + "\n", |
| 56 | + "#### Parameters\n", |
| 57 | + " - `inst_guide`: The subset of contraints $\\mathcal{I}_\\text{guide}$ for the guided state.\n", |
| 58 | + " - `inst_solve`: The subset of constraints $\\mathcal{I}$ for eigenvalue estimation.\n", |
| 59 | + " - `ell`: Kikuchi parameter $\\ell$.\n", |
| 60 | + " - `rho`: the planted advantage $\\rho$ in the planted case. \n", |
| 61 | + "\n", |
| 62 | + "#### References\n", |
| 63 | + " - [Quartic quantum speedups for planted inference](https://arxiv.org/abs/2406.19378v1). \n" |
| 64 | + ] |
| 65 | + }, |
| 66 | + { |
| 67 | + "cell_type": "code", |
| 68 | + "execution_count": null, |
| 69 | + "id": "f930da5f", |
| 70 | + "metadata": { |
| 71 | + "cq.autogen": "PlantedNoisyKXOR.bloq_doc.py" |
| 72 | + }, |
| 73 | + "outputs": [], |
| 74 | + "source": [ |
| 75 | + "from qualtran.bloqs.optimization.k_xor_sat import PlantedNoisyKXOR" |
| 76 | + ] |
| 77 | + }, |
| 78 | + { |
| 79 | + "cell_type": "markdown", |
| 80 | + "id": "18f43abd", |
| 81 | + "metadata": { |
| 82 | + "cq.autogen": "PlantedNoisyKXOR.example_instances.md" |
| 83 | + }, |
| 84 | + "source": [ |
| 85 | + "### Example Instances" |
| 86 | + ] |
| 87 | + }, |
| 88 | + { |
| 89 | + "cell_type": "code", |
| 90 | + "execution_count": null, |
| 91 | + "id": "1a28aa9c", |
| 92 | + "metadata": { |
| 93 | + "cq.autogen": "PlantedNoisyKXOR.solve_planted_symbolic" |
| 94 | + }, |
| 95 | + "outputs": [], |
| 96 | + "source": [ |
| 97 | + "from qualtran.bloqs.optimization.k_xor_sat import KXorInstance\n", |
| 98 | + "from qualtran.symbolics import HasLength\n", |
| 99 | + "\n", |
| 100 | + "n, m = sympy.symbols(\"n m\", positive=True, integer=True)\n", |
| 101 | + "k = sympy.symbols(\"k\", positive=True, integer=True, even=True)\n", |
| 102 | + "c = sympy.symbols(\"c\", positive=True, integer=True)\n", |
| 103 | + "ell = c * k\n", |
| 104 | + "rho = sympy.Symbol(r\"\\rho\", positive=True, real=True)\n", |
| 105 | + "\n", |
| 106 | + "inst = KXorInstance.symbolic(n, m, k)\n", |
| 107 | + "zeta = 1 / ln(n)\n", |
| 108 | + "solve_planted_symbolic = PlantedNoisyKXOR(\n", |
| 109 | + " inst_guide=inst.subset(HasLength((1 - zeta) * m)),\n", |
| 110 | + " inst_solve=inst.subset(HasLength(zeta * m)),\n", |
| 111 | + " ell=ell,\n", |
| 112 | + " rho=rho,\n", |
| 113 | + ")" |
| 114 | + ] |
| 115 | + }, |
| 116 | + { |
| 117 | + "cell_type": "code", |
| 118 | + "execution_count": null, |
| 119 | + "id": "2df9b4ea", |
| 120 | + "metadata": { |
| 121 | + "cq.autogen": "PlantedNoisyKXOR.solve_planted" |
| 122 | + }, |
| 123 | + "outputs": [], |
| 124 | + "source": [ |
| 125 | + "from qualtran.bloqs.optimization.k_xor_sat import KXorInstance\n", |
| 126 | + "\n", |
| 127 | + "rng = np.random.default_rng(42)\n", |
| 128 | + "n, m, k = 50, 1000, 4\n", |
| 129 | + "ell = k\n", |
| 130 | + "rho = 0.8\n", |
| 131 | + "\n", |
| 132 | + "inst = KXorInstance.random_instance(n, m, k, planted_advantage=rho, rng=rng)\n", |
| 133 | + "solve_planted = PlantedNoisyKXOR.from_inst(inst, ell=ell, rho=rho, zeta=0.1, rng=rng)" |
| 134 | + ] |
| 135 | + }, |
| 136 | + { |
| 137 | + "cell_type": "markdown", |
| 138 | + "id": "505c1e9c", |
| 139 | + "metadata": { |
| 140 | + "cq.autogen": "PlantedNoisyKXOR.graphical_signature.md" |
| 141 | + }, |
| 142 | + "source": [ |
| 143 | + "#### Graphical Signature" |
| 144 | + ] |
| 145 | + }, |
| 146 | + { |
| 147 | + "cell_type": "code", |
| 148 | + "execution_count": null, |
| 149 | + "id": "2ead66fe", |
| 150 | + "metadata": { |
| 151 | + "cq.autogen": "PlantedNoisyKXOR.graphical_signature.py" |
| 152 | + }, |
| 153 | + "outputs": [], |
| 154 | + "source": [ |
| 155 | + "from qualtran.drawing import show_bloqs\n", |
| 156 | + "show_bloqs([solve_planted_symbolic, solve_planted],\n", |
| 157 | + " ['`solve_planted_symbolic`', '`solve_planted`'])" |
| 158 | + ] |
| 159 | + }, |
| 160 | + { |
| 161 | + "cell_type": "markdown", |
| 162 | + "id": "bd068fb3", |
| 163 | + "metadata": { |
| 164 | + "cq.autogen": "PlantedNoisyKXOR.call_graph.md" |
| 165 | + }, |
| 166 | + "source": [ |
| 167 | + "### Call Graph" |
| 168 | + ] |
| 169 | + }, |
| 170 | + { |
| 171 | + "cell_type": "code", |
| 172 | + "execution_count": null, |
| 173 | + "id": "946fca15", |
| 174 | + "metadata": { |
| 175 | + "cq.autogen": "PlantedNoisyKXOR.call_graph.py" |
| 176 | + }, |
| 177 | + "outputs": [], |
| 178 | + "source": [ |
| 179 | + "from qualtran.resource_counting.generalizers import ignore_split_join\n", |
| 180 | + "solve_planted_symbolic_g, solve_planted_symbolic_sigma = solve_planted_symbolic.call_graph(max_depth=1, generalizer=ignore_split_join)\n", |
| 181 | + "show_call_graph(solve_planted_symbolic_g)\n", |
| 182 | + "show_counts_sigma(solve_planted_symbolic_sigma)" |
| 183 | + ] |
| 184 | + }, |
| 185 | + { |
| 186 | + "cell_type": "code", |
| 187 | + "execution_count": 13, |
| 188 | + "id": "2c8e9045-060a-4386-99be-5af7ee653fd6", |
| 189 | + "metadata": {}, |
| 190 | + "outputs": [ |
| 191 | + { |
| 192 | + "data": { |
| 193 | + "text/markdown": [ |
| 194 | + "#### Counts totals:\n", |
| 195 | + " - `Adjoint(subbloq=GuidedHamiltonianPhaseEstimation)`: $\\displaystyle \\left\\lceil{\\frac{202.020202020202 c^{0.5} k^{0.5} \\left(c k\\right)^{\\frac{c k}{2}}}{Part_{k}(\\ell)^{0.5} \\rho^{0.5} \\left(\\frac{\\left(\\frac{m \\left(1 - \\frac{1}{\\operatorname{log}_{2}{\\left(n \\right)}}\\right) + \\frac{m}{\\operatorname{log}_{2}{\\left(n \\right)}}}{{\\binom{n}{k}}}\\right)^{c} \\left(\\frac{\\rho^{2} m}{\\left(m \\left(1 - \\frac{1}{\\operatorname{log}_{2}{\\left(n \\right)}}\\right) + \\frac{m}{\\operatorname{log}_{2}{\\left(n \\right)}}\\right) \\operatorname{log}_{2}{\\left(n \\right)}}\\right)^{c}}{\\log{\\left(n \\right)}^{2}}\\right)^{0.5}}}\\right\\rceil$\n", |
| 196 | + " - `GuidedHamiltonianPhaseEstimation`: $\\displaystyle \\left\\lceil{\\frac{202.020202020202 c^{0.5} k^{0.5} \\left(c k\\right)^{\\frac{c k}{2}}}{Part_{k}(\\ell)^{0.5} \\rho^{0.5} \\left(\\frac{\\left(\\frac{m \\left(1 - \\frac{1}{\\operatorname{log}_{2}{\\left(n \\right)}}\\right) + \\frac{m}{\\operatorname{log}_{2}{\\left(n \\right)}}}{{\\binom{n}{k}}}\\right)^{c} \\left(\\frac{\\rho^{2} m}{\\left(m \\left(1 - \\frac{1}{\\operatorname{log}_{2}{\\left(n \\right)}}\\right) + \\frac{m}{\\operatorname{log}_{2}{\\left(n \\right)}}\\right) \\operatorname{log}_{2}{\\left(n \\right)}}\\right)^{c}}{\\log{\\left(n \\right)}^{2}}\\right)^{0.5}}}\\right\\rceil + 1$\n", |
| 197 | + " - `MultiControlZ`: $\\displaystyle \\left\\lceil{\\frac{202.020202020202 c^{0.5} k^{0.5} \\left(c k\\right)^{\\frac{c k}{2}}}{Part_{k}(\\ell)^{0.5} \\rho^{0.5} \\left(\\frac{\\left(\\frac{m \\left(1 - \\frac{1}{\\operatorname{log}_{2}{\\left(n \\right)}}\\right) + \\frac{m}{\\operatorname{log}_{2}{\\left(n \\right)}}}{{\\binom{n}{k}}}\\right)^{c} \\left(\\frac{\\rho^{2} m}{\\left(m \\left(1 - \\frac{1}{\\operatorname{log}_{2}{\\left(n \\right)}}\\right) + \\frac{m}{\\operatorname{log}_{2}{\\left(n \\right)}}\\right) \\operatorname{log}_{2}{\\left(n \\right)}}\\right)^{c}}{\\log{\\left(n \\right)}^{2}}\\right)^{0.5}}}\\right\\rceil$\n", |
| 198 | + " - `ZGate`: $\\displaystyle \\left\\lceil{\\frac{202.020202020202 c^{0.5} k^{0.5} \\left(c k\\right)^{\\frac{c k}{2}}}{Part_{k}(\\ell)^{0.5} \\rho^{0.5} \\left(\\frac{\\left(\\frac{m \\left(1 - \\frac{1}{\\operatorname{log}_{2}{\\left(n \\right)}}\\right) + \\frac{m}{\\operatorname{log}_{2}{\\left(n \\right)}}}{{\\binom{n}{k}}}\\right)^{c} \\left(\\frac{\\rho^{2} m}{\\left(m \\left(1 - \\frac{1}{\\operatorname{log}_{2}{\\left(n \\right)}}\\right) + \\frac{m}{\\operatorname{log}_{2}{\\left(n \\right)}}\\right) \\operatorname{log}_{2}{\\left(n \\right)}}\\right)^{c}}{\\log{\\left(n \\right)}^{2}}\\right)^{0.5}}}\\right\\rceil$" |
| 199 | + ], |
| 200 | + "text/plain": [ |
| 201 | + "<IPython.core.display.Markdown object>" |
| 202 | + ] |
| 203 | + }, |
| 204 | + "metadata": {}, |
| 205 | + "output_type": "display_data" |
| 206 | + } |
| 207 | + ], |
| 208 | + "source": [ |
| 209 | + "_, sigma = solve_planted_symbolic.call_graph(max_depth=2, generalizer=ignore_split_join)\n", |
| 210 | + "show_counts_sigma(sigma) # inverse of Eq. 150" |
| 211 | + ] |
| 212 | + } |
| 213 | + ], |
| 214 | + "metadata": { |
| 215 | + "kernelspec": { |
| 216 | + "display_name": "Python 3 (ipykernel)", |
| 217 | + "language": "python", |
| 218 | + "name": "python3" |
| 219 | + }, |
| 220 | + "language_info": { |
| 221 | + "codemirror_mode": { |
| 222 | + "name": "ipython", |
| 223 | + "version": 3 |
| 224 | + }, |
| 225 | + "file_extension": ".py", |
| 226 | + "mimetype": "text/x-python", |
| 227 | + "name": "python", |
| 228 | + "nbconvert_exporter": "python", |
| 229 | + "pygments_lexer": "ipython3", |
| 230 | + "version": "3.11.9" |
| 231 | + } |
| 232 | + }, |
| 233 | + "nbformat": 4, |
| 234 | + "nbformat_minor": 5 |
| 235 | +} |
0 commit comments