Skip to main content
KetQat

Appearance

Lesson 850 min

Noise, limitations and modern hardware

Decoherence, noise channels and T1/T2, how errors compound with circuit size, today's hardware platforms, and why error correction is necessary.

After this lesson you can

  • Describe noisy states with density matrices and noise processes as Kraus maps, and check that a set of Kraus operators is trace preserving
  • Apply the dephasing, depolarizing and amplitude-damping channels and describe their effect on the Bloch vector
  • Relate T1 and T2 to amplitude damping and dephasing, and compute the Bloch vector after free decay
  • Estimate how gate errors compound with circuit size using a simple independent-error model, and state the model's limitations
  • Compare the main hardware platforms qualitatively, using dated and cited sources
  • Explain why error correction is needed and show with the KetQat SDK repetition-code product how redundancy suppresses errors below p = 1/2

Read first: Quantum circuits and simulation

The gap between circuits and devices

Every calculation in this course so far assumed perfect gates, perfect measurements and qubits that wait indefinitely without changing. Real qubits are physical systems: an atom, an ion, a superconducting circuit, a photon, an electron spin. They interact with their surroundings, and every control pulse is slightly wrong. The result is noise, and it is the central obstacle between today's devices and the algorithms of the previous lesson. Preskill's term "NISQ" (noisy intermediate-scale quantum) names this situation: devices large enough to be hard to simulate in some cases, but whose noise limits the size of circuit they can run reliably (Preskill, 2018).

This lesson gives the standard mathematical description of noise, uses it to see how errors accumulate, surveys the hardware platforms qualitatively, and ends with the idea that makes large computations conceivable at all: error correction.

Density matrices and quantum channels

Noise turns a known pure state into a probabilistic mixture, so we need the density matrix previewed in the Bloch-sphere lesson. If a device prepares ∣ψj⟩\ket{\psi_j} with probability wjw_j, the state is ρ=∑jwj∣ψj⟩⟨ψj∣\rho = \sum_j w_j\ketbra{\psi_j}{\psi_j}. It is Hermitian, positive semidefinite and has trace 1. All earlier rules carry over: outcome probabilities are Pr⁡[k]=Tr⁡(Pkρ)\Pr[k] = \tr(P_k\rho), expectation values are ⟨O⟩=Tr⁡(Oρ)\expval O = \tr(O\rho), and a gate acts as ρ↦UρU†\rho\mapsto U\rho U^\dagger. For one qubit, ρ=12(I+rxX+ryY+rzZ)\rho = \tfrac12(I + r_xX + r_yY + r_zZ) with ∥r⃗∥≤1\norm{\vec r}\le1.

A general noise process is a quantum channel, written in Kraus form

E(ρ)=∑kKk ρ Kk†,∑kKk†Kk=I.\mathcal E(\rho) = \sum_k K_k\,\rho\,K_k^\dagger,\qquad \sum_k K_k^\dagger K_k = I .

One useful reading: with probability Tr⁡(KkρKk†)\tr(K_k\rho K_k^\dagger) "event kk" happens and the state becomes KkρKk†K_k\rho K_k^\dagger normalised. The completeness condition makes the probabilities add up to one, i.e. it preserves the trace. It is a theorem that every physically allowed transformation of a quantum system (completely positive and trace preserving) can be written this way (Nielsen and Chuang, Chapter 8, which this section follows in substance).

Three standard single-qubit channels

Dephasing (phase flip). With probability pp a ZZ error occurs: K0=1−p IK_0 = \sqrt{1-p}\,I, K1=p ZK_1 = \sqrt p\,Z. Since ZZ commutes with ZZ and anticommutes with XX and YY, the Bloch vector changes as

(rx,ry,rz)↦((1−2p)rx, (1−2p)ry, rz).(r_x, r_y, r_z)\mapsto\big((1-2p)r_x,\ (1-2p)r_y,\ r_z\big).

Populations of ∣0⟩\ket0 and ∣1⟩\ket1 are untouched; the relative phase, which carries the interference of the first lesson, is erased. At p=1/2p = 1/2 every state collapses onto the zz axis.

