{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "\n", "
\n", "META READING · Difficulty 1/10 · Notebook-level rule, objective, or usage guidance.\n", "
\n", "\n", "# Qiskit Patterns and Workflow Design Studio\n" ], "id": "ad02d95f" }, { "cell_type": "markdown", "metadata": {}, "source": [ "\n", "
\n", "META READING · Difficulty 1/10 · Official walkthrough guardrail.\n", "
\n", "\n", "\n", "## Mainline Navigation\n", "\n", "Step 46 of 59. Follow the official walkthrough in order.\n", "\n", "Previous notebook: [Qiskit Patterns and Workflow Design Problems](problems.ipynb)\n", "\n", "Next notebook: [Hardware-Aware Redesign Studio Lecture](../module_02_hardware_aware_redesign/lecture.ipynb)\n", "\n", "Rule: complete the mandatory cells in this notebook before you open the next one.\n" ], "id": "f8126da6" }, { "cell_type": "markdown", "metadata": {}, "source": [ "\n", "
\n", "META READING · Difficulty 1/10 · Notebook-level rule, objective, or usage guidance.\n", "
\n", "\n", "The studio turns the module into a design exercise: create a small workflow artifact that you would actually trust and hand to another engineer.\n" ], "id": "d9889f1a" }, { "cell_type": "markdown", "metadata": {}, "source": [ "\n", "
\n", "META READING · Difficulty 1/10 · Notebook-level rule, objective, or usage guidance.\n", "
\n", "\n", "## Design Brief\n", "\n", "\n", " Build a compact local-first pattern notebook that exposes configuration, quantum routine, execution assumptions, and result interpretation clearly enough that a reviewer could modify one layer without guessing what the other layers are doing.\n" ], "id": "ac175eab" }, { "cell_type": "markdown", "metadata": { "ql_injected": "badge", "ql_track": "mandatory", "ql_role": "setup" }, "source": [ "\n", "
\n", "MANDATORY SETUP · Difficulty 1/10 · Environment, import, or helper cell required by the notebook.\n", "
\n" ], "id": "d3172a31" }, { "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": "8ad03118" }, { "cell_type": "markdown", "metadata": { "ql_injected": "badge", "ql_track": "mandatory", "ql_role": "exercise" }, "source": [ "\n", "
\n", "MANDATORY EXERCISE · Difficulty 3/10 · Official walkthrough runnable or written exercise.\n", "
\n" ], "id": "540f0930" }, { "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": "aa77b87b" }, { "cell_type": "markdown", "metadata": {}, "source": [ "\n", "
\n", "META READING · Difficulty 1/10 · Notebook-level rule, objective, or usage guidance.\n", "
\n", "\n", "## Studio Prompt 1: Reusable Workflow Shell\n", "\n", "\n", " Create a small pattern shell that makes the stable routine visible and parameterizes the question being asked. The challenge is clarity, not size.\n" ], "id": "69089475" }, { "cell_type": "markdown", "metadata": { "ql_injected": "badge", "ql_track": "mandatory", "ql_role": "exercise" }, "source": [ "\n", "
\n", "MANDATORY EXERCISE · Difficulty 3/10 · Official walkthrough runnable or written exercise.\n", "
\n" ], "id": "256f55de" }, { "cell_type": "code", "execution_count": null, "metadata": { "jupyter": { "source_hidden": true }, "tags": [ "hide-input" ] }, "outputs": [], "source": [ "editable_code = '\\nfrom qiskit import QuantumCircuit\\n\\ndef build_agreement_probe(basis: str = \"z\") -> QuantumCircuit:\\n circuit = QuantumCircuit(2, 2)\\n # [1] The workflow chooses the question before the circuit is built.\\n circuit.h(0)\\n circuit.cx(0, 1)\\n # [2] Basis adaptation belongs in its own visible layer.\\n if basis == \"x\":\\n circuit.h([0, 1])\\n elif basis != \"z\":\\n raise ValueError(\"basis must be \\'z\\' or \\'x\\'\")\\n # [3] Keep the reporting contract explicit.\\n circuit.measure([0, 1], [0, 1])\\n return circuit\\n\\ncircuit = build_agreement_probe(basis=\"x\")\\n'\n", "editable_circuit_lab(\n", " initial_code=editable_code,\n", " context={\"QuantumCircuit\": QuantumCircuit, \"simulate_counts\": simulate_counts},\n", " title='Studio 1: Workflow Shell',\n", " instructions='Refine the builder until the question layer and the stable circuit layer are visibly separate.',\n", " shots=256,\n", ")\n" ], "id": "aa637212" }, { "cell_type": "markdown", "metadata": {}, "source": [ "\n", "
\n", "META READING · Difficulty 1/10 · Notebook-level rule, objective, or usage guidance.\n", "
\n", "\n", "## Studio Prompt 2: Explicit Result Record\n", "\n", "\n", " Turn the same pattern into a notebook that would still make sense a week later by recording what was asked and how the result should be interpreted.\n" ], "id": "f0a08151" }, { "cell_type": "markdown", "metadata": { "ql_injected": "badge", "ql_track": "mandatory", "ql_role": "exercise" }, "source": [ "\n", "
\n", "MANDATORY EXERCISE · Difficulty 3/10 · Official walkthrough runnable or written exercise.\n", "
\n" ], "id": "f726e04e" }, { "cell_type": "code", "execution_count": null, "metadata": { "jupyter": { "source_hidden": true }, "tags": [ "hide-input" ] }, "outputs": [], "source": [ "editable_code = '\\nfrom qiskit import QuantumCircuit\\n\\ndef build_probe(basis: str = \"z\", add_barrier: bool = True) -> QuantumCircuit:\\n circuit = QuantumCircuit(2, 2)\\n circuit.h(0)\\n circuit.cx(0, 1)\\n if add_barrier:\\n circuit.barrier()\\n if basis == \"x\":\\n circuit.h([0, 1])\\n elif basis != \"z\":\\n raise ValueError(\"basis must be \\'z\\' or \\'x\\'\")\\n circuit.measure([0, 1], [0, 1])\\n return circuit\\n\\ncircuit = build_probe(basis=\"z\", add_barrier=True)\\n'\n", "editable_circuit_lab(\n", " initial_code=editable_code,\n", " context={\"QuantumCircuit\": QuantumCircuit, \"simulate_counts\": simulate_counts},\n", " title='Studio 2: Result Record Pattern',\n", " instructions='Structure the pattern so a downstream result record could be attached without guessing hidden assumptions.',\n", " shots=256,\n", ")\n" ], "id": "97884185" }, { "cell_type": "markdown", "metadata": {}, "source": [ "\n", "
\n", "MANDATORY READING · Difficulty 3/10 · Official walkthrough reading cell.\n", "
\n", "\n", "## Studio Prompt 3: Interface Audit\n", "\n", "\n", " Use the reporting-contract variant to write a short interface audit. If the reporting order changes, what else in the workflow must change with it?\n" ], "id": "dd8b7521" }, { "cell_type": "markdown", "metadata": { "ql_injected": "badge", "ql_track": "mandatory", "ql_role": "exercise" }, "source": [ "\n", "
\n", "MANDATORY EXERCISE · Difficulty 3/10 · Official walkthrough runnable or written exercise.\n", "
\n" ], "id": "ed0949ad" }, { "cell_type": "code", "execution_count": null, "metadata": { "jupyter": { "source_hidden": true }, "tags": [ "hide-input" ] }, "outputs": [], "source": [ "editable_code = '\\nfrom qiskit import QuantumCircuit\\n\\ndef build_probe(swapped_report: bool = False) -> QuantumCircuit:\\n circuit = QuantumCircuit(2, 2)\\n circuit.h(0)\\n circuit.cx(0, 1)\\n if swapped_report:\\n circuit.measure([0, 1], [1, 0])\\n else:\\n circuit.measure([0, 1], [0, 1])\\n return circuit\\n\\ncircuit = build_probe(swapped_report=False)\\n'\n", "editable_circuit_lab(\n", " initial_code=editable_code,\n", " context={\"QuantumCircuit\": QuantumCircuit, \"simulate_counts\": simulate_counts},\n", " title='Studio 3: Interface Audit',\n", " instructions='Treat the reporting map as an API decision and explain what a reviewer would need to know before trusting it.',\n", " shots=256,\n", ")\n" ], "id": "8cb6f661" }, { "cell_type": "markdown", "metadata": { "ql_injected": "badge", "ql_track": "mandatory", "ql_role": "test" }, "source": [ "\n", "
\n", "MANDATORY TEST · Difficulty 3/10 · Official walkthrough multiple-choice test.\n", "
\n" ], "id": "81b9a6e6" }, { "cell_type": "code", "execution_count": null, "metadata": { "jupyter": { "source_hidden": true }, "tags": [ "hide-input" ] }, "outputs": [], "source": [ "quiz_block([{'prompt': 'What is a strong studio deliverable for this module?', 'options': ['A small, configurable workflow notebook with a clear circuit builder and a reviewable result record', 'A single screenshot of one circuit', 'A notebook with no post-processing because counts are enough'], 'correct_index': 0, 'explanation': 'The studio should produce a reusable local-first pattern artifact.'}, {'prompt': 'Why is explicit workflow prose still necessary here?', 'options': ['Because the professional value of the notebook lies in the interfaces and decision logic as much as in the circuit', 'Because the circuit is unimportant', 'Because prose replaces execution'], 'correct_index': 0, 'explanation': 'The prose tells reviewers how the pattern is meant to be used and judged.'}], heading='Studio Design Check')\n" ], "id": "9ebf53b3" }, { "cell_type": "markdown", "metadata": { "ql_injected": "badge", "ql_track": "mandatory", "ql_role": "exercise" }, "source": [ "\n", "
\n", "MANDATORY EXERCISE · Difficulty 3/10 · Official walkthrough runnable or written exercise.\n", "
\n" ], "id": "3609926b" }, { "cell_type": "code", "execution_count": null, "metadata": { "jupyter": { "source_hidden": true }, "tags": [ "hide-input" ] }, "outputs": [], "source": [ "evidence_checklist(['The notebook states the objective or decision clearly.', 'The relevant constraints are explicit and stable.', 'Evidence is tied to a concrete circuit, output, or metric.', 'At least one uncertainty or risk is named explicitly.', 'The notebook ends with a next action or defended judgement.'], title='Qiskit Patterns and Workflow Design Evidence Checklist')\n" ], "id": "cc3ff54b" }, { "cell_type": "markdown", "metadata": {}, "source": [ "\n", "
\n", "MANDATORY READING · Difficulty 3/10 · Official walkthrough reading cell.\n", "
\n", "\n", "## Studio Debrief\n", "\n", "\n", " A strong studio notebook in this module feels like a small internal tool. It does not only show a circuit. It states how the circuit is being asked to act inside a wider local-first workflow and how the notebook arrives at its interpretation of the result.\n" ], "id": "6160ff3e" }, { "cell_type": "markdown", "metadata": {}, "source": [ "\n", "
\n", "MANDATORY READING · Difficulty 3/10 · Official walkthrough reading cell.\n", "
\n", "\n", "## 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" ], "id": "fba3a7ae" }, { "cell_type": "markdown", "metadata": {}, "source": [ "\n", "
\n", "MANDATORY READING · Difficulty 3/10 · Official walkthrough reading cell.\n", "
\n", "\n", "## 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" ], "id": "d39427de" }, { "cell_type": "markdown", "metadata": {}, "source": [ "\n", "
\n", "MANDATORY READING · Difficulty 3/10 · Official walkthrough reading cell.\n", "
\n", "\n", "## 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" ], "id": "9acd51fa" }, { "cell_type": "markdown", "metadata": { "ql_injected": "badge", "ql_track": "mandatory", "ql_role": "exercise" }, "source": [ "\n", "
\n", "MANDATORY EXERCISE · Difficulty 3/10 · Official walkthrough runnable or written exercise.\n", "
\n" ], "id": "4304ae2c" }, { "cell_type": "code", "execution_count": null, "metadata": { "jupyter": { "source_hidden": true }, "tags": [ "hide-input" ] }, "outputs": [], "source": [ "reflection_box('Which part of your workflow shell would another engineer most likely need to change first?')\n" ], "id": "19d0e5b2" }, { "cell_type": "markdown", "metadata": { "ql_injected": "badge", "ql_track": "mandatory", "ql_role": "exercise" }, "source": [ "\n", "
\n", "MANDATORY EXERCISE · Difficulty 3/10 · Official walkthrough runnable or written exercise.\n", "
\n" ], "id": "c1288e5e" }, { "cell_type": "code", "execution_count": null, "metadata": { "jupyter": { "source_hidden": true }, "tags": [ "hide-input" ] }, "outputs": [], "source": [ "reflection_box('How did you make the reporting contract explicit in the final studio version?')\n" ], "id": "1851df96" }, { "cell_type": "markdown", "metadata": { "ql_injected": "badge", "ql_track": "mandatory", "ql_role": "exercise" }, "source": [ "\n", "
\n", "MANDATORY EXERCISE · Difficulty 3/10 · Official walkthrough runnable or written exercise.\n", "
\n" ], "id": "d9d75308" }, { "cell_type": "code", "execution_count": null, "metadata": { "jupyter": { "source_hidden": true }, "tags": [ "hide-input" ] }, "outputs": [], "source": [ "reflection_box('What information did you decide belonged in the final result record?')\n" ], "id": "74999ff3" }, { "cell_type": "markdown", "metadata": { "ql_injected": "badge", "ql_track": "mandatory", "ql_role": "exercise" }, "source": [ "\n", "
\n", "MANDATORY EXERCISE · Difficulty 3/10 · Official walkthrough runnable or written exercise.\n", "
\n" ], "id": "e7290783" }, { "cell_type": "code", "execution_count": null, "metadata": { "jupyter": { "source_hidden": true }, "tags": [ "hide-input" ] }, "outputs": [], "source": [ "reflection_box('Name one workflow habit from this module that should survive all later capstone work.')\n" ], "id": "bef1d174" }, { "cell_type": "markdown", "metadata": { "ql_injected": "badge", "ql_track": "mandatory", "ql_role": "exercise" }, "source": [ "\n", "
\n", "MANDATORY EXERCISE · Difficulty 3/10 · Official walkthrough runnable or written exercise.\n", "
\n" ], "id": "7342642e" }, { "cell_type": "code", "execution_count": null, "metadata": { "jupyter": { "source_hidden": true }, "tags": [ "hide-input" ] }, "outputs": [], "source": [ "feedback_iteration_panel(title='Qiskit Patterns and Workflow Design Studio Revision Loop', prompt='Write the decision or diagnosis the studio currently supports, the evidence carrying that weight, the main remaining uncertainty, and the next revision that would sharpen the notebook.')\n" ], "id": "5f68c7a5" }, { "cell_type": "markdown", "metadata": { "ql_injected": "badge", "ql_track": "mandatory", "ql_role": "exercise" }, "source": [ "\n", "
\n", "MANDATORY EXERCISE · Difficulty 3/10 · Official walkthrough runnable or written exercise.\n", "
\n" ], "id": "bd91d432" }, { "cell_type": "code", "execution_count": null, "metadata": { "jupyter": { "source_hidden": true }, "tags": [ "hide-input" ] }, "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 Studio Self-Grading',\n", ")\n" ], "id": "0c4ad953" }, { "cell_type": "markdown", "metadata": {}, "source": [ "\n", "
\n", "META READING · Difficulty 1/10 · Official walkthrough guardrail.\n", "
\n", "\n", "\n", "## What To Open Next\n", "\n", "Next notebook: [Hardware-Aware Redesign Studio Lecture](../module_02_hardware_aware_redesign/lecture.ipynb)\n", "\n", "Official walkthrough rule: once every mandatory cell above is complete, open the next notebook. Anything below this cell is facultative.\n" ], "id": "1bd97437" }, { "cell_type": "markdown", "metadata": { "ql_injected": "facultative_zone", "ql_track": "meta", "ql_role": "reading", "ql_difficulty": 1, "ql_note": "Optional-zone boundary. The official walkthrough is already complete above." }, "source": [ "\n", "
\n", "META READING · Difficulty 1/10 · Optional-zone boundary. The official walkthrough is already complete above.\n", "
\n", "\n", "\n", "## Facultative Extension Zone\n", "\n", "You have already completed the mandatory walkthrough for **Qiskit Patterns and Workflow Design Studio**. Everything below is optional. Use it only if you want deeper consolidation or extra transfer work.\n" ], "id": "2c35239a" }, { "cell_type": "markdown", "metadata": { "ql_injected": "facultative", "ql_track": "facultative", "ql_role": "reading", "ql_difficulty": 5, "ql_note": "Optional extension reading." }, "source": [ "\n", "
\n", "FACULTATIVE READING · Difficulty 5/10 · Optional extension reading.\n", "
\n", "\n", "## Facultative Extension Reading\n", "\n", "Use this optional studio extension only if the mandatory route in **Qiskit Patterns and Workflow Design Studio** feels stable. The right stretch here is not random complexity; it is one extra candidate, one sharper criterion, and one clearer written defence of the final decision.\n" ], "id": "6db37657" }, { "cell_type": "markdown", "metadata": { "ql_injected": "badge", "ql_track": "facultative", "ql_role": "test" }, "source": [ "\n", "
\n", "FACULTATIVE TEST · Difficulty 6/10 · Optional multiple-choice extension.\n", "
\n" ], "id": "ae1ab27a" }, { "cell_type": "code", "execution_count": null, "metadata": { "ql_injected": "facultative", "ql_track": "facultative", "ql_role": "test", "ql_difficulty": 6, "ql_note": "Optional multiple-choice extension.", "jupyter": { "source_hidden": true }, "tags": [ "hide-input" ] }, "outputs": [], "source": [ "quiz_block([{'prompt': 'What makes a facultative studio stretch worthwhile?', 'options': ['It sharpens a design judgement without breaking the single mandatory route', 'It replaces the mandatory brief', 'It adds complexity with no explicit criterion'], 'correct_index': 0, 'explanation': 'A studio stretch should sharpen judgement, not blur the route.'}, {'prompt': 'If a stretch candidate fails, what should change first?', 'options': ['The written explanation of the failure and the next criterion', 'The notebook order', 'The insistence that the failed candidate was still best'], 'correct_index': 0, 'explanation': 'The useful move is clearer review language and a better criterion.'}], heading='Facultative Extension Test')\n" ], "id": "bd3683ea" }, { "cell_type": "markdown", "metadata": { "ql_injected": "badge", "ql_track": "facultative", "ql_role": "exercise" }, "source": [ "\n", "
\n", "FACULTATIVE EXERCISE · Difficulty 7/10 · Optional written exercise.\n", "
\n" ], "id": "73411607" }, { "cell_type": "code", "execution_count": null, "metadata": { "ql_injected": "facultative", "ql_track": "facultative", "ql_role": "exercise", "ql_difficulty": 7, "ql_note": "Optional written exercise.", "jupyter": { "source_hidden": true }, "tags": [ "hide-input" ] }, "outputs": [], "source": [ "reflection_box('Write one optional stretch brief for Qiskit Patterns and Workflow Design Studio: objective, criterion, and the single risk that would matter most in your design review.')\n" ], "id": "a3c3df5f" } ], "metadata": { "kernelspec": { "display_name": "QuantumLearning (.venv)", "language": "python", "name": "quantum-learning" }, "language_info": { "name": "python", "version": "3.12" } }, "nbformat": 4, "nbformat_minor": 5 }