Skip to content
Permalink
Branch: master
Find file Copy path
Find file Copy path
Fetching contributors…
Cannot retrieve contributors at this time
740 lines (739 sloc) 105 KB
{
"cells": [
{
"cell_type": "markdown",
"metadata": {
"collapsed": true
},
"source": [
"In this notebook, we implement the Deutsch-Jozsa algorithm using Qiskit. Recall that the algorithm is figuring out whether a given binary function\n",
"$$\n",
"f \\colon \\{0,1\\}^n \\rightarrow \\{0,1\\}\n",
"$$\n",
"is balanced or constant. So let us first choose a reasonably simple function f and implement the corresponding oracle. Basically the easiest choice is probably $n = 2$ and\n",
"$$\n",
"f(x_0, x_1) = x_0 \\oplus x_1\n",
"$$\n",
"What is the oracle $U_f$? The oracle is specified by\n",
"$$\n",
"U_f |x \\rangle |y \\rangle = |x \\rangle |y \\oplus f(x) \\rangle\n",
"$$\n",
"So the third qubit is inverted if f is equal to one and left unchanged otherwise. Using the definition of f, we see that the third qubit is inverted if the first two qubits are different and left unchanged if they are equal.\n",
"This is easily implemented using two CNOT gates"
]
},
{
"cell_type": "code",
"execution_count": 1,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": [
"from qiskit import QuantumRegister, QuantumCircuit, ClassicalRegister\n",
"from qiskit.tools.visualization import matplotlib_circuit_drawer as drawer\n",
"from qiskit.tools.visualization import plot_histogram\n",
"from qiskit import Aer\n",
"from qiskit import compile, execute\n",
"from qiskit import IBMQ\n",
"import numpy as np\n",
"%matplotlib inline\n",
"my_style = {'cregbundle': True}"
]
},
{
"cell_type": "code",
"execution_count": 2,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": [
"#####################################\n",
"# Create the oracle. We assume that #\n",
"# our quantum register has three #\n",
"# qubits. #\n",
"#####################################\n",
"def createOracleBalanced(q,c):\n",
" circuit = QuantumCircuit(q,c)\n",
" circuit.cx(q[0], q[2])\n",
" circuit.cx(q[1], q[2])\n",
" circuit.barrier(q)\n",
" return circuit\n",
"\n",
"\n",
"\n",
"#####################################\n",
"# Create a constant oracle #\n",
"#####################################\n",
"def createOracleConstant(q,c):\n",
" circuit = QuantumCircuit(q,c)\n",
" circuit.x(q[2])\n",
" circuit.barrier(q)\n",
" return circuit"
]
},
{
"cell_type": "code",
"execution_count": 3,
"metadata": {},
"outputs": [
{
"data": {
"image/png": "iVBORw0KGgoAAAANSUhEUgAAAPEAAADRCAYAAAAdZ1Q/AAAABHNCSVQICAgIfAhkiAAAAAlwSFlz\nAAALEgAACxIB0t1+/AAAADl0RVh0U29mdHdhcmUAbWF0cGxvdGxpYiB2ZXJzaW9uIDMuMC4yLCBo\ndHRwOi8vbWF0cGxvdGxpYi5vcmcvOIA7rQAAFmBJREFUeJzt3X9M1Pf9B/DnB2qHU47jh4iF3llp\n3Te6r/Y8+ZKmDrq2KP2Knkq1zaIdscZETTYjo5C52c5fObTrQrJuGbUFW6FfyVwHRoPWlpEV9VqL\nYG2TricKtboCRrgTrD/uXt8/nJeigCCf43NveT6SS7z3vX2/nyhPPp/73AGaiAiISFlhRgcgoqFh\niYkUxxITKY4lJlIcS0ykOJaYSHEsMZHiWGIixbHERIpjiYkUxxITKY4lJlIcS0ykOJaYSHEsMZHi\nWGIixbHERIpjiYkUxxITKY4lJlIcS0ykOJaYSHEsMZHiWGIixbHERIpjiYkUxxITKY4lJlIcS0yk\nOJaYSHEsMZHiWGIixbHERIpjiYkUxxITKY4lJlLciCpxaWkpnnjiiQHPt9vtOHDgQPACKaqrqwvv\nvvsuXnvtNezcuRMdHR1GRxrRRlSJb+Xz+ZCXl4dx48YhMjIS2dnZaG9vDzzucDhQVVVlYMLQIiLY\ntm0bJkyYgJ/97GfIzc1FTk4OEhISUFBQAJ/PZ3TEEWlEl9jpdKKyshIulwtnz54FACxbtizwOEvc\n08aNG5Gfnw+v19tj/MqVKygsLMSqVasMSjbCSQjYvXu3JCcny5gxYyQjI0PWrVsnzz77rO77lJSU\nSHp6euC+xWKRHTt2BO673W4BIGfOnAmMWa1WOXbsmO5ZVHPu3DkJDw8XAP3eGhoajI464hh+JN65\ncydyc3NRVlYGr9eLrKw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HLqvHRkZCeDGNwh8X0dH\nx7B9l09//0nBcPT4F/j7wY/w4pL/xSMPJQ3r3qQvZU6n29vbER0dHZTTPrPZDIvFgvr6+sBYU1MT\nPB7PgE/JVcLnwvcWZU6nT548CZvNhr/97W+YO3cuPB4PXC4X5syZo8v6W7Zswdtvv43q6mrExsbi\nxRdfhNfrRXV1tS7r3wlPp6k//Z6piUJKS0tl8uTJMmbMGElISJBf//rXfc7dsmWLTJkyZcBrX79+\nXXJzcyU2NlbGjh0rCxculLa2Nj1ih5Rr167L1td3yZ/e+bv4/X6j45AOlDkSkz74XPjeo8yFLdLH\nf//XJIgInwvfQ3gkJlKcMleniah3LDGR4lhiIsWxxESKY4mJFMcSEymOJSZSHEtMpDiWmEhxLDGR\n4lhiIsWxxESKY4mJFMcSEymOJSZSHEtMpDiWmEhxLDGR4lhiIsWxxESKY4mJFMcSEymOJSZS3P8D\nqukNVbKk3KEAAAAASUVORK5CYII=\n",
"text/plain": [
"<Figure size 301x258.86 with 1 Axes>"
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"#\n",
"# Try it out\n",
"#\n",
"q = QuantumRegister(3,\"q\")\n",
"c = ClassicalRegister(3,\"c\")\n",
"circuit = createOracleBalanced(q,c)\n",
"drawer(circuit, style = my_style)"
]
},
{
"cell_type": "code",
"execution_count": 4,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"| 000 > --->> | 000 >\n",
"| 001 > --->> | 101 >\n",
"| 010 > --->> | 110 >\n",
"| 011 > --->> | 011 >\n"
]
}
],
"source": [
"backend = Aer.get_backend('unitary_simulator') \n",
"job = execute(circuit, backend)\n",
"#\n",
"# Print this as truth table\n",
"# \n",
"for i in range(2**2):\n",
" out = job.result().get_unitary()\n",
" print(\"|\", format(i, '03b'),\"> --->> |\", format(np.argmax(out.T[i]), '03b'),\">\")"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Now we get to the actual Deutsch-Jozsa algorithm. We use the version of the algorithm described in https://arxiv.org/abs/quant-ph/9708016. Here, the first step is to create the usual superposition state\n",
"$$\n",
"|\\psi \\rangle = \\frac{1}{2} \\sum_x |x \\rangle\n",
"$$\n",
"We know how to do this - we start with the fiducial state and apply a Hadamard gate to every qubit."
]
},
{
"cell_type": "code",
"execution_count": 5,
"metadata": {},
"outputs": [
{
"data": {
"image/png": "iVBORw0KGgoAAAANSUhEUgAAAMQAAADRCAYAAACTvR1DAAAABHNCSVQICAgIfAhkiAAAAAlwSFlz\nAAALEgAACxIB0t1+/AAAADl0RVh0U29mdHdhcmUAbWF0cGxvdGxpYiB2ZXJzaW9uIDMuMC4yLCBo\ndHRwOi8vbWF0cGxvdGxpYi5vcmcvOIA7rQAAEIlJREFUeJzt3W9MU/e/B/A3otOrtNTxNwKtAy+7\n8Q+0Y71E77aauIFOTCdsN3swDHHGJdsTYkMgcw/INk3FLdEH9z4gRnED8gvZxujiBt4tQnan66r8\nWq9ZsoTVFXUmgKG0YtCf5XsfbL+Tb+c/qqXn1L5fCQ/6PWfn86nz7fec00O/aUIIASICACxQuwEi\nLWEgiCQMBJGEgSCSMBBEEgaCSMJAEEkYCCIJA0EkYSCIJAwEkYSBIJIwEEQSBoJIwkAQSRgIIgkD\nQSRhIIgkDASRhIEgkjAQRBIGgkjCQBBJGAgiCQNBJGEgiCQL1W6A1NXY2Aiv15vwumazGYcOHUp4\n3QfhDJHivF5vwgOhRs254gxBMJvNGBwcTFi9jRs3JqxWrDhDEEkYCCIJA0EkYSCIJAwEkYSBIJIw\nEESSlApER0dHTPfAKyoqMDAwMH8NkeakVCD+KhKJoKmpCTk5OdDpdKirq8PExISy3W63w+Vyqdih\nNq1YsQJHjhyJGhNCQK/Xo7e3V6Wu4iOlA+F0OtHX1we3243Lly8DAOrr65XtDMSdrly5gqtXr8Js\nNkeN+/1+hMNhPPvssyp1Fh+aCERPTw9WrVqFjIwMVFVVweFw4LXXXpv3uu3t7WhubkZxcTEyMzPR\n1taG/v5+BAIBAEB5eTnS09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LvduHz5MgCgvr5e5a7m39n/+wVT4Wm88O/larei\nCUkXiB9++AGbNm2CXq+HwWCI26KI7e3taG5uRnFxMTIzM9HW1ob+/n4EAoG4HF+Lbt+O4NSZv8NU\nkIdVKwvUbkcTkioQn3/+ObZv3463334bY2NjuHTpEnbt2nXXfZ1OJ8rKyuZ03GAwiNHRUVRUVChj\nJSUl0Ov18Pl8celdi/45O7z4HxX81PpPSXNRPT09DZPJhCNHjuCVV16J67EvXboEo9EIv9+Pp556\nShk3mUzYt28f3njjjbjWu5uWA+3zXoP+4Gzefc9tSXPbdWhoCGlpabDb7XE/tk6nA/DHw2+yYDCY\nsKdB7/c/aT78+Pef8eXJ/8Wb//ky/vWpwoTW1rKkOWWamJjA8uXL52VqNxgMMBqNGB4eVsb8fj9C\nodCcT7uSCa8d7i1pTpkuXLgAi8WCL774Alu3bkUoFILb7UZ1dXVcjr9v3z588skn6O/vR1ZWFt58\n802Ew2H09/fH5fgPwlOmxLnvbCySSEdHhygtLRXLli0T+fn54t13373nvvv27ROrV6+e87Fv374t\nHA6HyMrKEhkZGWL79u1ifHw8Hm1ryj/+cVvs/69O8d+ffilmZ2fVbkdzkmaGoPjgtcP9Jc1FNcXH\nun8rhhCC1w73wBmCSJI0d5mIEoGBIJIwEEQSBoJIwkAQSRgIIgkDQSRhIIgkDASRhIEgkjAQRBIG\ngkjCQBBJGAgiCQNBJGEgiCQMBJGEgSCSMBBEEgaCSMJAEEkYCCIJA0Ek+X8QrAuTQ4z/EwAAAABJ\nRU5ErkJggg==\n",
"text/plain": [
"<Figure size 240.8x258.86 with 1 Axes>"
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"def createInitialState(circuit):\n",
" circuit.h(q[0])\n",
" circuit.h(q[1])\n",
" circuit.barrier(q)\n",
"\n",
" \n",
"q = QuantumRegister(3,\"q\")\n",
"c = ClassicalRegister(3,\"c\")\n",
"circuit = QuantumCircuit(q,c)\n",
"createInitialState(circuit)\n",
"drawer(circuit, style = my_style)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Next, we add an ancilla qubit that we initialize to one and apply the Hadamard to this ancilla qubit. The result will be the state\n",
"$$\n",
"|\\psi \\rangle = \\frac{1}{2\\sqrt{2}} \\sum_x |x , 0 \\rangle - |x, 1 \\rangle \n",
"$$"
]
},
{
"cell_type": "code",
"execution_count": 6,
"metadata": {},
"outputs": [
{
"data": {
"image/png": "iVBORw0KGgoAAAANSUhEUgAAAR8AAADRCAYAAAD1wrY9AAAABHNCSVQICAgIfAhkiAAAAAlwSFlz\nAAALEgAACxIB0t1+/AAAADl0RVh0U29mdHdhcmUAbWF0cGxvdGxpYiB2ZXJzaW9uIDMuMC4yLCBo\ndHRwOi8vbWF0cGxvdGxpYi5vcmcvOIA7rQAAE8RJREFUeJzt3X9sU3W/B/D3HMourF2xGyXQdXPj\n4g0D1jp6F7lKTVQml5ECE8MfQibiTNSYxblsAU0WDNghGjC512QhOHRbnuCPuRnJxtVsjVew6djT\nchcTk1nsHGK2kXWtU+ShO/cPH0+sE1xZ109L36+kf/R7zs7n0y5773t+9DRNURQFRERxdpt0A0SU\nmhg+RCSC4UNEIhg+RCSC4UNEIhg+RCSC4UNEIhg+RCSC4UNEIhg+RCSC4UNEIhg+RCSC4UNEIhg+\nRCSC4UNEIhg+RCSC4UNEIhg+RCSC4UNEIhg+RCSC4UNEIhg+RCSC4UNEIhg+RCSC4UNEIhg+RCRi\nnnQDJKu6uhoejyfudc1mM44cORL3upQ4OPNJcR6PJ+7hI1GTEg9nPgSz2Yze3t641XvggQfiVosS\nF2c+RCSC4UNEIhg+RCSC4UNEIhg+RCSC4UNEIhg+RCQipcKnubk5qmtMSkpK0N3dPXcNEaWwlAqf\nPwqHw6itrUVOTg40Gg0qKiowNjamLrfb7ejs7BTsMDEtXboUx44dixhTFAVarRbt7e1CXVGySenw\ncTgc6OjogMvlwvDwMABg586d6nKGz3QXL17EpUuXYDabI8Z9Ph9CoRDWrl0r1Bklm4QIn5MnT2L5\n8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UhLq6OhQUFCArKwuHDh1CV1cX/H5/TLafiK5dC6Pn7N+Rt8yA\n5fnLpNuhFJNU4fPBBx9g69ateOaZZzAyMoLvvvsOe/bs+dN1HQ4H1qxZM6PtBgIBDA0NoaSkRB0r\nLCyEVquF1+uNSe+J6LdZz0P/UcKrnSnukuaA8+TkJPLy8nDs2DFs2bIlptv+7rvvYDKZ4PP5cNdd\nd6njeXl5OHDgAB5//PGY1vsz9Y1Nc16DKN4cdVXXXZY0p9qdTifS0tJgt9tjvm2NRgPg1w9e/l4g\nEIjbp75v9EuaC1/+/St8dPp/8eRj/4l/vcsY19pEQBLtdo2NjWHRokVzsnug0+lgMpnQ39+vjvl8\nPgSDwRnvuiUTHuuhRJA0u10DAwOwWCz48MMPsWnTJgSDQbhcLpSVlcVk+wcOHMA777yDrq4u6PV6\nPPnkkwiFQujq6orJ9v8Kd7voVnTDGb2SRJqbm5UVK1YoCxcuVJYsWaLs3bv3uuseOHBAWbly5Yy3\nfe3aNaWmpkbR6/VKZmamsnXrVmV0dDQWbSeUf/zjmnLwv1qU/373I2Vqakq6HUphSTPzodjgsR5K\nFElzwJliY/W/FUBRFB7rIXGc+RCRiKQ520VEtxaGDxGJYPgQkQiGDxGJYPgQkQiGDxGJYPgQkQiG\nDxGJYPgQkQiGDxGJYPgQkQiGDxGJYPgQkQiGDxGJYPgQkQiGDxGJYPgQkQiGDxGJYPgQkQiGDxGJ\nYPgQkQiGDxGJYPgQkYj/BxllOluHJGm6AAAAAElFTkSuQmCC\n",
"text/plain": [
"<Figure size 361.2x258.86 with 1 Axes>"
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"def addAncilla(circuit):\n",
" circuit.x(q[2])\n",
" circuit.h(q[2])\n",
" circuit.barrier(q)\n",
"\n",
"addAncilla(circuit)\n",
"drawer(circuit, style = my_style)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Next we add $U_f$ to the circuit. This will result in the state\n",
"$$\n",
"\\frac{1}{\\sqrt{2^n}} (\\sum_x (-1)^{f(x)} |x\\rangle) \\otimes H|1\\rangle \n",
"$$"
]
},
{
"cell_type": "code",
"execution_count": 7,
"metadata": {},
"outputs": [
{
"data": {
"image/png": "iVBORw0KGgoAAAANSUhEUgAAAXoAAADRCAYAAADCDHkJAAAABHNCSVQICAgIfAhkiAAAAAlwSFlz\nAAALEgAACxIB0t1+/AAAADl0RVh0U29mdHdhcmUAbWF0cGxvdGxpYiB2ZXJzaW9uIDMuMC4yLCBo\ndHRwOi8vbWF0cGxvdGxpYi5vcmcvOIA7rQAAHNdJREFUeJzt3X9UU/f9P/BnxApTEkJBscoPB35Y\n6w8IYsZKW+PmAK34xV+gOx1OqbWtOseKFo7taZlOB7o5tbZz6FH8Af2MoQiuFlydMKc2J4rgsB57\nEAWhroiHmIgFNbnfP/oxa/xJIMlNLs/HOfcced+b9/vFrydv33nnRiYIggAiIpKsfmIXQEREjsWg\nJyKSOAY9EZHEMeiJiCSOQU9EJHEMeiIiiWPQExFJHIOeiEjiGPRERBLHoCcikjgGPRGRxDHoiYgk\njkFPRCRxDHoiIolj0BMRSRyDnohI4hj0REQSx6AnIpI4Bj0RkcQx6ImIJI5BT0QkcQx6IiKJY9AT\nEUkcg56ISOIY9EREEsegJyKSuP5iF0DiSk9PR01NjdPHValU2Lhxo9PHJeqLOKPv42pqapwe9GKM\nSdSXcUZPUKlUqKysdNp4EydOdNpYRMQZPRGR5DHoiYgkjkFPRCRxDHoiIolj0BMRSRyDnohI4hj0\nREQS16eCPj8/36Y93NHR0aioqHBcQUQSJAgC/vnPf2Ljxo344IMPUFdXJ3ZJfV6fCvr7mUwmrFix\nAoMHD4ZcLsesWbPQ1tZmOZ+UlISysjIRK3RNw4YNw/bt263aBEGAQqFASUmJSFWRK9BqtRg1ahQ0\nGg1+/etfY9myZRg7diwmTpyIK1euiF1en9Wngz4nJwelpaXQarVobm4GAKSmplrOM+gf1NLSgqtX\nr0KlUlm1NzQ0wGg0Yvz48SJVRmI7c+YMfvzjH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dOZmLHnnObbZXVlVVQSaTISkp\nye59y+VyAN/e9Ou79Hq90+7u+LhvkiN8fuYLHDj8L7ya8jL+5/uBTh2biJzLbZZu2tra4Ovr65Al\nBqVSieDgYFRXV1vaGhoaYDAYur384064Nk/Ut7jN0k1dXR2ioqKwf/9+TJ06FQaDAVqtFgkJCXbp\nf82aNdi9ezfKy8vh5+eHV199FUajEeXl5Xbp/0m4dENEvfG4VQG3CXoA2LVrF9auXYuWlhbI5XKk\npaVhzZo1D7127dq1KCgowLlz57rVt8lkQmZmJvLz89HV1YW4uDjk5eXB39/fnp+C6O7eNWF93v9C\nqfDGG6/8Pz4JS9QHuFXQU+9xbZ6o73GbJ2PJPsY+GwpBELg2T9SHcEZPRCRxbrPrhoiIeoZBT0Qk\ncQx6IiKJY9ATEUkcg56ISOIY9EREEsegJyKSOAY9EZHEMeiJiCSOQU9EJHEMeiIiiWPQExFJHIOe\niEjiGPRERBLHoCcikjgGPRGRxDHoiYgkjkFPRCRxDHoiIolj0BMRSRyDnohI4hj0REQSx6AnIpK4\n/w8wQrwazs9AFgAAAABJRU5ErkJggg==\n",
"text/plain": [
"<Figure size 481.6x258.86 with 1 Axes>"
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"circuit = circuit + (createOracleBalanced(q,c))\n",
"circuit.barrier(q)\n",
"drawer(circuit, style = my_style)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Next, we uncompute the ancillary qubit - we apply another Hadamard followed by a Pauli X gate. This will give us the state\n",
"$$\n",
"\\frac{1}{\\sqrt{2^n}} (\\sum_x (-1)^{f(x)} |x\\rangle) \\otimes |0\\rangle \n",
"$$"
]
},
{
"cell_type": "code",
"execution_count": 8,
"metadata": {},
"outputs": [
{
"data": {
"image/png": "iVBORw0KGgoAAAANSUhEUgAAAdQAAADRCAYAAAB1nUNrAAAABHNCSVQICAgIfAhkiAAAAAlwSFlz\nAAALEgAACxIB0t1+/AAAADl0RVh0U29mdHdhcmUAbWF0cGxv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3WULCwsxZcqUPvVrNpvR2tqK+Ph4R1tUVBQ0Gg0aGhqE1O6Nruyd/nJ6PJ+a\nREQ0QIq5KKm7uxsRERHYsmULHnjgAaF9nz17FuHh4WhubsaPf/xjR3tERATWrFmDX//610LHu578\nomK3j0FERANXmLf0uu2KuW2mpqYGKpUK6enpwvtWq9UAvn94/A+ZzWaPvY3lRr8gd/n0+GfYs/+f\neDTzfvzPj0M9OjYR0WCkmEO+nZ2dCAwMdMuhSa1Wi/DwcNTV1TnampubYbFY+nzYWEl47pSISDzF\nHPJtbGxEXFwc3nvvPcyZMwcWiwVGoxGpqalC+l+zZg127NiBqqoqBAUF4dFHH4XVakVVVZWQ/m+F\nh3yJiJThRkcUFROoALB9+3asXbsW7e3tUKvVyM7Oxpo1a6677Nq1a1FaWoqTJ0/2qW+bzYa8vDyU\nlJSgt7cXycnJKC4uRnBwsMgfQXaXL9uwvvh/odX44/FH/h8vRiIiEkRRgUoDx3OnRETuoZiLkkiM\nyT+NhCRJPHdKRCQY91CJiIgEUMxVvkRERN6MgUpERCQAA5WIiEgABioREZEADFQiIiIBGKhEREQC\nMFCJiIgEYKASEREJwEAlIiISgIFKREQkAAOViIhIAAYqERGRAAxUIiIiARioREREAjBQiYiIBGCg\nEhERCcBAJSIiEoCBSkREJAADlYiISAAGKhERkQAMVCIiIgEYqERERAIwUImIiAT4/yNIaeNYx4GU\nAAAAAElFTkSuQmCC\n",
"text/plain": [
"<Figure size 602x258.86 with 1 Axes>"
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"def uncomputeAncilla(circuit):\n",
" circuit.h(q[2])\n",
" circuit.x(q[2])\n",
" circuit.barrier(q)\n",
" \n",
"uncomputeAncilla(circuit)\n",
"drawer(circuit, style = my_style)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Finally, to return to the standard basis, we apply Hadamard gates on the first two qubits. We then measure the result."
]
},
{
"cell_type": "code",
"execution_count": 9,
"metadata": {},
"outputs": [
{
"data": {
"image/png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14I1RbZzIn09fX1GDJkCNLT0zF16lRR1339+nX4+PigpKQEw4YNM/YPGTIEGzdu\nxJw5c0QdryVJm9M6fQwiIiLqXCmJSx94n81ckf7kyZNQKBSIi4sTfd3Ozj+m6Fu3TK+GW1tbC6VS\n2dJDRNfaP1Jn+M+Fyzh87DMsmvUkftHGtVGIiMi2CYJgc0c0bLHmttjM4cWbN2/Czc2tU/4BXF1d\n4ePjg/z8fGNfSUkJdDqd2YcobQnP5SIi6l5sMbzYYs1tsZnDi0VFRQgNDcWHH36IyZMnQ6fTQaPR\nICYmRpT1b9y4Ee+++y5yc3Ph7u6ORYsWQa/XIzc3V5T1t4WHF4mIiGxfa0eubCZ0AcCePXuwadMm\nVFZWwtnZGQsXLsTGjRtbXHbTpk3IzMzEpUvNL7LWEoPBgMTERGRkZKCxsRETJ05EWloaPDw8xHwK\nsvvhBwO2pL0HV6UTlj39my75SYKIiMga2VTooo7juVxERETysJkT6UkcI4f7QhAEnstFREQkMe7p\nIiIiIpKAzXx7kYiIiMiWMXQRERERSYChi4iIiEgCDF1EREREEmDoIiIiIpIAQxcRERGRBBi6iIiI\niCTA0EVEREQkAYYuIiIiIgkwdBERERFJgKGLiIiISAIMXUREREQSYOgiIiIikgBDFxEREZEEGLqI\niIiIJMDQRURERCQBhi4iIiIiCTB0EREREUmAoYuIiIhIAgxdRERERBJg6CIiIiKSAEMXERERkQQY\nuoiIiIgk8P8Bqo6CEAKLl34AAAAASUVORK5CYII=\n",
"text/plain": [
"<Figure size 782.6x258.86 with 1 Axes>"
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"def addMeasurement(circuit):\n",
" circuit.h(q[0])\n",
" circuit.h(q[1])\n",
" circuit.barrier(q)\n",
" circuit.measure(q[0], c[0])\n",
" circuit.measure(q[1], c[1])\n",
" circuit.barrier(q)\n",
" \n",
"addMeasurement(circuit)\n",
"drawer(circuit, style = my_style)"
]
},
{
"cell_type": "code",
"execution_count": 10,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Status of backend: {'pending_jobs': 17, 'name': 'ibmqx4', 'operational': True}\n",
"Compiled qasm:\n",
" OPENQASM 2.0;\n",
"include \"qelib1.inc\";\n",
"qreg q[3];\n",
"creg c[3];\n",
"u2(0,3.14159265358979) q[1];\n",
"u2(0,3.14159265358979) q[0];\n",
"barrier q[0],q[1],q[2];\n",
"u3(1.57079632679490,3.14159265358979,3.14159265358979) q[2];\n",
"barrier q[0],q[1],q[2];\n",
"u2(0,3.14159265358979) q[1];\n",
"u2(0,3.14159265358979) q[0];\n",
"u2(0,3.14159265358979) q[2];\n",
"cx q[2],q[0];\n",
"cx q[2],q[1];\n",
"u2(0,3.14159265358979) q[0];\n",
"u2(0,3.14159265358979) q[1];\n",
"u2(0,3.14159265358979) q[2];\n",
"barrier q[0],q[1],q[2];\n",
"barrier q[0],q[1],q[2];\n",
"u3(1.57079632679490,1.22464679914735e-16,6.28318530717959) q[2];\n",
"barrier q[0],q[1],q[2];\n",
"u2(0,3.14159265358979) q[1];\n",
"u2(0,3.14159265358979) q[0];\n",
"barrier q[0],q[1],q[2];\n",
"barrier q[0],q[1],q[2];\n",
"measure q[0] -> c[0];\n",
"measure q[1] -> c[1];\n",
"\n"
]
}
],
"source": [
"#\n",
"# Now we are ready to execute the full circuit\n",
"#\n",
"IBMQ.load_accounts()\n",
"backend = IBMQ.get_backend('ibmqx4') \n",
"#backend = IBMQ.get_backend('ibmq_16_melbourne') \n",
"#backend = IBMQ.get_backend('ibmq_qasm_simulator') \n",
"#backend = Aer.get_backend(\"qasm_simulator\")\n",
"print(\"Status of backend: \", backend.status())\n",
"#\n",
"# Now we compile\n",
"#\n",
"from qiskit import compile\n",
"qobj = compile(circuit, backend=backend, shots=1024)\n",
"#\n",
"# Display compiled QASM. Note that this actually depends on the backend!\n",
"# \n",
"compiled_qasm = qobj.as_dict()['experiments'][0]['header']['compiled_circuit_qasm']\n",
"print(\"Compiled qasm:\\n\", compiled_qasm)\n",
"#\n",
"# and submit as a job\n",
"#\n",
"job = backend.run(qobj)"
]
},
{
"cell_type": "code",
"execution_count": 11,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Status @ 0 seconds\n",
"JobStatus.QUEUED\n",
"Position in queue: 17\n",
"Status @ 60 seconds\n",
"JobStatus.QUEUED\n",
"Position in queue: 16\n",
"Status @ 120 seconds\n",
"JobStatus.QUEUED\n",
"Position in queue: 13\n",
"Status @ 180 seconds\n",
"JobStatus.QUEUED\n",
"Position in queue: 13\n",
"Status @ 240 seconds\n",
"JobStatus.QUEUED\n",
"Position in queue: 12\n",
"Status @ 300 seconds\n",
"JobStatus.QUEUED\n",
"Position in queue: 12\n",
"Status @ 360 seconds\n",
"JobStatus.QUEUED\n",
"Position in queue: 11\n",
"Status @ 420 seconds\n",
"JobStatus.QUEUED\n",
"Position in queue: 10\n",
"Status @ 480 seconds\n",
"JobStatus.QUEUED\n",
"Position in queue: 10\n",
"Status @ 540 seconds\n",
"JobStatus.QUEUED\n",
"Position in queue: 9\n",
"Status @ 600 seconds\n",
"JobStatus.QUEUED\n",
"Position in queue: 9\n",
"Status @ 660 seconds\n",
"JobStatus.QUEUED\n",
"Position in queue: 8\n",
"Status @ 720 seconds\n",
"JobStatus.QUEUED\n",
"Position in queue: 8\n",
"Status @ 780 seconds\n",
"JobStatus.QUEUED\n",
"Position in queue: 7\n",
"Status @ 840 seconds\n",
"JobStatus.QUEUED\n",
"Position in queue: 7\n",
"Status @ 900 seconds\n",
"JobStatus.QUEUED\n",
"Position in queue: 6\n",
"Status @ 960 seconds\n",
"JobStatus.QUEUED\n",
"Position in queue: 6\n",
"Status @ 1020 seconds\n",
"JobStatus.QUEUED\n",
"Position in queue: 5\n",
"Status @ 1080 seconds\n",
"JobStatus.QUEUED\n",
"Position in queue: 4\n",
"Status @ 1140 seconds\n",
"JobStatus.QUEUED\n",
"Position in queue: 2\n",
"Status @ 1200 seconds\n",
"JobStatus.RUNNING\n",
"Position in queue: 0\n",
"JobStatus.DONE\n"
]
}
],
"source": [
"import time\n",
"lapse = 0\n",
"#\n",
"# Wait three seconds once, this should be good enough for the simulator in most cases\n",
"#\n",
"time.sleep(3)\n",
"interval = 60\n",
"while (job.status().name != 'DONE') and (job.status().name != 'CANCELLED') and (job.status().name != 'ERROR'):\n",
" print('Status @ {} seconds'.format(interval * lapse))\n",
" print(job.status())\n",
" print(\"Position in queue: \",job.queue_position())\n",
" time.sleep(interval)\n",
" lapse += 1\n",
"print(job.status())"
]
},
{
"cell_type": "code",
"execution_count": 12,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"{'000': 85, '001': 118, '010': 125, '011': 696}"
]
},
"execution_count": 12,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"result = job.result()\n",
"counts = result.get_counts()\n",
"counts"
]
},
{
"cell_type": "code",
"execution_count": 13,
"metadata": {},
"outputs": [
{
"data": {
"image/png": "iVBORw0KGgoAAAANSUhEUgAAAYgAAAEMCAYAAADeYiHoAAAABHNCSVQICAgIfAhkiAAAAAlwSFlz\nAAALEgAACxIB0t1+/AAAADl0RVh0U29mdHdhcmUAbWF0cGxvdGxpYiB2ZXJzaW9uIDMuMC4yLCBo\ndHRwOi8vbWF0cGxvdGxpYi5vcmcvOIA7rQAAH+hJREFUeJzt3X+cVXW97/HXWxBN8VcIRTMQPwYU\nkJFyQMwjhcYRtaBu5EUzUiPqJll2y/DkJeWcTnp8ZPVIOycyU+nqiJRKNcLppqh5JBiKQlBhQotB\nslFTj6YMo5/7x9roZrNg9mZm1p7ZvJ+PBw/W+u7v3vuzv+J+7/XruxQRmJmZFTqg3AWYmVn35IAw\nM7NUDggzM0vlgDAzs1QOCDMzS+WAMDOzVA4IMzNL5YAwM7NUDggzM0vlgDAzs1S9s3ojSVOB7wC9\ngBsi4qqCxwcDNwNH5vrMi4iGvb3m0UcfHUOGDOmags3MKtSaNWueiYj+7fXLJCAk9QKuB6YAzcBq\nSUsjYkNet8uBxRHx75JGAw3AkL297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"text/plain": [
"<Figure size 432x288 with 1 Axes>"
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"#\n",
"# Plot this\n",
"#\n",
"plot_histogram(counts)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Finally let us interpret the result. We know that there are two cases. If the function is balanced, the probability to measure 00 is zero. If the function is not balanced, it will be one. "
]
},
{
"cell_type": "code",
"execution_count": 14,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Function is balanced\n"
]
}
],
"source": [
"if '000' in counts:\n",
" zeroMeasurements = counts['000']\n",
"else:\n",
" zeroMeasurements = 0\n",
"if (zeroMeasurements < 100):\n",
" print(\"Function is balanced\")\n",
"else:\n",
" print(\"Function is constant\")"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Now we repeat the entire exercise with a constant function."
]
},
{
"cell_type": "code",
"execution_count": 15,
"metadata": {},
"outputs": [
{
"data": {
"image/png": "iVBORw0KGgoAAAANSUhEUgAAAi8AAADRCAYAAAAE01IEAAAABHNCSVQICAgIfAhkiAAAAAlwSFlz\nAAALEgAACxIB0t1+/AAAADl0RVh0U29mdHdhcmUAbWF0cGxvdGxpYiB2ZXJzaW9uIDMuMC4yLCBo\ndHRwOi8vbWF0cGxvdGxpYi5vcmcvOIA7rQAAHnRJREFUeJzt3X9wVPX97/FXDGkoJpvwMwj51QRp\nb4BkQ4gItSatX0lbAoEA6m2LMoBY0VYUmaTodPjGAQNFBpx26DdDFeTH+BWRJigGrg5we4Wmy4+E\nYqe3N40JBFF+SNgQQWQ59w/LljUJycJmz37I8zFzZnY/e/Z83nvCfnjlc34kzLIsSwAAAIa4ze4C\nAAAA/EF4AQAARiG8AAAAoxBeAACAUQgvAADAKIQXAABgFMILAAAwCuEFAAAYhfACAACMQngBAABG\nIbwAAACjEF4AAIBRCC8AAMAohBcAAGAUwgsAADAK4QUAABiF8AIAAIxCeAEAAEYhvAAAAKMQXgAA\ngFEILwAAwCiEFwAAYBTCCw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y8vINtfvHix\nXnvtNVVWVqpv376aNWuWmpubVVlZGZDtd4TDRgAA+GrvqIQx4UWS1q1bpyVLluj48eOKjo7WzJkz\ntXjx4jbXXbJkiTZu3KgPP/ywU9v2eDwqKirS2rVr9cUXX+j+++9XWVmZ+vUz46Sszrp82aPflL2u\nWEeUfv7TibdcGgcA3PqMCi+4eZzrAgAwnTEn7CIwRnwnRZZlca4LAMBYzLwAAACjGHO1EQAAgER4\nAQAAhiG8AAAAoxBeAACAUQgvAADAKIQXAABgFMILAAAwCuEFAAAYhfACAACMQngBAABGIbwAAACj\nEF4AAIBRCC8AAMAohBcAAGAUwgsAADAK4QUAABiF8AIAAIxCeAEAAEYhvAAAAKMQXgAAgFEILwAA\nwCiEFwAAYBTCCwAAMMr/B4BzxfKe5U6uAAAAAElFTkSuQmCC\n",
"text/plain": [
"<Figure size 722.4x258.86 with 1 Axes>"
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"q = QuantumRegister(3,\"q\")\n",
"c = ClassicalRegister(3,\"c\")\n",
"circuit = QuantumCircuit(q,c)\n",
"createInitialState(circuit)\n",
"addAncilla(circuit)\n",
"circuit = circuit + (createOracleConstant(q,c))\n",
"uncomputeAncilla(circuit)\n",
"addMeasurement(circuit)\n",
"drawer(circuit, style = my_style)"
]
},
{
"cell_type": "code",
"execution_count": 16,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": [
"qobj = compile(circuit, backend=backend, shots=1024)\n",
"job = backend.run(qobj)"
]
},
{
"cell_type": "code",
"execution_count": 17,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Status @ 0 seconds\n",
"JobStatus.QUEUED\n",
"Position in queue: 9\n",
"Status @ 60 seconds\n",
"JobStatus.QUEUED\n",
"Position in queue: 7\n",
"Status @ 120 seconds\n",
"JobStatus.QUEUED\n",
"Position in queue: 5\n",
"Status @ 180 seconds\n",
"JobStatus.QUEUED\n",
"Position in queue: 4\n",
"Status @ 240 seconds\n",
"JobStatus.QUEUED\n",
"Position in queue: 3\n",
"Status @ 300 seconds\n",
"JobStatus.QUEUED\n",
"Position in queue: 1\n",
"JobStatus.DONE\n"
]
}
],
"source": [
"import time\n",
"lapse = 0\n",
"#\n",
"# Wait three seconds once, this should be good enough for the simulator in most cases\n",
"#\n",
"time.sleep(3)\n",
"interval = 60\n",
"while (job.status().name != 'DONE') and (job.status().name != 'CANCELLED') and (job.status().name != 'ERROR'):\n",
" print('Status @ {} seconds'.format(interval * lapse))\n",
" print(job.status())\n",
" print(\"Position in queue: \",job.queue_position())\n",
" time.sleep(interval)\n",
" lapse += 1\n",
"print(job.status())"
]
},
{
"cell_type": "code",
"execution_count": 18,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"{'000': 916, '001': 57, '010': 42, '011': 9}"
]
},
"execution_count": 18,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"result = job.result()\n",
"counts = result.get_counts()\n",
"counts"
]
},
{
"cell_type": "code",
"execution_count": 19,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Function is constant\n"
]
}
],
"source": [
"if '000' in counts:\n",
" zeroMeasurements = counts['000']\n",
"else:\n",
" zeroMeasurements = 0\n",
"if (zeroMeasurements < 100):\n",
" print(\"Function is balanced\")\n",
"else:\n",
" print(\"Function is constant\")"
]
},
{
"cell_type": "code",
"execution_count": 20,
"metadata": {},
"outputs": [
{
"data": {
"image/png": "iVBORw0KGgoAAAANSUhEUgAAAYgAAAEMCAYAAADeYiHoAAAABHNCSVQICAgIfAhkiAAAAAlwSFlz\nAAALEgAACxIB0t1+/AAAADl0RVh0U29mdHdhcmUAbWF0cGxvdGxpYiB2ZXJzaW9uIDMuMC4yLCBo\ndHRwOi8vbWF0cGxvdGxpYi5vcmcvOIA7rQAAHRBJREFUeJzt3Xt8VeWd7/HPL4SLgAWF0NEE5BJA\nAypogGJnRJGWS2ucKYrAaxgFCscenRn1eETntMigHeW09XIUD4OFqliJiiiMRhgOLQPt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905O2\nh0VVi4iI1C7tBqlFRCQ9KCBERCSUAkJEREIpIEREJJQCQkREQikgREQklAJCRERCKSBERCSUAkJE\nREIpIEREJJQCQkREQikgREQklAJCRERCKSAkUsuWLaN3797k5+fz0EMPnfT8kSNHuPHGG8nPz2fQ\noEHs3LkTgJ07d3LWWWfRr18/+vXrxy233HLiNUePHmXq1Kn06tWLCy+8kJdffjmqjyOS0SJb7luk\noqKCW2+9lRUrVpCXl8eAAQMoKiqioKDgRJt58+ZxzjnnsG3bNoqLi5k2bRovvPACAD169ODdd989\n6X1//OMf06lTJ7Zs2cKXX37JJ598EtlnEslkOoKQyKxdu5b8/Hy6d+9OixYtGDt2LEuWLKnSZsmS\nJdx0000AXH/99axcuRJ3P+X7zp8/n3vvvReArKwsOnbs2DgfQOQMo4CQyOzZs4fOnb+6NXleXh57\n9uypsU12djbt2rVj//79AOzYsYP+/fszZMgQ1qxZA8CBAwcA+NGPfsRll13GDTfcwEcffRTFx0l7\np3s6r9KuXbto27YtP/3pT0/smzRpEp06daJv376NXb6kAQWENAnnnXceu3bt4p133uHhhx9m/Pjx\nfPbZZxw/fpzy8nKuuOIK3n77bQYPHsxdd90Vd7mxqzyd98Ybb1BWVsbChQspKyur0ib5dN4dd9zB\ntGnTqjx/5513MnLkyCr7br75ZpYtW9bo9Ut6UEBIZHJzc9m9e/eJx+Xl5eTm5tbY5vjx4xw8eJAO\nHTrQsmVLOnToAMDll19Ojx492LJlCx06dKB169Z873vfA+CGG27g7bffjugTpa/6ns579dVX6dat\nG3369KnymiuvvJJzzz03mg8hsVNASGQGDBjA1q1b2bFjB0ePHqW4uJiioqIqbYqKinjmmWcAWLRo\nEUOHDsXM2LdvHxUVFQBs376drVu30r17d8yMa6+9llWrVgGwcuXKKoPeZ6r6nM77/PPPmTVrFvfd\nd1+kNUv60SwmiUx2djZPPPEEw4cPp6KigkmTJtGnTx+mT59OYWEhRUVFTJ48mQkTJpCfn8+5555L\ncXExAKtXr2b69Ok0b96crKws5syZc+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r3dUVi4HQp8A8E4z/firPADJIRfa2ACPcK\nwcVZj5tZ9+QnEt9k/5Ng5VapP/V1dNTX0cmIvlZAhEismfIPBLO83jGzNWb292Z2sZndRrD65S9i\nLTJDqK+jo76OTqb0tcYgamFmlwHXEZw3PA/4FcHCfPNjLSwDqa+jo76OTlPuawVEChIXbrXwpHvK\nSuNQX0dHfR2dptbXCggREQmlMQgREQmlgBARkVAKCBERCaWAEBGRUAoIEREJpYAQEZFQCggREQn1\n/wFgy0K/oRmiNwAAAABJRU5ErkJggg==\n",
"text/plain": [
"<Figure size 432x288 with 1 Axes>"
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"plot_histogram(counts)"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": []
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.6.2"
}
},
"nbformat": 4,
"nbformat_minor": 2
}
You can’t perform that action at this time.