Depolarizing. With probability pp one of X,Y,ZX, Y, Z occurs, each with probability p/3p/3: K0=1−p IK_0 = \sqrt{1-p}\,I and KP=p/3 PK_P = \sqrt{p/3}\,P. Each Pauli flips two of the three Bloch components, and averaging gives a uniform shrink:

r⃗↦(1−4p3)r⃗,equivalentlyρ↦(1−4p3)ρ+4p3 I2.\vec r\mapsto\Big(1 - \frac{4p}{3}\Big)\vec r, \qquad\text{equivalently}\qquad \rho\mapsto\Big(1-\frac{4p}{3}\Big)\rho + \frac{4p}{3}\,\frac I2 .

The second form shows why the channel is called depolarizing: it replaces the state by the maximally mixed state I/2I/2 with probability 4p/34p/3. (Papers differ on whether "pp" means the Pauli-error probability, as here, or the replacement probability; always check.)

Amplitude damping. Energy relaxation from ∣1⟩\ket1 to ∣0⟩\ket0 with probability γ\gamma:

K0=(1001−γ),K1=(0γ00).K_0 = \begin{pmatrix}1&0\\0&\sqrt{1-\gamma}\end{pmatrix},\qquad K_1 = \begin{pmatrix}0&\sqrt\gamma\\0&0\end{pmatrix}.

The population of ∣1⟩\ket1 is multiplied by 1−γ1-\gamma, the off-diagonal entries of ρ\rho by 1−γ\sqrt{1-\gamma}, and repeated application drives every state to ∣0⟩\ket0. Unlike the other two channels it is not unital: it does not fix the centre of the sphere.

Worked example

Start in ∣+⟩\ket+, Bloch vector (1,0,0)(1, 0, 0).

  1. Depolarizing with p=0.1p = 0.1: r⃗=(1−0.4/3)(1,0,0)≈(0.8667,0,0)\vec r = (1 - 0.4/3)(1,0,0) \approx (0.8667, 0, 0).
  2. Amplitude damping with γ=0.3\gamma = 0.3: initially ρ11=1/2\rho_{11} = 1/2, so afterwards ρ11=0.35\rho_{11} = 0.35 and rz=1−2ρ11=0.3r_z = 1 - 2\rho_{11} = 0.3; the coherence ρ01=1/2\rho_{01} = 1/2 becomes 120.7\tfrac12\sqrt{0.7}, so rx=0.7≈0.8367r_x = \sqrt{0.7}\approx0.8367.
import numpy as np

X = np.array([[0, 1], [1, 0]]); Y = np.array([[0, -1j], [1j, 0]]); Z = np.diag([1, -1])

def apply_channel(rho, kraus):
    return sum(K @ rho @ K.conj().T for K in kraus)

def bloch(rho):
    return np.round([np.trace(rho @ P).real for P in (X, Y, Z)], 4)

plus = np.array([[1, 1], [1, 1]]) / 2                      # |+><+|, Bloch vector (1, 0, 0)
p = 0.1
depolarizing = [np.sqrt(1 - p) * np.eye(2)] + [np.sqrt(p / 3) * P for P in (X, Y, Z)]
print(bloch(apply_channel(plus, depolarizing)))            # [0.8667 0. 0.] = 1 - 4p/3

gamma = 0.3
damping = [np.array([[1, 0], [0, np.sqrt(1 - gamma)]]), np.array([[0, np.sqrt(gamma)], [0, 0]])]
print(bloch(apply_channel(plus, damping)))                 # [0.8367 0. 0.3]

T1 and T2

Device specifications summarise idle noise by two times.

  • T1T_1, energy relaxation. Prepare ∣1⟩\ket1 and wait: the excited population decays as e−t/T1e^{-t/T_1}. This is amplitude damping with γ(t)=1−e−t/T1\gamma(t) = 1 - e^{-t/T_1}.
  • T2T_2, coherence time. Prepare ∣+⟩\ket+ and wait: the length of the Bloch vector's xx–yy part decays as e−t/T2e^{-t/T_2} (in the simplest, exponential model).

In the Bloch picture, free decay (ignoring any deliberate rotation about zz) is

rx(t)=rx(0) e−t/T2,ry(t)=ry(0) e−t/T2,rz(t)=1−(1−rz(0))e−t/T1.r_x(t) = r_x(0)\,e^{-t/T_2},\quad r_y(t) = r_y(0)\,e^{-t/T_2},\quad r_z(t) = 1 - \big(1 - r_z(0)\big)e^{-t/T_1}.

