{ "cells": [ { "cell_type": "markdown", "id": "76613054", "metadata": {}, "source": [ "# 02 - Bell States\n", "\n", "Create all four Bell states — the simplest examples of quantum entanglement.\n", "\n", "**Concepts:** Entanglement, CNOT, Hadamard, Bell states" ] }, { "cell_type": "code", "execution_count": null, "id": "a1644f41", "metadata": {}, "outputs": [], "source": [ "import quantsdk as qs" ] }, { "cell_type": "markdown", "id": "6267ce48", "metadata": {}, "source": [ "## Bell State |Phi+>\n", "\n", "$$|\\Phi^+\\rangle = \\frac{1}{\\sqrt{2}}(|00\\rangle + |11\\rangle)$$\n", "\n", "Two gates: Hadamard + CNOT." ] }, { "cell_type": "code", "execution_count": null, "id": "d11b44f3", "metadata": {}, "outputs": [], "source": [ "phi_plus = qs.Circuit(2, name=\"Phi+\").h(0).cx(0, 1).measure_all()\n", "\n", "result = qs.run(phi_plus, shots=2000, seed=42)\n", "print(f\"|Phi+> counts: {result.counts}\")\n", "print(f\"Probabilities: {result.probabilities}\")\n", "print(\"\\nNotice: only |00> and |11> — qubits are perfectly correlated!\")" ] }, { "cell_type": "markdown", "id": "c4212fb9", "metadata": {}, "source": [ "## All Four Bell States" ] }, { "cell_type": "code", "execution_count": null, "id": "5ac8a398", "metadata": {}, "outputs": [], "source": [ "# |Phi+> = (|00> + |11>) / sqrt(2)\n", "phi_plus = qs.Circuit(2, name=\"Phi+\").h(0).cx(0, 1).measure_all()\n", "\n", "# |Phi-> = (|00> - |11>) / sqrt(2)\n", "phi_minus = qs.Circuit(2, name=\"Phi-\").h(0).z(0).cx(0, 1).measure_all()\n", "\n", "# |Psi+> = (|01> + |10>) / sqrt(2)\n", "psi_plus = qs.Circuit(2, name=\"Psi+\").h(0).x(1).cx(0, 1).measure_all()\n", "\n", "# |Psi-> = (|01> - |10>) / sqrt(2)\n", "psi_minus = qs.Circuit(2, name=\"Psi-\").h(0).z(0).x(1).cx(0, 1).measure_all()\n", "\n", "bell_states = {\n", " \"|Phi+>\": phi_plus,\n", " \"|Phi->\": phi_minus,\n", " \"|Psi+>\": psi_plus,\n", " \"|Psi->\": psi_minus,\n", "}\n", "\n", "for name, circuit in bell_states.items():\n", " result = qs.run(circuit, shots=2000, seed=42)\n", " print(f\"{name}: {result.counts}\")" ] }, { "cell_type": "markdown", "id": "11864911", "metadata": {}, "source": [ "## Circuit Details" ] }, { "cell_type": "code", "execution_count": null, "id": "8e38b985", "metadata": {}, "outputs": [], "source": [ "circuit = qs.Circuit(2, name=\"Bell\").h(0).cx(0, 1).measure_all()\n", "\n", "print(f\"Depth: {circuit.depth}\")\n", "print(f\"Gate count: {circuit.gate_count}\")\n", "print(f\"Operations: {circuit.count_ops()}\")\n", "print(f\"\\nCircuit drawing:\")\n", "print(circuit.draw())" ] }, { "cell_type": "markdown", "id": "d9a0c779", "metadata": {}, "source": [ "## Statistical Analysis" ] }, { "cell_type": "code", "execution_count": null, "id": "4c467017", "metadata": {}, "outputs": [], "source": [ "result = qs.run(phi_plus, shots=10000, seed=123)\n", "\n", "print(f\"Top results: {result.top_k(2)}\")\n", "print(f\"\\nSummary:\\n{result.summary()}\")" ] } ], "metadata": { "language_info": { "name": "python" } }, "nbformat": 4, "nbformat_minor": 5 }