Skip to main content

ppvm_traits/
char.rs

1// SPDX-FileCopyrightText: 2026 The PPVM Authors
2// SPDX-License-Identifier: Apache-2.0
3
4/// A single-qubit Pauli symbol.
5///
6/// The four standard Paulis are encoded so that the low two bits identify
7/// the operator (`I = 0b00`, `X = 0b01`, `Z = 0b10`, `Y = 0b11`), which is
8/// the same encoding stabilizer-formalism tools commonly use. The extra
9/// variant [`Pauli::L`] marks a qubit as *lost*, used by the loss-aware
10/// portions of the runtime.
11///
12/// # Examples
13///
14/// ```
15/// use ppvm_traits::char::Pauli;
16///
17/// assert_eq!(Pauli::I.to_string(), "I");
18/// assert_eq!(Pauli::X.to_string(), "X");
19/// assert_eq!(Pauli::Y.to_string(), "Y");
20/// assert_eq!(Pauli::Z.to_string(), "Z");
21/// assert_eq!(Pauli::L.to_string(), "L");
22/// ```
23#[derive(Debug, Clone, Copy, PartialEq, Eq)]
24#[repr(u8)]
25pub enum Pauli {
26    /// Identity `I`.
27    I = 0, // 0b00
28    /// Pauli `X`.
29    X = 1, // 0b01
30    /// Pauli `Z`.
31    Z = 2, // 0b10
32    /// Pauli `Y`.
33    Y = 3, // 0b11
34    /// Loss marker — the qubit has been lost and no longer participates.
35    L = 4, // 0b100
36}
37
38impl std::fmt::Display for Pauli {
39    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
40        match self {
41            Pauli::I => write!(f, "I"),
42            Pauli::X => write!(f, "X"),
43            Pauli::Y => write!(f, "Y"),
44            Pauli::Z => write!(f, "Z"),
45            Pauli::L => write!(f, "L"),
46        }
47    }
48}
49
50#[cfg(test)]
51mod tests {
52    use super::*;
53
54    #[test]
55    fn test_paul_word_display() {
56        insta::assert_yaml_snapshot!(Pauli::I.to_string());
57        insta::assert_yaml_snapshot!(Pauli::X.to_string());
58        insta::assert_yaml_snapshot!(Pauli::Y.to_string());
59        insta::assert_yaml_snapshot!(Pauli::Z.to_string());
60    }
61}