Amplitude damping alone already shrinks coherences by 1−γ=e−t/(2T1)\sqrt{1-\gamma} = e^{-t/(2T_1)}, so relaxation contributes to T2T_2. Any additional pure dephasing, with its own time TφT_\varphi, adds rates: 1/T2=1/(2T1)+1/Tφ1/T_2 = 1/(2T_1) + 1/T_\varphi. Hence, in this model, T2≤2T1T_2\le 2T_1. The exercise checks the closed form above against an explicit composition of amplitude damping and dephasing Kraus maps.

Two caveats keep these numbers honest. Real decay is not always exponential: slowly fluctuating noise makes the coherence decay measured in a simple Ramsey experiment (often called T2∗T_2^*) shorter than the value obtained with a refocusing echo. And T1T_1, T2T_2 vary between qubits on the same chip and drift over time, so a single quoted number is a summary, not a constant of nature.

Gate errors, readout errors and how they compound

Gates are noisy too. A gate's error rate is commonly summarised by its average infidelity: the average over input states ∣ψ⟩\ket\psi of 1−⟨ψ∣U†E(∣ψ⟩⟨ψ∣)U∣ψ⟩1 - \bra\psi U^\dagger\mathcal E(\ketbra\psi\psi)U\ket\psi, where E\mathcal E is the operation the device actually performs and UU the ideal gate. Measurements have readout errors: the probability of reporting 1 when the qubit was ∣0⟩\ket0, and vice versa, collected in a 2×22\times2 confusion matrix. Two-qubit gates are typically the noisiest operations on current devices.

A simple model of compounding (a heuristic, not a theorem). Suppose each of GG operations fails independently with probability ε\varepsilon, and any failure ruins the output. Then

Pr⁡[no failure]=(1−ε)G≈e−εG.\Pr[\text{no failure}] = (1-\varepsilon)^G \approx e^{-\varepsilon G}.

With ε=10−3\varepsilon = 10^{-3} and G=1000G = 1000 operations, (0.999)1000≈0.368(0.999)^{1000}\approx 0.368: barely one run in three is error-free. With G=106G = 10^6 the probability is about e−1000e^{-1000}, i.e. zero for practical purposes. The useful circuit size is of order 1/ε1/\varepsilon operations. The model is crude: some errors do not affect the output, errors can be correlated, and coherent errors (a gate that systematically over-rotates by a small angle) can add up in amplitude, so their effect can grow quadratically with the number of repetitions instead of linearly. But the conclusion survives every refinement: without a way to suppress errors, circuit size is capped by the inverse error rate, while interesting algorithms need far larger circuits.

Hardware platforms

Several physical systems are being developed as qubits. The descriptions below are qualitative and attributed to review articles with their dates; device figures change quickly, so consult current primary sources for numbers.

  • Superconducting circuits (Krantz et al., 2019). Qubits are nonlinear resonators built from Josephson junctions on a chip, cooled to millikelvin temperatures in dilution refrigerators and controlled by microwave pulses. Gates are fast and the chips are made with lithographic fabrication; qubits typically couple only to neighbours on the chip, and fabrication variation makes every qubit slightly different.
  • Trapped ions (Bruzewicz et al., 2019). Qubits are internal levels of ions held in vacuum by electromagnetic fields and driven by lasers or microwaves. All ions of a species are identical, coherence is long compared with gate times, and the shared motion of the ions mediates gates between any pair in a chain; gates are slower than in superconducting circuits, and scaling to many ions requires moving ions or linking traps.
  • Neutral atoms (Saffman, Walker and Mølmer, 2010). Atoms held in arrays of optical tweezers interact strongly when excited to Rydberg states, which provides entangling gates. Tweezer arrays can be large and rearranged during a computation: for example, Bluvstein et al. reported in December 2023 a processor operating on encoded logical qubits with up to 280 physical qubits (Bluvstein et al., 2024).
  • Photons (Kok et al., 2007). Qubits encoded in photons barely interact with their environment and travel easily, but they also barely interact with each other, so entangling operations rely on measurement and are probabilistic; photon loss is the dominant error.
  • Semiconductor spins (Burkard et al., 2023). Electron or nuclear spins in quantum dots or donors in silicon or germanium, attractive for their small size and compatibility with semiconductor manufacturing; control of charge noise and uniformity across many devices are active research questions.

