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 is the canonical entangled state:
It is prepared by applying to qubit 0 and then a CNOT (qubit 0 controlling qubit 1):
The ideal state has exactly two non-zero amplitudes, both equal to , and a perfectly uniform distribution over and :
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 error model applies
to a qubit with "over-rotation" angle . For this is almost the identity, but the deviation accumulates over many gates.
Effect on the Bell state
Apply to (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.