qubit using two

classical bits | Transmit two

classical bits

using one

qubit |\n", "\n", "\n", "The teleportation protocol can be thought of as a flipped version of the superdense coding protocol, in the sense that Alice and Bob merely “swap their equipment.”" ] }, { "cell_type": "markdown", "metadata": { "colab_type": "text", "id": "N5LyBKFXYG41" }, "source": [ "\n", "\n", "## 2. The Process \n", "\n", "![image1](images/superdense.png)\n", "\n", "### 2.1 Step 1 \n", "The process starts with a third party, who we'll call Charlie. Two qubits are prepared by Charlie in an entangled state. He initially starts the 2 qubits in the basis state $|0\\rangle$. He applies Hadamard gate ($H$) to the first qubit to create superposition. He then applies CNOT gate ($CX$) using the first qubit as a control and the second as the target. This is the entangled state (Bell pair) we mentioned earlier. \n", "\n", "#### Outcome States\n", "\n", "Charlie first applies a Hadamard gate. \n", "\n", "When the H-gate is applied to first qubit, it creates superposition and we get the state:\n", "\n", "\n", "$$|0+\\rangle = \\tfrac{1}{\\sqrt{2}}(|00\\rangle + |01\\rangle)$$\n", "\n", "\n", "\n", "Then Charlie applies the CNOT gate. The CNOT gate entangles both qubits, i.e. it flips the target if the control is $|1\\rangle$. Note that the control qubit is our rightmost qubit.\n", "\n", "\n", "\n", "$$\\text{CNOT} \\tfrac{1}{\\sqrt{2}}(|00\\rangle + |01\\rangle) = \\tfrac{1}{\\sqrt{2}}(|00\\rangle + |11\\rangle)$$\n", "\n", "\n", "\n", "### 2.2 Step 2 \n", "\n", "Charlie sends the first qubit to Alice and the second qubit to Bob. The goal of the protocol is for Alice to send 2 classical bits of information to Bob using her qubit. But before she does, she needs to apply a set of quantum gates to her qubit depending on the 2 bits of information she wants to send:\n", "\n", "\n", "#### Encoding Rules for Superdense Coding (Alice protocol):\n", "\n", "\n", "\n", "\n", "![image2](images/superdense_table1.png)

\n", "\n", "\n", "Thus if she wants to send a `00`, she does nothing to her qubit (apply the identity ($I$) gate). If she sends a `10`, then she applies the $X$ gate. Depending on what she wants to send, she applies the appropriate gate, then sends her qubit to Bob for the final step in the process\n", "\n", "\n", "### 2.3 Step 3 \n", "\n", "Bob receives Alice's qubit (rightmost qubit) and uses his qubit to decode Alice's message. Notice that he does not need to have knowledge of the state in order to decode it — he simply uses the restoration operation.\n", "\n", "Bob applies a CNOT gate using the rightmost qubit as control and the leftmost as target. Then he applies a Hadamard gate and finally performs a measurement on both qubits to extract Alice's message.\n", "\n", "\n", "\n", "![image3](images/superdense_table2.png)

\n", "\n", "When Bob performs the measurements, he is certain to get the message Alice sent him. Note that the last outcome has a negative sign $-|11\\rangle$, writing it as $|11\\rangle$ is also correct as this is global phase and is not measureable.\n", "\n", "\n", "## 3. Simulating the Superdense Coding Protocol " ] }, { "cell_type": "code", "execution_count": 1, "metadata": { "colab": {}, "colab_type": "code", "id": "u6m-M5G0X4HO" }, "outputs": [], "source": [ "# Importing everything\n", "from qiskit import *\n", "from qiskit.visualization import plot_histogram\n", "# For Jupyter Notebooks, change the settings to get nicer images\n", "%config InlineBackend.figure_format = 'svg'" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "We saw that to create an entangled pair, we needed to do a H-gate followed by a CNOT. Let's create a function that takes a `QuantumCircuit` and entangles the qubits with indexes `a` and `b`:" ] }, { "cell_type": "code", "execution_count": 2, "metadata": {}, "outputs": [], "source": [ "# Define a function that takes a QuantumCircuit (qc) \n", "# and two integers (a & b)\n", "def create_bell_pair(qc, a, b):\n", " qc.h(a) # Apply a h-gate to the first qubit\n", " qc.cx(a,b) # Apply a CNOT, using the first qubit as the control" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Next we need to encode our message. We saw that there were four possible messages we could send: `00`, `10`, `01` or `11`. Let's create a function that takes this message and applies the appropriate gates for us:" ] }, { "cell_type": "code", "execution_count": 3, "metadata": {}, "outputs": [], "source": [ "# Define a function that takes a QuantumCircuit (qc)\n", "# a qubit index (qubit) and a message string (msg)\n", "def encode_message(qc, qubit, msg):\n", " if msg == \"00\":\n", " pass # To send 00 we do nothing\n", " elif msg == \"10\":\n", " qc.x(qubit) # To send 10 we apply an X-gate\n", " elif msg == \"01\":\n", " qc.z(qubit) # To send 01 we apply a Z-gate\n", " elif msg == \"11\":\n", " qc.z(qubit) # To send 11, we apply a Z-gate\n", " qc.x(qubit) # followed by an X-gate\n", " else:\n", " print(\"Invalid Message: Sending '00'\")" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Finally, we need to decode our message, we saw we could do this using a CNOT followed by a H-gate. Let's create a function that does this for us too:" ] }, { "cell_type": "code", "execution_count": 4, "metadata": {}, "outputs": [], "source": [ "def decode_message(qc, a, b):\n", " qc.cx(a,b)\n", " qc.h(a)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Finally, we can put this together to complete our protocol." ] }, { "cell_type": "code", "execution_count": 5, "metadata": { "colab": { "base_uri": "https://localhost:8080/", "height": 185 }, "colab_type": "code", "id": "_HMTtQ8IYh19", "outputId": "2d05d830-a863-49d9-c522-5a0e331d2fe1" }, "outputs": [ { "data": { "image/svg+xml": [ "\n", "\n", "\n", "\n" ], "text/plain": [ "