No platform is uniformly best. Each trades gate speed, coherence, connectivity, uniformity and manufacturability differently, and all of them have error rates far above what the algorithms of this course need at scale.

Why error correction is needed

The compounding estimate says that a noisy device can run only about 1/ε1/\varepsilon operations. Reducing ε\varepsilon by engineering helps, but no plausible engineering improvement reaches the error rates needed for circuits with billions of operations. The way out is error correction: encode one logical qubit redundantly in many physical qubits, detect errors by measurements that do not reveal the encoded information, and correct them.

At first sight this seems impossible. Unknown quantum states cannot be copied (no-cloning), measurement disturbs them, and errors are continuous (any small rotation, not just bit flips). All three obstacles are overcome by encoding into entangled states and measuring only parity-type quantities called syndromes; the course Quantum Error Correction and Fault-Tolerant Quantum Computing develops this from the start. Here we look only at the simplest classical intuition.

Majority vote. Store a bit as nn copies (odd nn), let each flip independently with probability pp, and decode by majority. Decoding fails when more than half flip:

pL(n,p)=∑k>n/2(nk)pk(1−p)n−k,pL(3,p)=3p2−2p3.p_L(n, p) = \sum_{k > n/2}\binom nk p^k(1-p)^{n-k},\qquad p_L(3, p) = 3p^2 - 2p^3 .

For p<1/2p < 1/2, pLp_L decreases as nn grows; for p>1/2p > 1/2 redundancy makes things worse. At p=0.1p = 0.1: pL=0.1p_L = 0.1 for n=1n = 1, 0.0280.028 for n=3n=3, 0.008560.00856 for n=5n = 5 and 0.0027280.002728 for n=7n=7 (exact values from the formula). The quantum bit-flip repetition code achieves the same numbers against independent XX errors without ever reading the encoded qubit, by measuring the parities ZiZi+1Z_iZ_{i+1} of neighbouring qubits. It does nothing against ZZ errors, which is why real codes are more elaborate. The KetQat SDK's repetition-code product samples exactly this model (independent bit flips with probability pp on each data qubit, one round, perfect syndrome measurement, majority-vote decoding) and reports its Monte Carlo estimate beside the exact value:

from ketqat_runner import catalog

for n in (1, 3, 5, 7):
    result = catalog.run("[email protected]", seed=7, n=n, physical_error_rate=0.1, shots=100000).result
    ci = result["confidence_interval"]
    print(n, result["logical_error_rate"], round(result["exact_logical_error_rate"], 6),
          (round(ci["lower"], 5), round(ci["upper"], 5)))

This printed (SDK commit 2cedabb, NumPy 2.5; rates are logical failures per shot, i.e. per single round, with 95% Wilson intervals):

nn Monte Carlo p^L\hat p_L exact pLp_L 95% interval
1 0.09834 0.1 [0.09651, 0.1002]
3 0.02822 0.028 [0.02721, 0.02926]
5 0.00829 0.00856 [0.00775, 0.00887]
7 0.00244 0.002728 [0.00215, 0.00277]

Every interval contains the exact value, and each step in nn cuts the logical error rate by a factor of about three. The threshold theorem extends this idea to full quantum computation: if the physical error rate per operation is below a threshold value (which depends on the code and the noise model), logical error rates can be made arbitrarily small at a cost that grows only polylogarithmically in the size of the computation, under assumptions about the noise such as weak correlations (Nielsen and Chuang, Section 10.6).

Experiments have begun to see the key signature, logical errors that fall as the code grows. As one example, Google Quantum AI reported (online December 2024, in print 2025) surface-code memory experiments on a superconducting processor in which the logical error per error-correction cycle decreased by a factor of 2.14±0.022.14 \pm 0.02 each time the code distance increased by two, up to a distance-7 code on 101 qubits, with decoding as described in the paper (values quoted from Google Quantum AI, 2025). Turning such memories into large fault-tolerant computers remains an open engineering problem.

