Day 7 — Visualization & QASM
Math Prep
Solve this BEFORE lesson.md. Day 7's tools (plot_bloch_multivector, plot_state_qsphere, plot_state_city, histograms) each draw a specific mathematical object. Know the object, and every plot question becomes a computation.
Requires: Day 1 + Day 3 math prep. Video back-up: freeCodeCamp course (Bloch sphere section); Watrous Lesson 09 (Bloch ball); notes in resource-artifactory/notes/video-notes/.
1. The Bloch sphere — every 1-qubit state is a point on a ball
Any 1-qubit pure state can be written (global phase fixed away) as
are spherical coordinates: θ from the north pole, φ around the equator. Equivalently, the Bloch vector
Landmarks (memorize as pictures):
| State | Bloch vector | Position | |
|---|---|---|---|
| north pole | |||
| south pole | |||
| +x | |||
| −x | |||
| +y | |||
| −y |
Orthogonal states are antipodal (NOT perpendicular) on the sphere — Hilbert-space 90° becomes 180° on the sphere because of the half-angle.
2. Gates are rotations of the sphere
- : 180° rotations about their own axes. ( swaps poles — hence NOT.)
- : rotations by exactly θ about x/y/z. (Matrix half-angle ↔ full sphere angle — Day 2.)
- : 180° rotation about the diagonal axis — swaps x-axis ↔ z-axis, so , .
- : 90° rotation about z: . : 45° about z.
- Phase gates never move the poles (only rotate about z) — that's "Z-family gates don't change measurement probabilities" drawn geometrically.
Mixed states live INSIDE the ball: with ; pure ⇔ surface, maximally mixed ⇔ center (). Each qubit of a Bell pair plots at the center — that's how plot_bloch_multivector betrays entanglement (it shows per-qubit reduced states, and can never show the correlations themselves).
3. The Q-sphere — one ball for the WHOLE register
plot_state_qsphere is a different object: one node per basis state of all qubits.
- Node position: latitude by Hamming weight of ( north pole, south pole).
- Node size ∝ (probability).
- Node color = phase : 0 and π sit on opposite sides of the color wheel.
So Bell : two equal nodes ( north, south), same color. : same two nodes, opposite colors — the plot that distinguishes what histograms can't.
4. City / matrix plots — drawing ρ itself
plot_state_city draws the density matrix entries as bars (real and imaginary parts separately).
- Diagonal bars = probabilities.
- Off-diagonal bars = coherences: present for superpositions, ZERO for classical mixtures — the visual pure-vs-mixed test (Day 3 §5).
- Bell state: 4 corner bars of height 0.5 at positions (00,00), (00,11), (11,00), (11,11).
5. Histograms — drawing the sampled distribution
plot_histogram(counts) is Day 5's as bars; plot_distribution normalizes to probabilities. Phases are invisible here (Day 5 §1). GHZ and Bell histograms look identical in shape (two bars) — only the labels ('000'/'111' vs '00'/'11') differ.
PROBLEMS
P1. Give and the Bloch vector for . Where does it sit on the sphere?
P2. Start at . Apply H, then S, then H. Track the Bloch point through each step and name the final state.
P3. Is ry(π/2) on the same state as h on ? Is ry(π/2) the same gate as h? Check on both and .
P4. A Bloch-multivector plot of a 2-qubit state shows BOTH qubit arrows with zero length. Give two different global states consistent with the plot — one entangled pure state, one unentangled (mixed) state. What does zero-length force if the global state is known to be pure?
P5. Q-sphere shows nodes at and , equal size, colors 180° apart on the wheel. Write the state. What would its counts histogram look like vs 's?
P6. For : compute the Bloch vector and the density-matrix (city-plot) bars.
P7. is applied 8 times to . Describe the trajectory on the Bloch sphere and the final state.
ANSWERS
A1. , . Bloch vector — in the y–z plane, halfway between +y and +z (45° down from the north pole toward +y).
A2. (+x) (+y) : H maps , so = (up to global phase).
A3. Same state on : . Different gates: on , while . Same ray but opposite sign — and that sign is relative once these gates act inside superpositions or controlled contexts, so the operators are genuinely different ( but ).
A4. Zero arrows = both reduced states are . Entangled pure option: any Bell state. Unentangled option: the product of two maximally-mixed qubits (two independently randomized qubits). If the global state is pure, zero-length arrows force entanglement — a pure product state always shows two unit-length arrows.
A5. (phase π on the node). Histogram: identical to 's — two equal bars at '00' and '11'. Q-sphere sees phase; histograms never do.
A6. , . Bloch vector . : city bars 0.75 and 0.25 on the diagonal, on both off-diagonals, all real (imaginary city empty).
A7. Each T rotates 45° about z along the equator: visits 8 equally-spaced equatorial points and returns to , since .
Self-check: you can place any on the sphere, rotate it by any named gate mentally, decode q-sphere size/color, and explain why per-qubit Bloch arrows shrink for entangled states.