Analysis & Plotting paulicert.analysis paulicert.plotting
Evaluate exact decoded logical channels under true vs. Pauli-twirled noise, run logical error-rate sweeps across four simulation engines, and plot results. For definitions, see Foundations.
logical_channel
def logical_channel(code: StabilizerCode, channel: QuantumChannel | Sequence[QuantumChannel], *, decoder: str | StabilizerLUTDecoder = "min_weight") → LogicalChannel
Computes the exact decoded logical channel (as a Qiskit SuperOp) for one round of ideal syndrome extraction and lookup-table recovery, under both the true noise and its Pauli twirl. Supports codes with n ≤ 10.
| Parameter | Type | Default | Description |
|---|---|---|---|
code | StabilizerCode | — | Stabilizer code with n ≤ 10 and k ≥ 1. |
channel | QuantumChannel | Sequence[QuantumChannel] | — | Single-qubit channel applied to every qubit, or a length-n sequence of per-qubit channels. |
decoder | str | StabilizerLUTDecoder | "min_weight" | Decoding rule ("min_weight", "mpe", "ml") or prebuilt decoder used for both true and twirled channels. |
import paulicert as pc
shor = pc.get_preset_code("9-1-3-shor")
lc = pc.logical_channel(shor, pc.CHANNEL_FAMILIES["coherent_z"](0.01))
print(f"true={lc.infidelity:.4e} | PTA={lc.twirled_infidelity:.4e} | gap={lc.gap:.4f} | D_Choi={lc.choi_distance:.2e}")
# true=2.1685e-02 | PTA=2.5429e-03 | gap=8.5273 | D_Choi=4.91e-02
LogicalChannel
class LogicalChannel
Frozen dataclass returned by logical_channel.
| Attribute / Property | Type | Description |
|---|---|---|
superop | qiskit.quantum_info.SuperOp | Decoded logical superoperator under the true physical channel. |
twirled_superop | qiskit.quantum_info.SuperOp | Decoded logical superoperator under the Pauli-twirled channel. |
infidelity | float | Block logical error rate (entanglement infidelity) under the true channel. |
twirled_infidelity | float | Block logical error rate under the Pauli-twirled channel. |
gap | float | Ratio infidelity / twirled_infidelity (1.0 when the Pauli model matches logical fidelity). |
choi_distance | float | Normalized Choi trace distance in [0, 1] between superop and twirled_superop (zero if and only if the full logical channels are identical). |
Error-Rate Sweeps & Warnings
def block_logical_error_rate(code: StabilizerCode, channel: str | ChannelFamily, error_rates: Sequence[float] | NDArray[np.float64], *, decoder: str | StabilizerLUTDecoder = "min_weight", method: str = "auto", shots: int | None = None, seed: int = 42, sampler: BaseSamplerV2 | None = None) → NDArray[np.float64]
Sweeps the block logical error rate across a 1D array of channel parameters (p in [0, 1] for named families, or any finite parameter for custom callables). channel accepts a named family in CHANNEL_FAMILIES, a uniform callable param → QuantumChannel, or a per-qubit callable param → Sequence[QuantumChannel] (for example, selective Pauli twirling).
def logical_error_rate_per_qubit(code: StabilizerCode, channel: str | ChannelFamily, error_rates: Sequence[float] | NDArray[np.float64], *, decoder: str | StabilizerLUTDecoder = "min_weight", method: str = "auto", shots: int | None = None, seed: int = 42, sampler: BaseSamplerV2 | None = None) → NDArray[np.float64]
Same interface as block_logical_error_rate, returning the average fraction of logical qubits suffering an error (identical to block error rate when k == 1).
method | What it simulates | Limits & defaults |
|---|---|---|
"pauli_enumeration" | Exact sum over all Pauli errors of the twirled channel. | n ≤ 10 (zero sampling noise). |
"pauli_sampling" | Monte Carlo sampling of the twirled channel. | r ≤ 16; default 10,000 shots. |
"exact_channel" | Exact decoded logical superoperator of the full physical channel. | n ≤ 10 (zero sampling noise). |
"aer_circuit" | Zero-ancilla (n + k)-qubit Bell memory circuit via Qiskit V2 BaseSamplerV2 + classical Pauli-frame recovery (UnitaryGate for unitary channels on any BaseSamplerV2; qiskit_aer.primitives.SamplerV2 default for non-unitary Kraus noise; custom sampler sweeps submit one batched run() call). | n + k ≤ 24; default 4,096 shots. |
"auto" | Picks "pauli_enumeration" when shots is None and n ≤ 10, else "pauli_sampling". | — |
import warnings
import paulicert as pc
steane = pc.get_preset_code("7-1-3-steane")
with warnings.catch_warnings():
warnings.simplefilter("ignore", pc.PauliTwirlApproximationWarning)
pta = pc.block_logical_error_rate(steane, "coherent_x", [0.01, 0.02], method="pauli_enumeration")
exact = pc.block_logical_error_rate(steane, "coherent_x", [0.01, 0.02], method="exact_channel")
full = pc.block_logical_error_rate(steane, "coherent_x", [0.01, 0.02], method="aer_circuit", shots=4096, seed=42)
print("Pauli-model error rates :", pta.round(5)) # [0.002 0.00765]
print("Exact full-channel rates:", exact.round(5)) # [0.00588 0.02192]
print("SamplerV2 circuit rates :", full.round(5)) # [0.00586 0.02148]
class PauliTwirlApproximationWarning(UserWarning)
Emitted automatically when a Pauli-only engine runs on a code and channel where pauli_exact returns exact=False.
Reference Estimates & Plotting
def bounded_distance_estimate(error_rates: ArrayLike, n: int, t: int) → NDArray[np.float64]
Computes the probability of more than t single-qubit errors on n qubits — a reference upper bound for decoders correcting all errors of weight ≤ t.
def pseudo_threshold(error_rates: ArrayLike, logical_rates: ArrayLike) → float | None
Finds the break-even error rate where logical_rate(p) == p via log-log interpolation (falling back to linear interpolation when a low-p Monte Carlo point has 0.0 observed errors), or returns None if the curves do not cross.
def plot_logical_error_rates(error_rates: ArrayLike, curves: Mapping[str, ArrayLike], *, show_physical: bool = True, ylabel: str = "Logical error rate", ax: Axes | None = None) → Axes
Log-log plot comparing logical error-rate curves against the physical break-even line.
def plot_pauli_twirl(channel: str | ChannelFamily, error_rates: Sequence[float] | ArrayLike, *, ax: Axes | None = None) → Axes
Plots the Pauli-twirl error probabilities (p_X, p_Y, p_Z) of a channel family across error_rates.
def plot_stabilizer_tableau(code: StabilizerCode, *, ax: Axes | None = None) → Axes
Draws a color-coded grid of the stabilizer generators (I, X, Y, Z).