Common mistakes

  • Treating T2T_2 as independent of T1T_1. Relaxation also destroys coherence; in the exponential model T2≤2T1T_2\le 2T_1.
  • Mixing depolarizing conventions. "Depolarizing probability pp" may mean Pauli errors with total probability pp (Bloch shrink 1−4p/31-4p/3) or replacement by I/2I/2 with probability pp (shrink 1−p1-p).
  • Reading (1−ε)G(1-\varepsilon)^G as exact. It is a back-of-the-envelope model; coherent and correlated errors behave differently.
  • Quoting hardware numbers without date and source. Device figures change quickly and vary across qubits.
  • Expecting redundancy to always help. Majority vote helps only when p<1/2p < 1/2, and a bit-flip code protects only against bit flips.

Summary

  • Noisy states are density matrices; noise processes are Kraus maps with ∑kKk†Kk=I\sum_kK_k^\dagger K_k = I.
  • Dephasing shrinks x,yx, y by 1−2p1-2p; depolarizing shrinks r⃗\vec r by 1−4p/31-4p/3; amplitude damping relaxes towards ∣0⟩\ket0.
  • T1T_1 is energy relaxation, T2T_2 coherence decay; in the exponential model T2≤2T1T_2\le2T_1.
  • With independent error probability ε\varepsilon per operation, circuits of more than about 1/ε1/\varepsilon operations rarely succeed.
  • Hardware platforms trade speed, coherence, connectivity and scalability; none is yet good enough for large algorithms without error correction.
  • Redundancy suppresses errors when they are rare enough, which is the starting point of quantum error correction.

The exercise implements the channels and T1T_1/T2T_2 decay with NumPy and checks your exact repetition-code formula against the KetQat SDK. This completes the course. The natural continuations are the Algorithms course and the course on quantum error correction and fault tolerance.

Exercises

Run these on your own computer. Each comes with automated checks: python -m pytest test_exercise.py. Nothing you write is sent to KetQat.

Noise channels, T1/T2 decay and redundancy with the KetQat SDK

intermediate · about 50 min · needs numpy, ketqat[qinfo]

You will implement the three standard single-qubit noise channels as Kraus maps, derive the Bloch-vector picture of T1T_1/T2T_2 decay, estimate how errors compound with circuit size, and compute the exact logical error rate of the bit-flip repetition code, which the test compares with the KetQat SDK's repetition-code product.

Conventions (as in the lesson):

  • dephasing (phase flip): K0=1−p IK_0 = \sqrt{1-p}\,I, K1=p ZK_1 = \sqrt p\,Z;
  • depolarizing: K0=1−p IK_0 = \sqrt{1-p}\,I, K1,2,3=p/3 X,p/3 Y,p/3 ZK_{1,2,3} = \sqrt{p/3}\,X, \sqrt{p/3}\,Y, \sqrt{p/3}\,Z;
  • amplitude damping: K0=(1001−γ)K_0 = \begin{pmatrix}1&0\\0&\sqrt{1-\gamma}\end{pmatrix}, K1=(0γ00)K_1 = \begin{pmatrix}0&\sqrt\gamma\\0&0\end{pmatrix}.

Functions to implement (in starter.py)

Function Contract
dephasing_kraus(p) List of the two Kraus matrices above.
depolarizing_kraus(p) List of the four Kraus matrices above.
amplitude_damping_kraus(gamma) List of the two Kraus matrices above.
apply_channel(rho, kraus) ∑kKkρKk†\sum_k K_k\rho K_k^\dagger.
bloch_after_t1_t2(r, t, T1, T2) The Bloch vector after free decay for time t from Bloch vector r (closed form from the lesson): x,yx, y multiplied by e−t/T2e^{-t/T_2}, and z↦1−(1−z)e−t/T1z \mapsto 1 - (1 - z)e^{-t/T_1}. Raise ValueError if T2>2T1T_2 > 2T_1.
circuit_success_estimate(error_per_gate, gates) The heuristic estimate (1−ε)G(1-\varepsilon)^G that no gate fails.
repetition_logical_error(n, p) Exact probability that majority vote over nn (odd) independent bit flips of probability pp fails: ∑k>n/2(nk)pk(1−p)n−k\sum_{k>n/2}\binom nk p^k(1-p)^{n-k}.

