{ "cells": [ { "cell_type": "markdown", "id": "50284a7c", "metadata": {}, "source": [ "# 08 - Quantum Teleportation\n", "\n", "Transfer a quantum state from one qubit to another using entanglement.\n", "\n", "**Concepts:** Bell pair, Bell measurement, classical communication" ] }, { "cell_type": "code", "execution_count": null, "id": "e21b99b9", "metadata": {}, "outputs": [], "source": [ "import quantsdk as qs\n", "import math" ] }, { "cell_type": "markdown", "id": "3de7ad2e", "metadata": {}, "source": [ "## The Protocol\n", "\n", "1. Alice has state |psi> on qubit 0\n", "2. Alice and Bob share a Bell pair (qubits 1-2)\n", "3. Alice performs Bell measurement (qubits 0-1)\n", "4. Bob applies corrections based on Alice's results\n", "\n", "```\n", "q0 (Alice's state): --[Rx]--*--[H]--[M]--\n", "q1 (Alice's Bell): --[H]--*--[X]---[M]--\n", "q2 (Bob's Bell): -------X-----------[M]\n", "```" ] }, { "cell_type": "code", "execution_count": null, "id": "2d9b5524", "metadata": {}, "outputs": [], "source": [ "def teleportation_circuit(theta: float) -> qs.Circuit:\n", " \"\"\"Create teleportation circuit for state RY(theta)|0>.\"\"\"\n", " circuit = qs.Circuit(3, name=f\"teleport-{theta:.2f}\")\n", " \n", " # Prepare state to teleport\n", " circuit.ry(0, theta)\n", " \n", " # Create Bell pair (qubits 1-2)\n", " circuit.barrier()\n", " circuit.h(1).cx(1, 2)\n", " \n", " # Bell measurement\n", " circuit.barrier()\n", " circuit.cx(0, 1).h(0)\n", " \n", " # Measure all\n", " circuit.measure_all()\n", " return circuit" ] }, { "cell_type": "code", "execution_count": null, "id": "49e83753", "metadata": {}, "outputs": [], "source": [ "# Teleport different states\n", "for theta in [0, math.pi/4, math.pi/2, math.pi]:\n", " circuit = teleportation_circuit(theta)\n", " result = qs.run(circuit, shots=2000, seed=42)\n", " \n", " # Analyze Bob's qubit (q2) conditioned on Alice's results\n", " p_bob_1 = 0\n", " for bitstring, count in result.counts.items():\n", " if bitstring[2] == '1': # Bob's qubit\n", " p_bob_1 += count\n", " p_bob_1 /= 2000\n", " \n", " expected = math.sin(theta / 2) ** 2\n", " print(f\"theta={theta:.2f}: P(Bob=1)={p_bob_1:.3f} (need corrections, expected~{expected:.3f})\")" ] }, { "cell_type": "code", "execution_count": null, "id": "46633c18", "metadata": {}, "outputs": [], "source": [ "# Show full output for one case\n", "circuit = teleportation_circuit(math.pi / 3)\n", "result = qs.run(circuit, shots=4000, seed=42)\n", "\n", "print(f\"Circuit depth: {circuit.depth}\")\n", "print(f\"Gate count: {circuit.gate_count}\")\n", "print(f\"\\nAll outcomes (q0 q1 q2):\")\n", "for bs, count in sorted(result.counts.items()):\n", " print(f\" |{bs}>: {count} ({count/4000:.3f})\")" ] } ], "metadata": { "language_info": { "name": "python" } }, "nbformat": 4, "nbformat_minor": 5 }