{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "# Noise-Aware Verification and Mitigation Studio\n" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "The studio turns diagnosis into a compact verification case study.\n" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Design Brief\n", "\n", "\n", " Produce a local verification notebook that states the intended invariant, compares clean and noisy behavior, and writes a mitigation note that is useful precisely because it is limited and evidence-backed.\n" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "from pathlib import Path\n", "import sys\n", "\n", "project_root = Path.cwd().resolve()\n", "while not (project_root / \"pyproject.toml\").exists():\n", " if project_root.parent == project_root:\n", " raise RuntimeError(\"Could not locate the project root from this notebook.\")\n", " project_root = project_root.parent\n", "\n", "src_path = project_root / \"src\"\n", "if str(src_path) not in sys.path:\n", " sys.path.insert(0, str(src_path))\n" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "from quantum_learning import (\n", " build_demo_noise_model,\n", " counts_to_probabilities,\n", " draw_circuit,\n", " editable_circuit_lab,\n", " line_coupling_map,\n", " plot_counts,\n", " plot_probabilities,\n", " quiz_block,\n", " reflection_box,\n", " simulate_counts,\n", " statevector_probabilities,\n", " step_reference_table,\n", " transpile_summary,\n", ")\n", "from qiskit import QuantumCircuit\n", "from qiskit.providers.basic_provider import BasicSimulator\n" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Studio Prompt 1: Baseline Case File\n", "\n", "\n", " Start with a correct baseline and make the invariant as explicit as the circuit itself.\n" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "demo_noise = build_demo_noise_model(\n", " single_qubit_error=0.01,\n", " two_qubit_error=0.05,\n", " readout_error=0.03,\n", ")\n", "\n", "def simulate_noisy_counts(circuit, shots=256):\n", " return simulate_counts(circuit, shots=shots, noise_model=demo_noise)\n", "\n", " editable_code = '\\nfrom qiskit import QuantumCircuit\\n\\ndef bell_candidate(bug: bool = False) -> QuantumCircuit:\\n circuit = QuantumCircuit(2, 2)\\n # [1] Toggle only one potential design defect at a time.\\n if not bug:\\n circuit.h(0)\\n # [2] Correlate the second wire so the intended support is {00, 11}.\\n circuit.cx(0, 1)\\n # [3] Keep the reporting layer explicit and stable.\\n circuit.barrier()\\n # [4] Measure both outputs so invariants can inspect the evidence.\\n circuit.measure([0, 1], [0, 1])\\n return circuit\\n\\ncircuit = bell_candidate(bug=False)\\n'\n", " editable_circuit_lab(\n", " initial_code=editable_code,\n", " context={\"QuantumCircuit\": QuantumCircuit, \"simulate_counts\": simulate_noisy_counts},\n", " title='Studio 1: Baseline Case File',\n", " instructions='Use the correct circuit as a baseline and write the invariant you want the later noisy comparison to respect.',\n", " shots=256,\n", " )\n" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Studio Prompt 2: Defect Comparison\n", "\n", "\n", " Add a deliberate bug so your case file contains a real contrast between broken mechanism and noisy degradation.\n" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "editable_code = '\\nfrom qiskit import QuantumCircuit\\n\\ndef bell_candidate(bug: bool = True) -> QuantumCircuit:\\n circuit = QuantumCircuit(2, 2)\\n if not bug:\\n circuit.h(0)\\n circuit.cx(0, 1)\\n circuit.measure([0, 1], [0, 1])\\n return circuit\\n\\ncircuit = bell_candidate(bug=True)\\n'\n", "editable_circuit_lab(\n", " initial_code=editable_code,\n", " context={\"QuantumCircuit\": QuantumCircuit, \"simulate_counts\": simulate_counts},\n", " title='Studio 2: Defect Comparison',\n", " instructions='Use the bug toggle to construct a contrast case and explain what diagnostic conclusion the comparison supports.',\n", " shots=256,\n", ")\n" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Studio Prompt 3: Bounded Mitigation Note\n", "\n", "\n", " Finish by writing the most disciplined mitigation note you can: specific, useful, and limited.\n" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "demo_noise = build_demo_noise_model(\n", " single_qubit_error=0.01,\n", " two_qubit_error=0.05,\n", " readout_error=0.03,\n", ")\n", "\n", "def simulate_noisy_counts(circuit, shots=256):\n", " return simulate_counts(circuit, shots=shots, noise_model=demo_noise)\n", "\n", " editable_code = '\\nfrom qiskit import QuantumCircuit\\n\\ndef bell_candidate() -> QuantumCircuit:\\n circuit = QuantumCircuit(2, 2)\\n circuit.h(0)\\n circuit.cx(0, 1)\\n circuit.measure([0, 1], [0, 1])\\n return circuit\\n\\ncircuit = bell_candidate()\\n'\n", " editable_circuit_lab(\n", " initial_code=editable_code,\n", " context={\"QuantumCircuit\": QuantumCircuit, \"simulate_counts\": simulate_noisy_counts},\n", " title='Studio 3: Mitigation Note',\n", " instructions='Treat filtering or postselection as a diagnostic tool and say exactly what it improves and what it leaves unresolved.',\n", " shots=256,\n", " )\n" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "quiz_block([{'prompt': 'What is a strong studio outcome for this module?', 'options': ['A verification notebook that states an invariant, compares clean and noisy behavior, and writes a bounded mitigation note', 'A notebook that only declares the result noisy', 'A notebook that assumes any deviation is a design bug'], 'correct_index': 0, 'explanation': 'The studio should culminate in disciplined diagnosis, not generic complaint.'}, {'prompt': 'Why does this module belong in the professional band?', 'options': ['Because serious circuit work requires debugging and falsification habits, not only construction skill', 'Because noise makes design impossible', 'Because ideal simulation is obsolete'], 'correct_index': 0, 'explanation': 'Professional competence includes knowing how to test and challenge a design.'}], heading='Studio Design Check')\n" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Studio Debrief\n", "\n", "\n", " A strong studio notebook in this module reads like a careful case file. It says what should happen, what actually happened ideally, what changed under noise, and why any mitigation claim remains bounded by explicit evidence.\n" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Studio Standard\n", "\n", "A strong studio notebook is compact, explicit, and reviewable. It does not hide behind volume. It makes the objective clear, the candidate or case structure visible, the evidence traceable, and the final judgement conditional in the right way. If those things are not yet present, the notebook is not finished no matter how many cells it contains.\n" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## What A Finished Studio Should Feel Like\n", "\n", "The finished notebook should feel like something another engineer could open and use. They should be able to understand what the notebook is trying to decide, how the circuits were compared, what evidence was gathered, and why the recommendation or diagnosis ended where it did. That is the practical definition of \"world-class\" in this project: not theatrical polish, but concentrated clarity under real engineering burdens.\n" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Final Check Before You Stop\n", "\n", "Before you leave a studio notebook, ask one last question: if another engineer disagreed with my conclusion, would the notebook give them enough material to locate the disagreement precisely? If the answer is yes, the studio is doing its job.\n" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "reflection_box('Which invariant anchored your final verification case study?')\n" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "reflection_box('What evidence let you separate defect from distortion most confidently?')\n" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "reflection_box('How did you keep your mitigation note bounded and honest?')\n" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "reflection_box('Name one verification habit from this module that must survive into the capstone.')\n" ] } ], "metadata": { "kernelspec": { "display_name": "QuantumLearning (.venv)", "language": "python", "name": "quantum-learning" }, "language_info": { "name": "python", "version": "3.12" } }, "nbformat": 4, "nbformat_minor": 5 }