##// END OF EJS Templates
Merge branch 'stdin'...
Merge branch 'stdin' Changes stdin channel from REQ-REQ to ROUTER-DEALER, fixing the round-robin load-balancing of stdin_requests across frontends. stdin_requests now go to the client that made the execute_request that prompted the stdin request. stdin_requests from frontends that do not support stdin will raise an error, rather than hanging on input that will never arrive. reviewed by @fperez closes #673

File last commit:

r4637:d919e2ec
r4954:6e92ffd9 merge
Show More
grovers.ipynb
139 lines | 24.3 KiB | text/plain | TextLexer
Brian E. Granger
Converting notebooks to JSON format.
r4634 {
"nbformat": 2,
Brian E. Granger
Implemented metadata for notebook format.
r4637 "metadata": {
"name": "grovers"
},
Brian E. Granger
Converting notebooks to JSON format.
r4634 "worksheets": [
{
"cells": [
{
"source": "<h1>Grover's Algorithm</h1>",
"cell_type": "markdown"
},
{
"cell_type": "code",
"language": "python",
"outputs": [],
"collapsed": true,
"prompt_number": 1,
"input": "%load_ext sympyprinting"
},
{
"cell_type": "code",
"language": "python",
"outputs": [],
"collapsed": true,
"prompt_number": 2,
"input": "from sympy import sqrt, symbols, Rational\nfrom sympy import expand, Eq, Symbol, simplify, exp, sin\nfrom sympy.physics.quantum import *\nfrom sympy.physics.quantum.qubit import *\nfrom sympy.physics.quantum.gate import *\nfrom sympy.physics.quantum.grover import *\nfrom sympy.physics.quantum.qft import QFT, IQFT, Fourier\nfrom sympy.physics.quantum.circuitplot import circuit_plot"
},
{
"cell_type": "code",
"language": "python",
"outputs": [],
"collapsed": true,
"prompt_number": 3,
"input": "nqubits = 3\n"
},
{
"source": "Grover's algorithm is a quantum algorithm which searches an unordered database (inverts a function).<br/>\nProvides polynomial speedup over classical brute-force search ($O(\\sqrt{N}) vs. O(N))$ ",
"cell_type": "markdown"
},
{
"source": "Define a black box function that returns True if it is passed the state we are searching for.",
"cell_type": "markdown"
},
{
"cell_type": "code",
"language": "python",
"outputs": [],
"collapsed": true,
"prompt_number": 4,
"input": "def black_box(qubits):\n return True if qubits == IntQubit(1, qubits.nqubits) else False\n"
},
{
"source": "Build a uniform superposition state to start the search.",
"cell_type": "markdown"
},
{
"cell_type": "code",
"language": "python",
"outputs": [
{
"output_type": "pyout",
"latex": "$$\\frac{1}{4} \\sqrt{2} {\\left|0\\right\\rangle } + \\frac{1}{4} \\sqrt{2} {\\left|1\\right\\rangle } + \\frac{1}{4} \\sqrt{2} {\\left|2\\right\\rangle } + \\frac{1}{4} \\sqrt{2} {\\left|3\\right\\rangle } + \\frac{1}{4} \\sqrt{2} {\\left|4\\right\\rangle } + \\frac{1}{4} \\sqrt{2} {\\left|5\\right\\rangle } + \\frac{1}{4} \\sqrt{2} {\\left|6\\right\\rangle } + \\frac{1}{4} \\sqrt{2} {\\left|7\\right\\rangle }$$",
"prompt_number": 5,
"png": "iVBORw0KGgoAAAANSUhEUgAAAtoAAAAkCAYAAAC36Z1zAAAABHNCSVQICAgIfAhkiAAADKdJREFU\neJztnX3MHEUdxz9tH6C0WMqbtlrUBAHfeGlAtIDyWBGCilBrsFEIGEHhIYBgfGlQU6GKhmA1JChB\nBQISEKqgpuILoQYQIiBIBVE0eRAFCtQACuWltv7x280zN7t3t3u7tzN39/0km7ubndvdfp5f52Zm\nZ2ZBCCGEEEIIIYQQQgghhBDV2VLDJsrxGuQ9BPLePHIeBnkPg7w3j5yHYWC9vw6Y2fA5rwN2bPic\nMSHnYZD35pHzMMh7GOS9eeQ8DCPvfXqBPAuAjwJ3AfP6ezktLAQeBv7d4DljQc7DIO/NI+dhkPcw\nyHvzyHkY5L0ERwD7YN3or2/wvFdi3f+jiJyHQd6bR87DIO9hkPfmkfMwyHvCWIE8v+j7VWTZA3gO\n+FeAc8eAnIdB3ptHzsMg72GQ9+aR8zDIew802Sq5BNi9oXPFjJyHQd6bR87DIO9hkPfmkfMwjLz3\nImO0m2ZXbOD8Q4HOf3yg84YktHOQ91CMmnc5D4O8h0Hem0fOwxCt9yJDR5rmM8AFHfbvDZyIDbS/\nE/gpcH9Ovn2S1z966ccBB2AD5R8DVgNPOvu3wmbJPlz2wgeYbs6huve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9kXOzlx5LvId2DvWW\nMdOxSXl5T0GNxTmE9153rG+Fle3P5OzL9V506MgMbFHwdQXzF6FsgD5O/hN42tGuMAB7nOZkm329\nBidYAeMXMr0Sg3Oox3uRY8j7FGWdQ9Z70WPE4D0G51BvGfN0suURg3OIw3sdse7yJO1XH5H3Ker2\nDrakXx4xeI/BOdRbxmwmv5INcTiHOLzXHesvk1/JhmreOQnrAV5L8XU0R5FZZBeM7xU5L468h6Eu\n73JeHMV6GOQ9DCpjmkexXjNFerQXYq2m9X2+lmHg+ZqOI+flkPcw1OFdzsuhWA+DvIdBZUzzKNZr\nZnqX/TOxVsia/l+KSJDzMMh788h5GOQ9DPLePHIeBnl3mNFl/xnADtiszYOxx2DOxsbvPNTfSxtZ\n5DwM8t48ch4GeQ+DvDePnIdB3iswyQiPswnEJHIegknkvWkmkfMQTCLvIZhE3ptmEjkPwSQj7L3b\n0JGUOdjSLDsBR9J5qRRRD3IeBnlvHjkPg7yHQd6bR87DIO+UezLkeuCI5P2mPlyLyCLnYZD35pHz\nMMh7GOS9eeQ8DPIuhBBCCCGEEEIIIYQQQgghhBBCCCGEEEIIIYQQojb+D/rKtnnTRosYAAAAAElF\nTkSuQmCC\n",
"text": "\u23bd\u23bd\u23bd \u23bd\u23bd\u23bd \u23bd\u23bd\u23bd \u23bd\u23bd\u23bd \u23bd\u23bd\u23bd \u23bd\u23bd\u23bd \u23bd\u23bd\u23bd \n\u2572\u2571 2 \u22c5\u27580\u27e9 \u2572\u2571 2 \u22c5\u27581\u27e9 \u2572\u2571 2 \u22c5\u27582\u27e9 \u2572\u2571 2 \u22c5\u27583\u27e9 \u2572\u2571 2 \u22c5\u27584\u27e9 \u2572\u2571 2 \u22c5\u27585\u27e9 \u2572\u2571 2 \u22c5\n\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500 + \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500 + \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500 + \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500 + \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500 + \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500 + \u2500\u2500\u2500\u2500\u2500\u2500\n 4 4 4 4 4 4 4 \n\n \u23bd\u23bd\u23bd \n\u27586\u27e9 \u2572\u2571 2 \u22c5\u27587\u27e9\n\u2500\u2500\u2500 + \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\n 4"
}
],
"collapsed": false,
"prompt_number": 5,
"input": "psi = superposition_basis(nqubits); psi\n"
},
{
"cell_type": "code",
"language": "python",
"outputs": [],
"collapsed": true,
"prompt_number": 6,
"input": "v = OracleGate(nqubits, black_box)\n"
},
{
"source": "Perform two iterations of Grover's algorithm. Each iteration, the amplitude of the target state increases.",
"cell_type": "markdown"
},
{
"cell_type": "code",
"language": "python",
"outputs": [
{
"output_type": "pyout",
"latex": "$$\\frac{1}{8} \\sqrt{2} {\\left|0\\right\\rangle } + \\frac{5}{8} \\sqrt{2} {\\left|1\\right\\rangle } + \\frac{1}{8} \\sqrt{2} {\\left|2\\right\\rangle } + \\frac{1}{8} \\sqrt{2} {\\left|3\\right\\rangle } + \\frac{1}{8} \\sqrt{2} {\\left|4\\right\\rangle } + \\frac{1}{8} \\sqrt{2} {\\left|5\\right\\rangle } + \\frac{1}{8} \\sqrt{2} {\\left|6\\right\\rangle } + \\frac{1}{8} \\sqrt{2} {\\left|7\\right\\rangle }$$",
"prompt_number": 7,
"png": "iVBORw0KGgoAAAANSUhEUgAAAtoAAAAkCAYAAAC36Z1zAAAABHNCSVQICAgIfAhkiAAADOJJREFU\neJztnXusHFUZwH9tb6EUKKVQbbGoCRTw0VeKSAHtFSuk+ADE1KqQIqLCJSiP+GhAU6GKBrGaJiii\nAuFhEWqLmloVBAMIERCkgqiQiCiPQlXQWlqw9Y9vJnvmzOzuzM7s+WZ3v1+y2btnzs7s/d3vnp1z\n5jtnwDAMw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YhmEYhmEYhmEYhmFUyv8B4/u7khlDVCAAAAAA\nSUVORK5CYII=\n",
"text": "\u23bd\u23bd\u23bd \u23bd\u23bd\u23bd \u23bd\u23bd\u23bd \u23bd\u23bd\u23bd \u23bd\u23bd\u23bd \u23bd\u23bd\u23bd \u23bd\u23bd\n\u2572\u2571 2 \u22c5\u27580\u27e9 5\u22c5\u2572\u2571 2 \u22c5\u27581\u27e9 \u2572\u2571 2 \u22c5\u27582\u27e9 \u2572\u2571 2 \u22c5\u27583\u27e9 \u2572\u2571 2 \u22c5\u27584\u27e9 \u2572\u2571 2 \u22c5\u27585\u27e9 \u2572\u2571 2\n\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500 + \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500 + \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500 + \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500 + \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500 + \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500 + \u2500\u2500\u2500\u2500\n 8 8 8 8 8 8 \n\n\u23bd \u23bd\u23bd\u23bd \n \u22c5\u27586\u27e9 \u2572\u2571 2 \u22c5\u27587\u27e9\n\u2500\u2500\u2500\u2500\u2500 + \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\n8 8"
}
],
"collapsed": false,
"prompt_number": 7,
"input": "iter1 = qapply(grover_iteration(psi, v)); iter1\n"
},
{
"cell_type": "code",
"language": "python",
"outputs": [
{
"output_type": "pyout",
"latex": "$$- \\frac{1}{16} \\sqrt{2} {\\left|0\\right\\rangle } + \\frac{11}{16} \\sqrt{2} {\\left|1\\right\\rangle } - \\frac{1}{16} \\sqrt{2} {\\left|2\\right\\rangle } - \\frac{1}{16} \\sqrt{2} {\\left|3\\right\\rangle } - \\frac{1}{16} \\sqrt{2} {\\left|4\\right\\rangle } - \\frac{1}{16} \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SfzZESNV4dMNEcQ/l/GfPh07Ly3+cqv6zPEG8QQDyH6Pu68Ej5K8c0u0PhioMqn+Af+ak6/vf\nSp3+19E8VC6L3Meps+4vOoZc/+PZKFibvNJumSyHY49sXghsDdyPrc4giin7AIwUxcQPufdF/n2R\nf1/k3xf590Puu8BrovF8rEv7VOzu92VYS+6rTsczURivdfpBMfFE7n2Rf1/k3xf590X+/ZD7gLJP\nWavKeqy7Jh0OcxNwrNOxCEMx8UPufZF/X+TfF/n3Rf79kPsAr0bBGmysa8o6WtcUFr1FMfFD7n2R\nf1/k3xf590X+/ZD7AK9GwWU0r986F5vgIfxQTPyQe1/k3xf590X+fZF/P+Q+oBdzCqZiS0JluRh4\nNfZwkQewB1ss6sGxCEMx8UPufZF/X+TfF/n3Rf79kPsOGM/nFOwALMYeFjEZuAP4FrY+c8psLFD3\ntJQW44Fi4ofc+yL/vsi/L/Lvi/z7IfdCCCGEEEIIIYQQQgghhBBCCCGEEEIIIYQQQgghhBBt+D/S\nzSfShSQN5wAAAABJRU5ErkJggg==\n",
"text": "\u23bd\u23bd\u23bd \u23bd\u23bd\u23bd \u23bd\u23bd\u23bd \u23bd\u23bd\u23bd \u23bd\u23bd\u23bd \u23bd\u23bd\u23bd \n \u2572\u2571 2 \u22c5\u27580\u27e9 11\u22c5\u2572\u2571 2 \u22c5\u27581\u27e9 \u2572\u2571 2 \u22c5\u27582\u27e9 \u2572\u2571 2 \u22c5\u27583\u27e9 \u2572\u2571 2 \u22c5\u27584\u27e9 \u2572\u2571 2 \u22c5\u27585\u27e9 \u2572\n- \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500 + \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500 - \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500 - \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500 - \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500 - \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500 - \u2500\n 16 16 16 16 16 16 \n\n \u23bd\u23bd\u23bd \u23bd\u23bd\u23bd \n\u2571 2 \u22c5\u27586\u27e9 \u2572\u2571 2 \u22c5\u27587\u27e9\n\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500 - \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\n 16 16"
}
],
"collapsed": false,
"prompt_number": 8,
"input": "iter2 = qapply(grover_iteration(iter1, v)); iter2\n"
},
{
"source": "A single shot measurement is performed to retrieve the target state.",
"cell_type": "markdown"
},
{
"cell_type": "code",
"language": "python",
"outputs": [
{
"output_type": "pyout",
"latex": "$${\\left|001\\right\\rangle }$$",
"prompt_number": 9,
"png": "iVBORw0KGgoAAAANSUhEUgAAACkAAAATCAYAAAANgSQ9AAAABHNCSVQICAgIfAhkiAAAAahJREFU\nSInt1rtrFUEcxfEPQeMr6DXiC3yksFHRRiQoiHVCKiuxyh9gYyMWVhaCooKttZXYiEZQ0yhib7AR\ng5GA+CgUITe+IFrMBMa9e/fO3NZ8YZjZ8zu7e3Z3dnZZoYgL3QqrkvEZPMV7tHAdbXzBWtzC28r+\nub5lNuIJTmOuUmtjGz43XckkRuJ4GlcrtVdYX9kn1zeIE3iOP9hXc/4tONcUMA05Gg+0P6mtw3dc\nTrRcXwv3hTt+ryEkXMJATsi7mK+pP8JMsp3rS7nYI+RxjFfFutRH8KZGn8Uh4bGU+Ep4EYP2DLkd\nCzV6O/Y7Cn2lzGNvKlRDbhLmVVsny1qrwNcPDzDRFPI3lmKrsjr2SwW+fpjAVFPIRd3XuA2x/1Dg\n64cRvEuFujk5g801+lDsPxb6SjgmvDz/0C3k7hr9qPDm/ij0lTCGhzkhX+IA9iTaVhzGtT58uQzj\nqx5zeVKYD4N4hptJ7bzwTV+TaLm+lBvCYt6xFuKssKx1kP5gLOJXbKeET9ttfMMunMTPxJ/rI/xU\n7MTBuP0Yr3EHV6I2hE9dLm6F/4e/u+tyeF0qLvsAAAAASUVORK5CYII=\n",
"text": "\u2758001\u27e9"
}
],
"collapsed": false,
"prompt_number": 9,
"input": "measure_all_oneshot(iter2)\n"
}
]
}
]
}