|q⟩ Bad Qubits

beginner · Programming · Measurement & Probability in Code

Measuring in the X Basis

Every measurement we have seen so far has been a computational-basis (or ZZ-basis) measurement: the qubit collapses to 0|0\rangle or 1|1\rangle. But qubits can also be measured in other bases. The XX basis uses the eigenstates of the Pauli XX operator,

+=12(0+1),=12(01).|+\rangle = \tfrac{1}{\sqrt{2}}\bigl(|0\rangle + |1\rangle\bigr), \qquad |−\rangle = \tfrac{1}{\sqrt{2}}\bigl(|0\rangle - |1\rangle\bigr).

A qubit in +|+\rangle gives outcome 00 in the XX basis with certainty, and a qubit in |−\rangle gives outcome 11 with certainty — exactly the same kind of deterministic readout that 0|0\rangle and 1|1\rangle give in the ZZ basis.

Why rotating first works

Most quantum hardware only provides ZZ-basis measurement. The standard trick is to rotate into the ZZ basis before measuring: apply a Hadamard gate, then measure. Because HH swaps the two bases,

H+=0,H=1,H|+\rangle = |0\rangle, \qquad H|−\rangle = |1\rangle,

a ZZ-basis measurement on the rotated state returns the correct XX-basis outcome. Schematically:

measure in X    H  then  measure in Z.\text{measure in } X \;\equiv\; H \;\text{then}\; \text{measure in } Z.

This is the general strategy: to measure in any basis, first apply the unitary that rotates that basis onto the computational basis, then perform a standard measurement.

Example: reading out |−\rangle

Starting from 0|0\rangle, we can prepare |−\rangle in two steps:

  1. Apply XX to flip to 1|1\rangle.
  2. Apply HH to get H1=H|1\rangle = |−\rangle.

To read out the XX-basis value, we then apply another HH (the rotation step) and measure:

H1measure1 with probability 1.|−\rangle \xrightarrow{H} |1\rangle \xrightarrow{\text{measure}} 1 \text{ with probability 1.}

The double application of HH around |−\rangle is not a coincidence: HH is its own inverse (H2=IH^2 = I), so the second HH exactly undoes the first while simultaneously performing the basis-change needed for measurement.

Try it

Build the circuit that prepares |−\rangle and measures it in the XX basis. The grader checks the probability distribution: outcome 1 should appear with probability 1 and outcome 0 with probability 0.

Run your code to see the quantum state.

After running, the probability bar for 1 should be full and the bar for 0 empty — the signature of a deterministic XX-basis measurement on |−\rangle.

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