QuantumLearning/notebooks/professional/module_01_qiskit_patterns/problems.ipynb

311 lines
13 KiB
Text

{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# Qiskit Patterns and Workflow Design Problems\n"
],
"id": "da23abc1"
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"<!-- COURSE_NAV_TOP -->\n",
"## Mainline Navigation\n",
"\n",
"Step 45 of 59. Follow the mainline in order and do not skip ahead.\n",
"\n",
"Previous notebook: [Qiskit Patterns and Workflow Design Lab](lab.ipynb)\n",
"\n",
"Next notebook: [Qiskit Patterns and Workflow Design Studio](studio.ipynb)\n",
"\n",
"Rule: finish this notebook top-to-bottom before you open the next one.\n"
],
"id": "5db9d16c"
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"These problems test whether you can reason about patterns as engineering artifacts rather than only as circuit snippets.\n"
],
"id": "bca078a2"
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## How To Use This Notebook\n",
"\n",
"\n",
" When an answer sounds attractive because it compresses several responsibilities into one vague statement, treat that as a warning sign. The strong answers in this module preserve clear boundaries between intent, circuit body, and evidence.\n"
],
"id": "aa8fbedb"
},
{
"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 quantum_learning import (\n",
" build_demo_noise_model,\n",
" counts_to_probabilities,\n",
" draw_circuit,\n",
" editable_circuit_lab,\n",
" evidence_checklist,\n",
" feedback_iteration_panel,\n",
" line_coupling_map,\n",
" load_assessment_blueprint,\n",
" plot_counts,\n",
" plot_probabilities,\n",
" quiz_block,\n",
" reflection_box,\n",
" rubric_scorecard,\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"
],
"id": "933f1ed0"
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Workflow Boundaries\n",
"\n",
"Treat these questions as miniature review situations rather than as trivia. The correct answer should survive a serious engineering conversation.\n"
],
"id": "8150ddb3"
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"quiz_block([{'prompt': 'Which comment is strongest in a workflow review?', 'options': ['The pattern hides where the question changes and where the circuit stays stable', 'The circuit is quantum enough', 'Please make the code shorter regardless of meaning'], 'correct_index': 0, 'explanation': 'Workflow patterns are judged by the clarity of their boundaries.'}, {'prompt': 'What belongs outside the quantum routine in a good pattern?', 'options': ['Configuration of the experimental question and downstream scoring choices', 'All measurement logic', 'Every explanation cell'], 'correct_index': 0, 'explanation': 'The routine should stay stable while the surrounding workflow varies.'}], heading='Workflow Boundaries')\n"
],
"id": "34ec289a"
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Evidence Records\n",
"\n",
"Treat these questions as miniature review situations rather than as trivia. The correct answer should survive a serious engineering conversation.\n"
],
"id": "be931743"
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"quiz_block([{'prompt': 'Why is a derived score often more useful than raw counts alone?', 'options': ['It makes the decision rule explicit and reviewable', 'It removes the need to keep counts', 'It always improves accuracy'], 'correct_index': 0, 'explanation': 'Good post-processing clarifies what the workflow is claiming.'}, {'prompt': 'What is the danger of no recorded compile or execution context?', 'options': ['A later reader cannot reconstruct which environment assumptions shaped the result', 'The circuit stops being unitary', 'The notebook cannot include plots'], 'correct_index': 0, 'explanation': 'Pattern notebooks should preserve enough context for re-interpretation and critique.'}], heading='Evidence Records')\n"
],
"id": "98506fc9"
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Variation Pressure\n",
"\n",
"Treat these questions as miniature review situations rather than as trivia. The correct answer should survive a serious engineering conversation.\n"
],
"id": "e0e9884f"
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"quiz_block([{'prompt': 'What tests whether a pattern is real rather than accidental?', 'options': ['Changing a small input condition and seeing whether the stable routine still makes sense', 'Adding more notebook themes', 'Removing every helper function'], 'correct_index': 0, 'explanation': 'Patterns become visible under controlled variation.'}, {'prompt': 'Why do pattern notebooks belong in the professional band?', 'options': ['Because circuits in real projects live inside larger workflows, not alone', 'Because basic gates no longer matter', 'Because algorithms are no longer relevant'], 'correct_index': 0, 'explanation': 'Professional work embeds quantum routines inside a broader engineering loop.'}], heading='Variation Pressure')\n"
],
"id": "04711eb4"
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Review Language\n",
"\n",
"Treat these questions as miniature review situations rather than as trivia. The correct answer should survive a serious engineering conversation.\n"
],
"id": "53113807"
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"quiz_block([{'prompt': 'Which review statement is strongest?', 'options': ['The scoring logic depends on a readout order that the builder never states explicitly', 'The diagram looks nice', 'The notebook should remove every markdown explanation'], 'correct_index': 0, 'explanation': 'The issue is the hidden interface assumption between circuit and workflow record.'}, {'prompt': 'What should a good workflow pattern survive?', 'options': ['Controlled changes in inputs, basis choice, and scoring emphasis without losing clarity', 'Only the exact original notebook cell order', 'The absence of any documentation'], 'correct_index': 0, 'explanation': 'Patterns are valuable because they handle variation gracefully.'}], heading='Review Language')\n"
],
"id": "baa5c5f1"
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Mini Case\n",
"\n",
"\n",
" A very common failure in notebook-heavy projects is the illusion of reuse. A cell is copied a few times, a parameter or two is exposed, and the writer calls the result a pattern. But the pattern is not real if the question being asked is still implicit, the output interpretation depends on unstated conventions, or a future reader cannot tell which parts are meant to vary. These problems are trying to inoculate you against that weak standard.\n"
],
"id": "1b0ef99f"
},
{
"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 you can preserve the right burdens while the wording shifts. If your understanding is strong, a changed phrase still points you back to the same structure, constraint, invariant, or recommendation logic. If your understanding is weak, the wording change will tempt you into vague or prestige-based answers. That is why these problem sets matter.\n"
],
"id": "5958b61b"
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Common Failure Mode\n",
"\n",
"A common failure mode in advanced notebook work is broad correctness with local vagueness. A learner says something true at a high level, yet still fails to name what this particular workflow, redesign, diagnosis, or recommendation is actually doing. The problems notebook is meant to squeeze that vagueness out. It prefers circuit-specific or review-specific sentences over vague correctness.\n"
],
"id": "65391384"
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Why Written Justification Matters\n",
"\n",
"The written prompts at the end of this notebook are not filler. They are where you prove that the right distinctions are surviving contact with your own prose. Multiple-choice blocks can tell you whether a distinction still feels recognizable. A written answer tells you whether you can actually deploy that distinction in a design note, verification memo, or review comment. Professional skill depends on that second ability.\n"
],
"id": "04f1efab"
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Written Checks\n",
"\n",
"Use the prompts below to practice full-sentence engineering judgement.\n"
],
"id": "22207a38"
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"reflection_box('Explain why an execution record with no design brief is weaker than it first appears.')\n"
],
"id": "f95f119f"
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"reflection_box('Describe the minimum information a local-first workflow notebook should record so another engineer can rerun and critique it.')\n"
],
"id": "f54858e0"
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"feedback_iteration_panel(title='Qiskit Patterns and Workflow Design Problem-Set Review Loop', prompt='After the quizzes, write the claim you now trust most, the evidence pattern behind it, the phrasing that still feels weak, and the next rewrite you owe yourself.')\n"
],
"id": "31c2fbbb"
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"assessment_blueprint = load_assessment_blueprint()\n",
"rubric_scorecard(\n",
" assessment_blueprint.get_rubric('module_self_review'),\n",
" title='Qiskit Patterns and Workflow Design Problem Self-Grading',\n",
")\n"
],
"id": "1b15bbe4"
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Exit Condition\n",
"\n",
"\n",
" Move on when you can read a notebook as a workflow pattern with responsibilities, not merely as a series of runnable cells.\n"
],
"id": "e84e90b4"
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"<!-- COURSE_NAV_BOTTOM -->\n",
"## What To Open Next\n",
"\n",
"Next notebook: [Qiskit Patterns and Workflow Design Studio](studio.ipynb)\n",
"\n",
"When you finish this notebook, open the next notebook shown above. Stay on the guarded mainline route.\n"
],
"id": "4bf55303"
}
],
"metadata": {
"kernelspec": {
"display_name": "QuantumLearning (.venv)",
"language": "python",
"name": "quantum-learning"
},
"language_info": {
"name": "python",
"version": "3.12"
}
},
"nbformat": 4,
"nbformat_minor": 5
}