mirror of
https://github.com/saymrwulf/QuantumLearning.git
synced 2026-05-14 20:58:00 +00:00
272 lines
11 KiB
Text
272 lines
11 KiB
Text
{
|
|
"cells": [
|
|
{
|
|
"cell_type": "markdown",
|
|
"metadata": {},
|
|
"source": [
|
|
"# QFT and Periodic Structure Problems\n"
|
|
],
|
|
"id": "8b1f3cb4"
|
|
},
|
|
{
|
|
"cell_type": "markdown",
|
|
"metadata": {},
|
|
"source": [
|
|
"<!-- COURSE_NAV_TOP -->\n",
|
|
"## Mainline Navigation\n",
|
|
"\n",
|
|
"Step 37 of 59. Follow the mainline in order and do not skip ahead.\n",
|
|
"\n",
|
|
"Previous notebook: [QFT and Periodic Structure Lab](lab.ipynb)\n",
|
|
"\n",
|
|
"Next notebook: [QFT and Periodic Structure Studio](studio.ipynb)\n",
|
|
"\n",
|
|
"Rule: finish this notebook top-to-bottom before you open the next one.\n"
|
|
],
|
|
"id": "647f8767"
|
|
},
|
|
{
|
|
"cell_type": "markdown",
|
|
"metadata": {},
|
|
"source": [
|
|
"These problems check whether you can keep the QFT grounded in explicit roles instead of slipping back into name-based mystique.\n"
|
|
],
|
|
"id": "48ca19ff"
|
|
},
|
|
{
|
|
"cell_type": "markdown",
|
|
"metadata": {},
|
|
"source": [
|
|
"## How To Use This Notebook\n",
|
|
"\n",
|
|
"\n",
|
|
" Whenever an answer sounds appealing because it is vague, reject it. This module improves only if you become more precise about basis change, phase structure, ordering, and verification.\n"
|
|
],
|
|
"id": "6994be80"
|
|
},
|
|
{
|
|
"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"
|
|
],
|
|
"id": "50c7b992"
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": null,
|
|
"metadata": {},
|
|
"outputs": [],
|
|
"source": [
|
|
"from math import pi\n",
|
|
"\n",
|
|
"from quantum_learning import (\n",
|
|
" counts_to_probabilities,\n",
|
|
" draw_circuit,\n",
|
|
" editable_circuit_lab,\n",
|
|
" plot_counts,\n",
|
|
" plot_probabilities,\n",
|
|
" quiz_block,\n",
|
|
" reflection_box,\n",
|
|
" simulate_counts,\n",
|
|
" statevector_probabilities,\n",
|
|
" step_reference_table,\n",
|
|
")\n",
|
|
"from qiskit import QuantumCircuit\n",
|
|
"from qiskit.quantum_info import Statevector\n"
|
|
],
|
|
"id": "6d5918b3"
|
|
},
|
|
{
|
|
"cell_type": "markdown",
|
|
"metadata": {},
|
|
"source": [
|
|
"## Basis Change\n",
|
|
"\n",
|
|
"Treat this block as a miniature review situation. Choose the answer that would best survive an engineering conversation.\n"
|
|
],
|
|
"id": "28589408"
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": null,
|
|
"metadata": {},
|
|
"outputs": [],
|
|
"source": [
|
|
"quiz_block([{'prompt': 'Which phrase best captures the QFT at beginner-professional level?', 'options': ['A basis change that reorganizes periodic structure into readable phase relationships', 'A black-box acceleration primitive with no circuit meaning', 'A measurement shortcut'], 'correct_index': 0, 'explanation': 'Mechanistic language matters if you want to design with the QFT later.'}, {'prompt': \"Why is 'basis change' better language than 'magic transform'?\", 'options': ['Because it points you toward verification and interface questions', 'Because it removes the need for phase reasoning', 'Because it implies all amplitudes stay real'], 'correct_index': 0, 'explanation': 'Good language anchors good engineering questions.'}], heading='Basis Change')\n"
|
|
],
|
|
"id": "e59b1782"
|
|
},
|
|
{
|
|
"cell_type": "markdown",
|
|
"metadata": {},
|
|
"source": [
|
|
"## Controlled-Phase Reading\n",
|
|
"\n",
|
|
"Treat this block as a miniature review situation. Choose the answer that would best survive an engineering conversation.\n"
|
|
],
|
|
"id": "d5bb316b"
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": null,
|
|
"metadata": {},
|
|
"outputs": [],
|
|
"source": [
|
|
"quiz_block([{'prompt': 'What does the smallest-angle controlled phase represent in a 3-qubit QFT?', 'options': ['A weaker but still real contribution to the final phase pattern', 'A gate that can be ignored without consequence in every setting', 'A measurement of the least significant bit'], 'correct_index': 0, 'explanation': 'Its contribution is smaller, not conceptually meaningless.'}, {'prompt': 'Why do QFT circuits deserve line-by-line explanation?', 'options': ['Because many later algorithms embed them, so shallow memorization becomes expensive later', 'Because QFT never appears in serious work', 'Because all controlled phases are interchangeable'], 'correct_index': 0, 'explanation': 'This module installs vocabulary for later reuse.'}], heading='Controlled-Phase Reading')\n"
|
|
],
|
|
"id": "39d3b6cb"
|
|
},
|
|
{
|
|
"cell_type": "markdown",
|
|
"metadata": {},
|
|
"source": [
|
|
"## Ordering And Verification\n",
|
|
"\n",
|
|
"Treat this block as a miniature review situation. Choose the answer that would best survive an engineering conversation.\n"
|
|
],
|
|
"id": "54b00ec7"
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": null,
|
|
"metadata": {},
|
|
"outputs": [],
|
|
"source": [
|
|
"quiz_block([{'prompt': 'What is the strongest reason to discuss swaps explicitly?', 'options': ['They encode a bit-order convention that affects how results are interpreted', 'They are visually attractive', 'They remove the need for inverse verification'], 'correct_index': 0, 'explanation': \"Ordering is part of the transform's external contract.\"}, {'prompt': 'Which evidence is most persuasive when validating a small QFT implementation?', 'options': ['Statevector plots or inverse-composition checks tied to a written explanation', 'Only a final count histogram', 'Only gate count totals'], 'correct_index': 0, 'explanation': 'Basis-change circuits need representational evidence, not only sampled readout.'}], heading='Ordering And Verification')\n"
|
|
],
|
|
"id": "231baac7"
|
|
},
|
|
{
|
|
"cell_type": "markdown",
|
|
"metadata": {},
|
|
"source": [
|
|
"## Approximation Tradeoffs\n",
|
|
"\n",
|
|
"Treat this block as a miniature review situation. Choose the answer that would best survive an engineering conversation.\n"
|
|
],
|
|
"id": "503ea36f"
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": null,
|
|
"metadata": {},
|
|
"outputs": [],
|
|
"source": [
|
|
"quiz_block([{'prompt': 'Why might an engineer drop the smallest controlled-phase term?', 'options': ['To trade some transform fidelity for structural simplification under a cost budget', 'To make the circuit classical', 'To eliminate all ordering issues'], 'correct_index': 0, 'explanation': 'Approximation belongs to explicit tradeoff reasoning.'}, {'prompt': 'Which review comment is strongest?', 'options': ['This approximation is acceptable because the omitted phase term is least significant and the verification notebook shows the recovery gap clearly', 'I removed some gates because the circuit looked busy', 'Approximate QFT means exact output with fewer gates'], 'correct_index': 0, 'explanation': 'A professional defense ties structural changes to evidence and scope.'}], heading='Approximation Tradeoffs')\n"
|
|
],
|
|
"id": "71b8c168"
|
|
},
|
|
{
|
|
"cell_type": "markdown",
|
|
"metadata": {},
|
|
"source": [
|
|
"## Mini Case\n",
|
|
"\n",
|
|
"\n",
|
|
" The most common QFT failure mode in beginner material is reverent opacity. The transform is introduced with respect, but not with enough operational clarity. The learner comes away knowing that the QFT is important without knowing how to inspect, verify, or modify a small implementation. This problems notebook pushes directly against that failure. Importance without inspectability is not yet useful knowledge.\n"
|
|
],
|
|
"id": "fcca38ba"
|
|
},
|
|
{
|
|
"cell_type": "markdown",
|
|
"metadata": {},
|
|
"source": [
|
|
"## What These Questions Are Really Testing\n",
|
|
"\n",
|
|
"The multiple-choice format is only the surface. Underneath it, the notebook is testing whether your explanation can survive small shifts in phrasing, emphasis, and review context. If your understanding is robust, the wording can change and the same mechanism will still come into focus. If your understanding is fragile, the wording change will tempt you back into vague or prestige-based answers. That is why these problems matter.\n"
|
|
],
|
|
"id": "7f90af7d"
|
|
},
|
|
{
|
|
"cell_type": "markdown",
|
|
"metadata": {},
|
|
"source": [
|
|
"## Common Failure Mode\n",
|
|
"\n",
|
|
"A common failure mode at this stage is to answer with something broadly true but locally weak. For example, saying that a circuit uses superposition or interference may be accurate, yet still fail to identify what role a specific block is playing in the present design. The goal of the problems notebook is to eliminate that kind of vague correctness and replace it with circuit-specific explanation.\n"
|
|
],
|
|
"id": "28cac969"
|
|
},
|
|
{
|
|
"cell_type": "markdown",
|
|
"metadata": {},
|
|
"source": [
|
|
"## Written Checks\n",
|
|
"\n",
|
|
"Use the prompts below to rehearse full-sentence engineering explanations.\n"
|
|
],
|
|
"id": "a25e47b5"
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": null,
|
|
"metadata": {},
|
|
"outputs": [],
|
|
"source": [
|
|
"reflection_box('Explain why a beautiful circuit diagram is not enough evidence for a correct QFT implementation.')\n"
|
|
],
|
|
"id": "8e2ebdbc"
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": null,
|
|
"metadata": {},
|
|
"outputs": [],
|
|
"source": [
|
|
"reflection_box('Describe one concrete reason an engineer might choose a small approximate-QFT variant.')\n"
|
|
],
|
|
"id": "bb1e5a42"
|
|
},
|
|
{
|
|
"cell_type": "markdown",
|
|
"metadata": {},
|
|
"source": [
|
|
"## Exit Condition\n",
|
|
"\n",
|
|
"\n",
|
|
" Move on when you can read a 3-qubit QFT as a deliberate basis-change circuit and defend how you would verify it.\n"
|
|
],
|
|
"id": "221d0538"
|
|
},
|
|
{
|
|
"cell_type": "markdown",
|
|
"metadata": {},
|
|
"source": [
|
|
"<!-- COURSE_NAV_BOTTOM -->\n",
|
|
"## What To Open Next\n",
|
|
"\n",
|
|
"Next notebook: [QFT and Periodic Structure Studio](studio.ipynb)\n",
|
|
"\n",
|
|
"When you finish this notebook, open the next notebook shown above. Stay on the guarded mainline route.\n"
|
|
],
|
|
"id": "b721bf5e"
|
|
}
|
|
],
|
|
"metadata": {
|
|
"kernelspec": {
|
|
"display_name": "QuantumLearning (.venv)",
|
|
"language": "python",
|
|
"name": "quantum-learning"
|
|
},
|
|
"language_info": {
|
|
"name": "python",
|
|
"version": "3.12"
|
|
}
|
|
},
|
|
"nbformat": 4,
|
|
"nbformat_minor": 5
|
|
}
|