Certification paulicert.certify
Check whether Pauli-channel simulation is guaranteed exact for a code and noise channel, and compute the smallest set of qubits to twirl. For the underlying theorems, see Foundations.
pauli_exact
def pauli_exact(code: StabilizerCode, channel: QuantumChannel | Sequence[QuantumChannel], *, max_witnesses: int = 100, tol: float = 1e-10, full_channel: bool = False) → PauliExactness
Checks whether the Pauli twirl approximation is certified exact for code under single-qubit CPTP channel. Runs in polynomial time over GF(2) and scales to codes with hundreds of qubits.
| Parameter | Type | Default | Description |
|---|---|---|---|
code | StabilizerCode | — | Stabilizer code of any blocklength n. |
channel | QuantumChannel | Sequence[QuantumChannel] | — | One single-qubit channel applied to all qubits, or a list of n per-qubit channels. |
max_witnesses | int | 100 | Maximum number of witness rows returned in PauliExactness.witnesses. |
tol | float | 1e-10 | Relative threshold below which off-diagonal process-matrix entries are treated as zero. |
full_channel | bool | False | If False, certifies exact logical fidelity and diagonal process-matrix entries. If True, also checks logical operators to certify identical full logical channels (choi_distance == 0). |
import paulicert as pc
steane = pc.get_preset_code("7-1-3-steane")
five = pc.get_preset_code("5-1-3-perfect")
ch = pc.CHANNEL_FAMILIES["coherent_x"](0.01)
print("[[5, 1, 3]] exact :", pc.pauli_exact(five, ch).exact) # True (fidelity exact)
print("[[5, 1, 3]] full_channel:", pc.pauli_exact(five, ch, full_channel=True).exact) # False (weight-5 logical XXXXX)
cert = pc.pauli_exact(steane, ch)
print(f"Steane -> exact={cert.exact} | witnesses={cert.num_witnesses} | min_weight={cert.min_witness_weight}")
# Steane -> exact=False | witnesses=7 | min_weight=4
PauliExactness
class PauliExactness
Frozen dataclass returned by pauli_exact.
| Attribute | Type | Description |
|---|---|---|
exact | bool | True if no witness exists (certified exact for logical fidelity, or for the full channel when full_channel=True). |
coherent_sets | tuple[str, ...] | Per-qubit active coherent Pauli labels (for example ("IZ", "IZ", ...)). |
witness_space_dim | int | GF(2) dimension of the witness subspace. |
num_witnesses | int | None | Total number of witnesses, or None if a non-group space has dimension > 20. |
min_witness_weight | int | None | Lowest Pauli weight among witnesses (computed when dimension ≤ 14 for group channels or ≤ 20 for non-group channels; None for larger spaces because exact minimum weight of a large linear code is NP-hard). |
witnesses | NDArray[np.uint8] | Array of shape (m, 2n) storing up to max_witnesses symplectic rows sorted by weight (or a basis for large spaces). |
minimal_twirl_set
def minimal_twirl_set(code: StabilizerCode, channel: QuantumChannel | Sequence[QuantumChannel], *, tol: float = 1e-10, full_channel: bool = False) → TwirlSet
Returns the qubit indices whose physical Pauli twirling makes pauli_exact certify the remaining noise as exact (using a single bit-packed GF(2) RREF pass for single-axis coherence and an exact branch-and-bound minimum hitting-set solver when witness_space_dim ≤ 20). Returns an empty set immediately if the channel is already certified exact.
| Parameter | Type | Default | Description |
|---|---|---|---|
code | StabilizerCode | — | Stabilizer code to analyze. |
channel | QuantumChannel | Sequence[QuantumChannel] | — | Single-qubit CPTP channel or length-n sequence of per-qubit channels. |
tol | float | 1e-10 | Relative threshold for off-diagonal process-matrix entries. |
full_channel | bool | False | If True, eliminates logical-operator witnesses as well so the full logical superoperator matches identically. |
import paulicert as pc
shor = pc.get_preset_code("9-1-3-shor")
ts = pc.minimal_twirl_set(shor, pc.CHANNEL_FAMILIES["coherent_z"](0.01))
print(f"Qubits to twirl: {ts.qubits} ({len(ts.qubits)}/{shor.n} qubits, provably_minimal={ts.provably_minimal})")
# Qubits to twirl: (0, 1, 3, 4, 6, 7) (6/9 qubits, provably_minimal=True)
TwirlSet
class TwirlSet
Frozen dataclass returned by minimal_twirl_set.
| Attribute | Type | Description |
|---|---|---|
qubits | tuple[int, ...] | Physical data-qubit indices to Pauli-twirl. |
provably_minimal | bool | True when no smaller subset can eliminate all algebraic witnesses (pauli_exact == True), guaranteed for single-axis coherence (e.g. amplitude damping or X/Y/Z rotations) and whenever the exact minimum hitting-set solver completes (witness_space_dim ≤ 20). Accidental coset cancellations (e.g. [[4, 2, 2]]) can still yield gap == 1 with fewer twirled qubits. |
witness_space_dim | int | GF(2) dimension of the witness subspace (matching PauliExactness.witness_space_dim). |