What the checks verify

  • Each channel satisfies ∑kKk†Kk=I\sum_k K_k^\dagger K_k = I and maps random density matrices to density matrices (unit trace, Hermitian, positive semidefinite).
  • Depolarizing shrinks every Bloch vector by 1−4p/31 - 4p/3; dephasing scales x,yx, y by 1−2p1-2p and leaves zz; amplitude damping drives every state towards ∣0⟩\ket0 (analytic values from the lesson).
  • bloch_after_t1_t2 agrees with an independent route: amplitude damping with γ=1−e−t/T1\gamma = 1 - e^{-t/T_1} followed by the dephasing that brings the total coherence decay to e−t/T2e^{-t/T_2}, both applied with your Kraus maps to density matrices.
  • circuit_success_estimate matches (1−ε)G(1-\varepsilon)^G and is close to e−εGe^{-\varepsilon G} for small ε\varepsilon.
  • repetition_logical_error equals the exact_logical_error_rate reported by catalog.run("[email protected]", ...), lies inside the SDK's 95% Wilson interval around its seeded Monte Carlo estimate, decreases with nn for p<1/2p < 1/2 and increases for p>1/2p > 1/2.

Run the checks

python -m pip install numpy "ketqat[qinfo] @ git+https://github.com/ketqat/ketqat-sdk@2cedabbd814fd199b1989c8ceb1e9efa1744c2c0#subdirectory=python"
python -m pytest test_exercise.py

The test points KETQAT_HOME at a temporary directory, so SDK run records are not left in your home directory.

Terminal
python -m pip install numpy "ketqat[qinfo]"

starter.py

Python
"""Noise channels, T1/T2 decay and redundancy (KetQat Commons, Foundations)."""
import numpy as np

I2 = np.eye(2, dtype=complex)
X = np.array([[0, 1], [1, 0]], dtype=complex)
Y = np.array([[0, -1j], [1j, 0]], dtype=complex)
Z = np.array([[1, 0], [0, -1]], dtype=complex)


def dephasing_kraus(p):
    """Return [sqrt(1-p) I, sqrt(p) Z]."""
    raise NotImplementedError


def depolarizing_kraus(p):
    """Return [sqrt(1-p) I, sqrt(p/3) X, sqrt(p/3) Y, sqrt(p/3) Z]."""
    raise NotImplementedError


def amplitude_damping_kraus(gamma):
    """Return [[[1, 0], [0, sqrt(1-gamma)]], [[0, sqrt(gamma)], [0, 0]]]."""
    raise NotImplementedError


def apply_channel(rho, kraus):
    """Return sum_k K rho K^dagger."""
    raise NotImplementedError


def bloch_after_t1_t2(r, t, T1, T2):
    """Return the Bloch vector after free decay for time t; ValueError if T2 > 2 T1."""
    raise NotImplementedError


def circuit_success_estimate(error_per_gate, gates):
    """Return (1 - error_per_gate) ** gates."""
    raise NotImplementedError


def repetition_logical_error(n, p):
    """Return the exact majority-vote failure probability for n independent flips of probability p."""
    raise NotImplementedError

test_exercise.py

Python
"""Checks for the noisy-channels exercise. Run: python -m pytest test_exercise.py"""
import importlib.util
import os
from pathlib import Path

def _load_target():
    name = os.environ.get("KETQAT_COMMONS_TARGET", "starter")
    path = Path(__file__).with_name(f"{name}.py")
    spec = importlib.util.spec_from_file_location(f"{Path(__file__).parent.name}_{name}", path)
    module = importlib.util.module_from_spec(spec)
    spec.loader.exec_module(module)
    return module

target = _load_target()

import numpy as np
import pytest

RNG = np.random.default_rng(1950)
PAULI = [np.array([[0, 1], [1, 0]]), np.array([[0, -1j], [1j, 0]]), np.diag([1, -1])]


@pytest.fixture(autouse=True)
def _isolated_ketqat_home(tmp_path, monkeypatch):
    monkeypatch.setenv("KETQAT_HOME", str(tmp_path / "ketqat-home"))


