|q⟩ Bad Qubits

beginner · Programming · Mini-Projects: Coin Flips, RNG & Bell Tests

Project: Guess the Hidden Gate

Every gate has a unique fingerprint: the way it transforms states. If you are handed a black box that applies one of several known gates, you can figure out which gate it is by carefully choosing your probe state and observing how the output changes. This idea — called gate tomography in its full form — underpins quantum verification, benchmarking, and several quantum algorithms.

Why the probe state matters

Consider the ZZ gate and the identity II. Their matrices are

Z=(1001),I=(1001).Z = \begin{pmatrix} 1 & 0 \\ 0 & -1 \end{pmatrix}, \qquad I = \begin{pmatrix} 1 & 0 \\ 0 & 1 \end{pmatrix}.

If you probe with 0|0\rangle: both give 0|0\rangle back — completely useless for telling them apart. If you probe with 1|1\rangle: Z1=1Z|1\rangle = -|1\rangle, which differs from I1=1I|1\rangle = |1\rangle only by a global phase (1-1). By the Born rule, global phases are unobservable, so a computational-basis measurement still cannot distinguish them.

The winning probe is +=12(0+1)|+\rangle = \tfrac{1}{\sqrt{2}}(|0\rangle + |1\rangle):

Z+=12(Z0+Z1)=12(01)=.Z|+\rangle = \frac{1}{\sqrt{2}}\bigl(Z|0\rangle + Z|1\rangle\bigr) = \frac{1}{\sqrt{2}}\bigl(|0\rangle - |1\rangle\bigr) = |-\rangle.

Now the two gates produce different states, |-\rangle versus +|+\rangle — but those states are still 50/50 in a ZZ-basis measurement. To turn the phase difference into an amplitude difference you can detect, apply a second Hadamard:

H=H12(01)=1,H|-\rangle = H \cdot \frac{1}{\sqrt{2}}\bigl(|0\rangle - |1\rangle\bigr) = |1\rangle, H+=0.H|+\rangle = |0\rangle.

The complete circuit Hgate?HH \to \text{gate?} \to H outputs 1|1\rangle if the gate was ZZ and 0|0\rangle if it was II. One measurement shot is enough to decide with certainty.

Comparing X and Z

The XX gate swaps 0|0\rangle and 1|1\rangle, so X+=+X|+\rangle = |+\rangle+|+\rangle is an eigenstate of XX with eigenvalue +1+1. Probing with +|+\rangle cannot distinguish XX from II. Instead, probe with 0|0\rangle: X0=1X|0\rangle = |1\rangle versus I0=0I|0\rangle = |0\rangle, which is immediately measurable. The right probe always depends on the gate set you are trying to tell apart.

| Gate | Effect on 0|0\rangle | Effect on +|+\rangle | |-------|----------------------|----------------------| | II | 0|0\rangle | +|+\rangle | | XX | 1|1\rangle | +|+\rangle | | ZZ | 0|0\rangle | |-\rangle | | HH | +|+\rangle | 0|0\rangle |

No single probe state distinguishes all four simultaneously, but pairing 0|0\rangle and +|+\rangle does — this is why real tomography uses multiple probe states.

Try it

Build the discrimination circuit for ZZ: prepare +|+\rangle, apply ZZ, rotate back with HH. The grader checks the final statevector — it should be 1|1\rangle, confirming the hidden gate is ZZ and not II.

Run your code to see the quantum state.

After running, the amplitude display should show 1.01.0 on the 1|1\rangle component. Swap the ZZ for an XX in your circuit and notice you get 0|0\rangle — a completely different answer, which is how you would rule XX out as the hidden gate.

Sign in on the full site to ask questions and join the discussion.