QuantumCore

Hands-on lab · 1 step

Grover search on three qubits

Build Grover's algorithm for N=8N=8 items and one marked item ww: the uniform superposition ∣s⟩=H⊗3∣000⟩\lvert s\rangle=H^{\otimes3}\lvert000\rangle followed by two iterations of the phase oracle Of=I−2∣w⟩⟨w∣O_f=I-2\lvert w\rangle\langle w\rvert and the diffuser D=2∣s⟩⟨s∣−ID=2\lvert s\rangle\langle s\rvert-I. The grader substitutes three different oracles (w=101w=101, 010010, 111111) into the placeholder and requires the distribution P(w)=sin⁡2(5θ)=121128P(w)=\sin^2(5\theta)=\tfrac{121}{128} with sin⁡θ=18\sin\theta=\tfrac1{\sqrt8}, every other outcome having probability 1128\tfrac1{128}.

0/1 step passedBest score 0/100

Step 1: Two Grover iterations for N = 8

The register has three qubits in ∣000⟩\lvert000\rangle; qubit 00 is the most significant bit, so ∣b0b1b2⟩\lvert b_0b_1b_2\rangle has index 4b0+2b1+b24b_0+2b_1+b_2.

The circuit already contains the oracle placeholder OfO_f twice. In the circuit editor it is the statement Of on its own line; keep it exactly twice, once per Grover iteration. The grader replaces both copies by the diagonal matrix Of=I8−2∣w⟩⟨w∣O_f=I_8-2\lvert w\rangle\langle w\rvert, i.e. the identity with the single entry (w,w)(w,w) changed to −1-1.

Allowed gates: HH, XX, ZZ, CZ\mathrm{CZ}, CCZ\mathrm{CCZ}, CNOT\mathrm{CNOT}, CCX\mathrm{CCX}; at most 3232 operations including both Of statements; no measurements.

Build H⊗3H^{\otimes3} followed by two copies of [ Of; diffuser ][\,O_f;\ \text{diffuser}\,]. The diffuser D=H⊗3(2∣000⟩⟨000∣−I)H⊗3D=H^{\otimes3}(2\lvert000\rangle\langle000\rvert-I)H^{\otimes3} equals, up to the global phase −1-1, the gate sequence H⊗3X⊗3 CCZ X⊗3H⊗3H^{\otimes3}X^{\otimes3}\,\mathrm{CCZ}\,X^{\otimes3}H^{\otimes3}, because X⊗3 CCZ X⊗3=I−2∣000⟩⟨000∣X^{\otimes3}\,\mathrm{CCZ}\,X^{\otimes3}=I-2\lvert000\rangle\langle000\rvert.

grover-cases (three oracles, w∈{101,010,111}w\in\{101,010,111\}): the full distribution on qubits [0,1,2][0,1,2] must equal P(w)=121128=0.9453125P(w)=\tfrac{121}{128}=0.9453125 and P(y)=1128=0.0078125P(y)=\tfrac1{128}=0.0078125 for every y≠wy\neq w, within 10−610^{-6}.

  • 3 qubits
  • allowed gates: H, X, Z, CZ, CCZ, CNOT, CCX
  • at most 32 gates
  • no measurements
  • use Of at least 2×

One gate per line or separated by ;, e.g. H(0); CNOT(0,1); RY(1, pi/3); measure(1 -> 0). Qubit 0 is the top wire (most significant bit); controls come first. # starts a comment.

Measure into a classical bit with measure(q -> c); apply a gate only when a bit is set with X(2) if c1==1 (several bits, first = most significant: if c[0,1]==3). Placeholders: Of — write the name on its own (e.g. Of); it acts on the qubits fixed by the step.

Circuit diagram of your answerOf on q0, q1, q2; Of on q0, q1, q2q0q1q2OfOf
Statevector amplitudes
BasisAmplitude α|α|Phase arg αProbability
|000⟩1
1.0000
0
100.00%
7 basis states with zero amplitude hidden