def _rho_from_bloch(r):
    return 0.5 * (np.eye(2) + sum(c * P for c, P in zip(r, PAULI)))


def _bloch_from_rho(rho):
    return np.array([np.trace(rho @ P).real for P in PAULI])


def _random_bloch(inside=True):
    v = RNG.normal(size=3)
    v /= np.linalg.norm(v)
    return v * (RNG.uniform() if inside else 1.0)


CHANNELS = [
    ("dephasing", lambda: target.dephasing_kraus(RNG.uniform())),
    ("depolarizing", lambda: target.depolarizing_kraus(RNG.uniform(0, 0.75))),
    ("amplitude damping", lambda: target.amplitude_damping_kraus(RNG.uniform())),
]


@pytest.mark.parametrize("name, make", CHANNELS)
def test_channels_are_trace_preserving_and_positive(name, make):
    for _ in range(20):
        kraus = make()
        assert np.allclose(sum(K.conj().T @ K for K in kraus), np.eye(2)), name
        rho = _rho_from_bloch(_random_bloch())
        out = target.apply_channel(rho, kraus)
        assert np.isclose(np.trace(out), 1) and np.allclose(out, out.conj().T)
        assert np.min(np.linalg.eigvalsh(out)) > -1e-12


def test_depolarizing_shrinks_uniformly():
    for _ in range(20):
        p, r = RNG.uniform(0, 0.75), _random_bloch(inside=False)
        out = _bloch_from_rho(target.apply_channel(_rho_from_bloch(r), target.depolarizing_kraus(p)))
        assert np.allclose(out, (1 - 4 * p / 3) * r)


def test_dephasing_kills_coherence_only():
    for _ in range(20):
        p, r = RNG.uniform(), _random_bloch(inside=False)
        out = _bloch_from_rho(target.apply_channel(_rho_from_bloch(r), target.dephasing_kraus(p)))
        assert np.allclose(out, [(1 - 2 * p) * r[0], (1 - 2 * p) * r[1], r[2]])


def test_amplitude_damping_relaxes_towards_zero():
    one = _rho_from_bloch([0, 0, -1])
    out = target.apply_channel(one, target.amplitude_damping_kraus(0.3))
    assert np.isclose(out[1, 1].real, 0.7)  # excited population decays by (1 - gamma)
    rho = _rho_from_bloch(_random_bloch())
    for _ in range(400):
        rho = target.apply_channel(rho, target.amplitude_damping_kraus(0.1))
    assert np.allclose(rho, np.diag([1, 0]), atol=1e-8)


def test_t1_t2_closed_form_matches_kraus_composition():
    for _ in range(30):
        T1 = RNG.uniform(10, 100)
        T2 = RNG.uniform(1, 2 * T1)
        t = RNG.uniform(0, 3 * T1)
        r = _random_bloch()
        gamma = 1 - np.exp(-t / T1)
        # amplitude damping leaves coherence factor sqrt(1 - gamma) = exp(-t / (2 T1));
        # extra dephasing (1 - 2 p) supplies the rest of exp(-t / T2).
        p = (1 - np.exp(-t / T2 + t / (2 * T1))) / 2
        rho = target.apply_channel(_rho_from_bloch(r), target.amplitude_damping_kraus(gamma))
        rho = target.apply_channel(rho, target.dephasing_kraus(p))
        assert np.allclose(target.bloch_after_t1_t2(r, t, T1, T2), _bloch_from_rho(rho))
    with pytest.raises(ValueError):
        target.bloch_after_t1_t2([1, 0, 0], 1.0, 10.0, 25.0)


def test_circuit_success_estimate():
    assert np.isclose(target.circuit_success_estimate(1e-3, 1000), 0.999 ** 1000)
    assert abs(target.circuit_success_estimate(1e-4, 5000) - np.exp(-0.5)) < 1e-4
    assert target.circuit_success_estimate(0.0, 10 ** 6) == 1.0


@pytest.mark.parametrize("n, p", [(1, 0.1), (3, 0.1), (5, 0.1), (7, 0.2), (3, 0.6)])
def test_repetition_code_matches_ketqat_sdk(n, p):
    from ketqat_runner import catalog

    record = catalog.run("[email protected]", seed=7, n=n, physical_error_rate=p, shots=20000)
    assert record.status == "succeeded"
    result = record.result
    mine = target.repetition_logical_error(n, p)
    assert abs(mine - result["exact_logical_error_rate"]) < 1e-12
    interval = result["confidence_interval"]
    assert interval["lower"] <= mine <= interval["upper"]


