|q⟩ Bad Qubits

intermediate · Programming · Algorithm Projects & Benchmarking

Project: Noisy vs Ideal Comparison

Every quantum gate on real hardware comes with an error rate. Understanding how noise deforms a circuit's output — and quantifying that deformation — is the first step toward quantum error mitigation and eventually quantum error correction.

The ideal Bell state

The two-qubit Bell state Φ+|\Phi^+\rangle is the canonical entangled state:

Φ+=12(00+11).|\Phi^+\rangle = \frac{1}{\sqrt{2}}\bigl(|00\rangle + |11\rangle\bigr).

It is prepared by applying HH to qubit 0 and then a CNOT (qubit 0 controlling qubit 1):

Φ+=CNOT01(HI)00.|\Phi^+\rangle = \text{CNOT}_{0\to1}\,\bigl(H \otimes I\bigr)|00\rangle.

The ideal state has exactly two non-zero amplitudes, both equal to 1/21/\sqrt{2}, and a perfectly uniform distribution over 00|00\rangle and 11|11\rangle:

Pideal(00)=Pideal(11)=12,Pideal(01)=Pideal(10)=0.P_\text{ideal}(|00\rangle) = P_\text{ideal}(|11\rangle) = \tfrac{1}{2}, \qquad P_\text{ideal}(|01\rangle) = P_\text{ideal}(|10\rangle) = 0.

Modeling noise as a spurious rotation

Real gate errors are described by quantum channels, but a compact and instructive approximation is to insert a small unitary rotation immediately after each gate. The Rx(ε)R_x(\varepsilon) error model applies

Rx(ε)=(cos(ε/2)isin(ε/2)isin(ε/2)cos(ε/2))R_x(\varepsilon) = \begin{pmatrix} \cos(\varepsilon/2) & -i\sin(\varepsilon/2) \\ -i\sin(\varepsilon/2) & \cos(\varepsilon/2) \end{pmatrix}

to a qubit with "over-rotation" angle ε\varepsilon. For ε1\varepsilon \ll 1 this is almost the identity, but the deviation accumulates over many gates.

Effect on the Bell state

Apply Rx(ε)IR_x(\varepsilon) \otimes I to Φ+|\Phi^+\rangle (an error on qubit 0 only):

= \frac{1}{\sqrt{2}}\Bigl( \cos\tfrac{\varepsilon}{2}|00\rangle - i\sin\tfrac{\varepsilon}{2}|10\rangle + \cos\tfrac{\varepsilon}{2}|11\rangle - i\sin\tfrac{\varepsilon}{2}|01\rangle \Bigr).$$ The measurement probabilities become $$P_\text{noisy}(|00\rangle) = P_\text{noisy}(|11\rangle) = \tfrac{1}{2}\cos^2\!\tfrac{\varepsilon}{2}, \qquad P_\text{noisy}(|01\rangle) = P_\text{noisy}(|10\rangle) = \tfrac{1}{2}\sin^2\!\tfrac{\varepsilon}{2}.$$ For $\varepsilon = \pi/4$ (a $22.5°$ over-rotation): $$P_\text{noisy}(|00\rangle) = \tfrac{1}{2}\cos^2\!\tfrac{\pi}{8} \approx 0.427, \qquad P_\text{noisy}(|01\rangle) \approx 0.073.$$ The ideal symmetric distribution is clearly broken: probability has leaked from the correlated outcomes $|00\rangle$ and $|11\rangle$ into the anti-correlated ones. ## Fidelity as a figure of merit The **state fidelity** between the noisy output $|\psi_\text{noisy}\rangle$ and the ideal target $|\Phi^+\rangle$ is $$F = |\langle\Phi^+|\psi_\text{noisy}\rangle|^2.$$ Substituting the above: $$F = \left|\frac{1}{\sqrt{2}}\langle 00|\cdot\frac{1}{\sqrt{2}}\cos\tfrac{\varepsilon}{2} + \frac{1}{\sqrt{2}}\langle 11|\cdot\frac{1}{\sqrt{2}}\cos\tfrac{\varepsilon}{2}\right|^2 = \cos^2\!\tfrac{\varepsilon}{2}.$$ At $\varepsilon = 0$ (no noise) $F = 1$; at $\varepsilon = \pi$ (a full $X$ flip) $F = 0$. For the $\varepsilon = \pi/4$ example above $F = \cos^2(\pi/8) \approx 0.854$ — a 14.6 % fidelity loss from a single miscalibrated gate. <Callout type="tip"> To build a noisy circuit in the simulator, insert small rotations with `c.rx(eps, q)` after the gate you want to corrupt. Compare its statevector against the ideal output by eye: extra non-zero amplitudes on states that should be zero are the direct signature of noise. </Callout> ## Comparing noisy and ideal circuits in the simulator In the exercises that follow this project you will use `rx`, `ry`, and `rz` rotation errors to probe how algorithm performance degrades as a function of noise strength. The workflow is always the same: 1. Build the **ideal** circuit and record its statevector or distribution. 2. Build the **noisy** version by inserting small rotations at strategic points. 3. Compute the fidelity or probability deviation as a function of the error angle $\varepsilon$. Even for small circuits this analysis reveals which qubits and which gate positions are most sensitive to noise — exactly the information needed to choose where to apply error mitigation. ## Try it Build the **ideal** Bell state. The grader checks the full statevector, which should have amplitude $1/\sqrt{2}$ on $|00\rangle$ and $|11\rangle$ and zero on $|01\rangle$ and $|10\rangle$. Once you have the ideal circuit working, try modifying it by adding `c.rx(Math.PI/4, 0)` right before the return to see the noisy output in the visualizer. <RunnableExample />

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