|q⟩ Bad Qubits

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

Capstone: Design Your Own Demo

Every project in this module focused on one idea at a time: a Hadamard for randomness, a CNOT for entanglement, a rotation for bias. A real quantum demo rarely uses just one idea. This capstone asks you to combine them all in a single circuit — the GHZ state, named after Greenberger, Horne, and Zeilinger, who used it to give the most striking proof that quantum correlations are incompatible with any classical hidden-variable theory.

What the GHZ state is

The three-qubit GHZ state is defined as

GHZ=12(000+111).|\mathrm{GHZ}\rangle = \frac{1}{\sqrt{2}}\bigl(|000\rangle + |111\rangle\bigr).

It is a superposition of two perfectly opposite outcomes. If all three qubits are measured in the computational basis, the result is always either 000 or 111, each with probability 12\tfrac{1}{2} — just like a quantum coin flip. But unlike the single-qubit coin flip, the three outcomes are maximally correlated: every qubit agrees with every other qubit on every single shot.

The individual qubits, viewed in isolation, look completely random — qubit 0 alone is in an equal mixture of 0|0\rangle and 1|1\rangle. The correlations live in the joint state, not in any one qubit separately.

Building it step by step

Start with all three qubits in 000|000\rangle. Apply a Hadamard to qubit 0:

HII000=12(0+1)00=12(000+100).H \otimes I \otimes I\,|000\rangle = \frac{1}{\sqrt{2}}\bigl(|0\rangle + |1\rangle\bigr) \otimes |0\rangle \otimes |0\rangle = \frac{1}{\sqrt{2}}\bigl(|000\rangle + |100\rangle\bigr).

Now apply a CNOT with control 0 and target 1. The CNOT flips qubit 1 whenever qubit 0 is 1|1\rangle:

CNOT0112(000+100)=12(000+110).\text{CNOT}_{0\to1}\,\frac{1}{\sqrt{2}}\bigl(|000\rangle + |100\rangle\bigr) = \frac{1}{\sqrt{2}}\bigl(|000\rangle + |110\rangle\bigr).

Finally, apply a second CNOT with control 0 and target 2. Qubit 0 is still 1|1\rangle in the second term, so it flips qubit 2 as well:

CNOT0212(000+110)=12(000+111).\text{CNOT}_{0\to2}\,\frac{1}{\sqrt{2}}\bigl(|000\rangle + |110\rangle\bigr) = \frac{1}{\sqrt{2}}\bigl(|000\rangle + |111\rangle\bigr).

Three gates — HH, CNOT01\text{CNOT}_{0\to1}, CNOT02\text{CNOT}_{0\to2} — and the GHZ state is ready.

Why this is the right capstone

Each gate in the GHZ circuit plays a role you have seen individually in this module:

Checking the state vector directly (no measurement needed) also illustrates something deeper: the grader verifies that your circuit implements the correct operation, not just a distribution that happens to look right. A circuit that measures during preparation, or uses the wrong gate sequence, will produce a different state vector and fail even if its output looks similar at first glance.

Try it

Prepare the GHZ state on three qubits. The grader compares the full state vector, so every amplitude must be correct — 12\tfrac{1}{\sqrt{2}} on 000|000\rangle and on 111|111\rangle, zero everywhere else.

Run your code to see the quantum state.

After running, check the State Vector panel. You should see exactly two non-zero amplitudes: 0.707\approx 0.707 on 000 and 0.707\approx 0.707 on 111. That pattern — a superposition of the two fully-correlated extremes — is the signature of the GHZ state and the culmination of everything you have built in this beginner track.

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