{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "# Quantum Teleportation Circuit" ] }, { "cell_type": "code", "execution_count": 1, "metadata": {}, "outputs": [], "source": [ "from qutip_qip.circuit import QubitCircuit, Measurement, Gate\n", "from qutip import basis, tensor, identity\n", "from math import sqrt" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Introduction \n", "\n", "This notebook introduces the basic quantum teleportation circuit (http://www.physics.udel.edu/~msafrono/425-2011/Lecture%2025-1.pdf), complete with measurements and classical control. This notebook also serves as an example on how to add measurement gates and classical controls to a circuit.\n", "\n", "We will describe the circuit that enables quantum teleportation. We will use two classical wires and three qubit wires. The first qubit wire represents the quantum state $| q0 ⟩ = | \\psi ⟩$ that needs to be transferred from Alice to Bob (so the first qubit is in the possession of Alice). " ] }, { "cell_type": "code", "execution_count": 2, "metadata": {}, "outputs": [], "source": [ "teleportation = QubitCircuit(3, num_cbits = 2, input_states = [\"\\psi\", \"0\", \"0\", \"c0\", \"c1\"])" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "First, Alice and Bob need to create the shared EPR pair ($\\frac{| 00 ⟩ + | 11 ⟩} {2}$) between the second and third qubit by using the hadamard gate on Alice's qubit followed by an entangling CNOT gate. " ] }, { "cell_type": "code", "execution_count": 3, "metadata": {}, "outputs": [], "source": [ "teleportation.add_gate(\"SNOT\", targets=[1])\n", "teleportation.add_gate(\"CNOT\", targets=[2], controls=[1])" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Following this, Alice makes the qubit $| q0 ⟩$ interact with Alice's EPR qubit, followed by measuring on the two qubits belonging to Alice. The measurement results for the first qubit is stored in classical register $c1$ and the second qubit is stored in classical register $c0$." ] }, { "cell_type": "code", "execution_count": 4, "metadata": {}, "outputs": [], "source": [ "teleportation.add_gate(\"CNOT\", targets=[1], controls=[0])\n", "teleportation.add_gate(\"SNOT\", targets=[0])\n", "\n", "teleportation.add_measurement(\"M0\", targets=[0], classical_store=1)\n", "teleportation.add_measurement(\"M1\", targets=[1], classical_store=0)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Now, we apply the $X$ gate on Bob's qubit based on the classical control $c0$ and $Z$ gate based on classical control $c1$. These operations correspond to the following operations based on the state of Alice's measurement. \n", "\n", "$|00⟩ \\rightarrow $ no operation \\\n", "$|01⟩ \\rightarrow Z$ \\\n", "$|10⟩ \\rightarrow X$ \\\n", "$|11⟩ \\rightarrow ZX$ \n", "\n", "The final circuit mathematically must result in the third qubit taking the state $|\\psi⟩$. " ] }, { "cell_type": "code", "execution_count": 5, "metadata": {}, "outputs": [], "source": [ "teleportation.add_gate(\"X\", targets=[2], classical_controls=[0])\n", "teleportation.add_gate(\"Z\", targets=[2], classical_controls=[1])" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Finally, our teleportation circuit is ready to run, we can view the circuit structure using the following command. " ] }, { "cell_type": "code", "execution_count": 6, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "[Gate(SNOT, targets=[1], controls=None, classical controls=None, control_value=None),\n", " Gate(CNOT, targets=[2], controls=[1], classical controls=None, control_value=None),\n", " Gate(CNOT, targets=[1], controls=[0], classical controls=None, control_value=None),\n", " Gate(SNOT, targets=[0], controls=None, classical controls=None, control_value=None),\n", " Measurement(M0, target=[0], classical_store=1),\n", " Measurement(M1, target=[1], classical_store=0),\n", " Gate(X, targets=[2], controls=None, classical controls=[0], control_value=None),\n", " Gate(Z, targets=[2], controls=None, classical controls=[1], control_value=None)]" ] }, "execution_count": 6, "metadata": {}, "output_type": "execute_result" } ], "source": [ "teleportation.gates" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "The circuit can also be visualized:" ] }, { "cell_type": "code", "execution_count": 7, "metadata": {}, "outputs": [ { "data": { "image/png": "iVBORw0KGgoAAAANSUhEUgAAAhMAAADdCAQAAACr1zhCAAAAAmJLR0QA/4ePzL8AAAAJcEhZcwAAAGQAAABkAA+Wxd0AAAAHdElNRQflBAwROBwrcRAaAAAKeHpUWHRSYXcgcHJvZm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5cmlnaHQAQ29weXJpZ2h0IEFydGlmZXggU29mdHdhcmUgMjAxMQi6xbQAAAAxdEVYdGljYzpkZXNjcmlwdGlvbgBBcnRpZmV4IFNvZnR3YXJlIHNSR0IgSUNDIFByb2ZpbGUTDAGGAAAAE3RFWHRwZGY6VmVyc2lvbgBQREYtMS41UzZawQAAAABJRU5ErkJggg==\n", "text/plain": [ "" ] }, "execution_count": 7, "metadata": {}, "output_type": "execute_result" } ], "source": [ "teleportation" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "The first qubit is user-specified $|\\psi ⟩$ state and the other two must be $|0⟩$. \n", "\n", "### Example 1 \n", "#### $|\\psi⟩ = |+ ⟩$ " ] }, { "cell_type": "code", "execution_count": 8, "metadata": {}, "outputs": [], "source": [ "a = 1/sqrt(2) * basis(2, 0) + 1/sqrt(2) * basis(2, 1)\n", "state = tensor(a, basis(2,0), basis(2,0))" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "We can confirm our state is initialized correctly by observing the measurment statistics on the first qubit, followed by which we run the circuit." ] }, { "cell_type": "code", "execution_count": 9, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "([Quantum object: dims = [[2, 2, 2], [1, 1, 1]], shape = (8, 1), type = ket\n", " Qobj data =\n", " [[1.]\n", " [0.]\n", " [0.]\n", " [0.]\n", " [0.]\n", " [0.]\n", " [0.]\n", " [0.]],\n", " Quantum object: dims = [[2, 2, 2], [1, 1, 1]], shape = (8, 1), type = ket\n", " Qobj data =\n", " [[0.]\n", " [0.]\n", " [0.]\n", " [0.]\n", " [1.]\n", " [0.]\n", " [0.]\n", " [0.]]],\n", " [0.4999999999999999, 0.4999999999999999])" ] }, "execution_count": 9, "metadata": {}, "output_type": "execute_result" } ], "source": [ "initial_measurement = Measurement(\"start\", targets=[0])\n", "initial_measurement.measurement_comp_basis(state)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "We can run the circuit using the `QubitCircuit.run()` function which provided the initial state-vector (or density matrix) initiates one run on the circuit (including sampling any intermediate measurements) and providing the final results (any classical bits can also be explicitly set using the argument `cbits`). The results are returned as a `Result` object. The result states can be accessed through the `get_states()` function where the argument `index=0` specifies the first(only) result should be returned" ] }, { "cell_type": "code", "execution_count": 10, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Quantum object: dims = [[2, 2, 2], [1, 1, 1]], shape = (8, 1), type = ket\n", "Qobj data =\n", "[[0. ]\n", " [0. ]\n", " [0. ]\n", " [0. ]\n", " [0. ]\n", " [0. ]\n", " [0.70710678]\n", " [0.70710678]]\n" ] } ], "source": [ "state_final = teleportation.run(state)\n", "print(state_final)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "After running, we can see the measurement statistics on the last qubit to see that the qubit is teleported correctly. " ] }, { "cell_type": "code", "execution_count": 11, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "([Quantum object: dims = [[2, 2, 2], [1, 1, 1]], shape = (8, 1), type = ket\n", " Qobj data =\n", " [[0.]\n", " [0.]\n", " [0.]\n", " [0.]\n", " [0.]\n", " [0.]\n", " [1.]\n", " [0.]],\n", " Quantum object: dims = [[2, 2, 2], [1, 1, 1]], shape = (8, 1), type = ket\n", " Qobj data =\n", " [[0.]\n", " [0.]\n", " [0.]\n", " [0.]\n", " [0.]\n", " [0.]\n", " [0.]\n", " [1.]]],\n", " [0.4999999999999999, 0.4999999999999999])" ] }, "execution_count": 11, "metadata": {}, "output_type": "execute_result" } ], "source": [ "final_measurement = Measurement(\"start\", targets=[2])\n", "final_measurement.measurement_comp_basis(state_final)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### Example 2 \n", "#### $|\\psi⟩ = |1 ⟩$ " ] }, { "cell_type": "code", "execution_count": 12, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "([None,\n", " Quantum object: dims = [[2, 2, 2], [1, 1, 1]], shape = (8, 1), type = ket\n", " Qobj data =\n", " [[0.]\n", " [0.]\n", " [0.]\n", " [0.]\n", " [1.]\n", " [0.]\n", " [0.]\n", " [0.]]],\n", " [0.0, 1.0])" ] }, "execution_count": 12, "metadata": {}, "output_type": "execute_result" } ], "source": [ "state = tensor(basis(2,1), basis(2,0), basis(2,0))\n", "initial_measurement = Measurement(\"start\", targets=[0])\n", "initial_measurement.measurement_comp_basis(state)" ] }, { "cell_type": "code", "execution_count": 13, "metadata": { "scrolled": true }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Quantum object: dims = [[2, 2, 2], [1, 1, 1]], shape = (8, 1), type = ket\n", "Qobj data =\n", "[[0.]\n", " [1.]\n", " [0.]\n", " [0.]\n", " [0.]\n", " [0.]\n", " [0.]\n", " [0.]]\n" ] } ], "source": [ "state_final = teleportation.run(state)\n", "print(state_final)" ] }, { "cell_type": "code", "execution_count": 14, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "([None,\n", " Quantum object: dims = [[2, 2, 2], [1, 1, 1]], shape = (8, 1), type = ket\n", " Qobj data =\n", " [[0.]\n", " [1.]\n", " [0.]\n", " [0.]\n", " [0.]\n", " [0.]\n", " [0.]\n", " [0.]]],\n", " [0.0, 1.0])" ] }, "execution_count": 14, "metadata": {}, "output_type": "execute_result" } ], "source": [ "final_measurement = Measurement(\"start\", targets=[2])\n", "final_measurement.measurement_comp_basis(state_final)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Another useful feature of the circuit module is the **QubitCircuit.run_statistics()** feature which provides the opportunity to gather all the possible output states of the circuit along with their output probabilities. Again, the results are returned as a `Result` object. The result states and respective probabilites can be accessed through the `get_results()` function. " ] }, { "cell_type": "code", "execution_count": 15, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "[0.24999999999999994,\n", " 0.24999999999999994,\n", " 0.24999999999999994,\n", " 0.24999999999999994]" ] }, "execution_count": 15, "metadata": {}, "output_type": "execute_result" } ], "source": [ "results = teleportation.run_statistics(state)\n", "results.probabilities" ] }, { "cell_type": "code", "execution_count": 16, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "[Quantum object: dims = [[2, 2, 2], [1, 1, 1]], shape = (8, 1), type = ket\n", " Qobj data =\n", " [[0.]\n", " [1.]\n", " [0.]\n", " [0.]\n", " [0.]\n", " [0.]\n", " [0.]\n", " [0.]],\n", " Quantum object: dims = [[2, 2, 2], [1, 1, 1]], shape = (8, 1), type = ket\n", " Qobj data =\n", " [[0.]\n", " [0.]\n", " [0.]\n", " [1.]\n", " [0.]\n", " [0.]\n", " [0.]\n", " [0.]],\n", " Quantum object: dims = [[2, 2, 2], [1, 1, 1]], shape = (8, 1), type = ket\n", " Qobj data =\n", " [[0.]\n", " [0.]\n", " [0.]\n", " [0.]\n", " [0.]\n", " [1.]\n", " [0.]\n", " [0.]],\n", " Quantum object: dims = [[2, 2, 2], [1, 1, 1]], shape = (8, 1), type = ket\n", " Qobj data =\n", " [[0.]\n", " [0.]\n", " [0.]\n", " [0.]\n", " [0.]\n", " [0.]\n", " [0.]\n", " [1.]]]" ] }, "execution_count": 16, "metadata": {}, "output_type": "execute_result" } ], "source": [ "results.final_states" ] }, { "cell_type": "code", "execution_count": 17, "metadata": {}, "outputs": [ { "data": { "text/html": [ "
SoftwareVersion
QuTiP4.6.0+c003ff5
Numpy1.20.1
SciPy1.5.3
matplotlib3.3.0
Cython0.29.21
Number of CPUs12
BLAS InfoGeneric
IPython7.16.1
Python3.8.6 | packaged by conda-forge | (default, Oct 7 2020, 18:22:52) [MSC v.1916 64 bit (AMD64)]
OSnt [win32]
Mon Apr 12 19:56:28 2021 W. Europe Daylight Time
" ], "text/plain": [ "" ] }, "execution_count": 17, "metadata": {}, "output_type": "execute_result" } ], "source": [ "from qutip.ipynbtools import version_table\n", "version_table()" ] } ], "metadata": { "celltoolbar": "Raw Cell Format", "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.9.4" } }, "nbformat": 4, "nbformat_minor": 2 }