def test_redundancy_helps_only_below_one_half():
    low = [target.repetition_logical_error(n, 0.1) for n in (1, 3, 5, 7, 9)]
    high = [target.repetition_logical_error(n, 0.6) for n in (1, 3, 5, 7, 9)]
    assert all(a > b for a, b in zip(low, low[1:]))
    assert all(a < b for a, b in zip(high, high[1:]))
    assert np.isclose(target.repetition_logical_error(3, 0.1), 3 * 0.1 ** 2 - 2 * 0.1 ** 3)

Check your understanding

8 questions. Pass with 70% of the points. Answers are checked on the server; retakes are allowed. Explanations appear once you pass or after three complete attempts.

  1. The state ∣0⟩\ket0 passes through the depolarizing channel with Pauli-error probability p=0.15p = 0.15 (each of X,Y,ZX, Y, Z with probability p/3p/3). What is rzr_z afterwards?

    1 pt
  2. Which channel does not leave the maximally mixed state I/2I/2 unchanged?

    1 pt
  3. A qubit with T1=100 μsT_1 = 100\,\mu s and T2=80 μsT_2 = 80\,\mu s is prepared in ∣+⟩\ket+ and left idle for t=40 μst = 40\,\mu s. Using the exponential model of the lesson, what is rxr_x?

    1 pt
  4. A data sheet lists T1=50 μsT_1 = 50\,\mu s and T2=150 μsT_2 = 150\,\mu s for a qubit. In the model of the lesson, what should you conclude?

    1 pt
  5. Run circuit_success_estimate(1e-3, 500) from the exercise. Enter the estimated probability that none of 500 operations fails.

    1 pt

    Computed by running exercise “noisy-channels” on your computer.

  6. Run repetition_logical_error(5, 0.1) from the exercise. Enter the exact logical error probability.

    1 pt

    Computed by running exercise “noisy-channels” on your computer.

  7. Run catalog.run("[email protected]", seed=7, n=3, physical_error_rate=0.1, shots=10000) with the KetQat SDK (as in the exercise) and enter result["logical_error_rate"].

    1 pt

    Computed by running exercise “noisy-channels” on your computer.

  8. Select every true statement.

    1 pt

    Select all that apply.

Sign in with GitHub to check answers and save progress. Reading stays free without an account.

References

  1. Michael A. Nielsen, Isaac L. Chuang (2010). Quantum Computation and Quantum Information (10th Anniversary Edition). Cambridge University Press. doi:10.1017/CBO9780511976667
  2. John Preskill (2018). Quantum computing in the NISQ era and beyond. Quantum 2, 79. doi:10.22331/q-2018-08-06-79
  3. Philip Krantz et al. (2019). A quantum engineer's guide to superconducting qubits. Applied Physics Reviews 6, 021318. doi:10.1063/1.5089550
  4. Colin D. Bruzewicz et al. (2019). Trapped-ion quantum computing: Progress and challenges. Applied Physics Reviews 6, 021314. doi:10.1063/1.5088164
  5. Mark Saffman, Thad G. Walker, Klaus Mølmer (2010). Quantum information with Rydberg atoms. Reviews of Modern Physics 82, 2313-2363. doi:10.1103/RevModPhys.82.2313
  6. Dolev Bluvstein et al. (2024). Logical quantum processor based on reconfigurable atom arrays. Nature 626, 58-65 (published online 6 December 2023). doi:10.1038/s41586-023-06927-3
  7. Pieter Kok et al. (2007). Linear optical quantum computing with photonic qubits. Reviews of Modern Physics 79, 135-174. doi:10.1103/RevModPhys.79.135
  8. Guido Burkard et al. (2023). Semiconductor spin qubits. Reviews of Modern Physics 95, 025003. doi:10.1103/RevModPhys.95.025003
  9. Google Quantum AI and Collaborators (2025). Quantum error correction below the surface code threshold. Nature 638, 920-926. doi:10.1038/s41586-024-08449-y