tk_pg_bitpacked/u8_encodings.rs
1/// U8 encoding for Pauli X
2pub const X_U8: u8 = 0;
3/// U8 encoding for Pauli Y
4pub const Y_U8: u8 = 1;
5/// U8 encoding for Pauli Z
6pub const Z_U8: u8 = 2;
7/// U8 encoding for Pauli I
8pub const I_U8: u8 = 3;
9
10// U8 encoding for TQE gates
11// base 3 encoding 3a+b
12/// U8 encoding for TQE gate XX
13pub const XX_U8: u8 = 0;
14/// U8 encoding for TQE gate XY
15pub const XY_U8: u8 = 1;
16/// U8 encoding for TQE gate XZ
17pub const XZ_U8: u8 = 2;
18/// U8 encoding for TQE gate YX
19pub const YX_U8: u8 = 3;
20/// U8 encoding for TQE gate YY
21pub const YY_U8: u8 = 4;
22/// U8 encoding for TQE gate YZ
23pub const YZ_U8: u8 = 5;
24/// U8 encoding for TQE gate ZX
25pub const ZX_U8: u8 = 6;
26/// U8 encoding for TQE gate ZY
27pub const ZY_U8: u8 = 7;
28/// U8 encoding for TQE gate ZZ
29pub const ZZ_U8: u8 = 8;
30
31/// Converts a pair of bits (z, x) into a u8 representing the corresponding Pauli operator.
32///
33/// # Arguments
34///
35/// - `z` (`u8`) - The Z bit of the Pauli operator.
36/// - `x` (`u8`) - The X bit of the Pauli operator.
37///
38/// # Returns
39///
40/// - `u8` - The U8 encoding of the corresponding Pauli operator.
41///
42#[inline(always)]
43pub fn bits_to_u8_pauli(z: u8, x: u8) -> u8 {
44 BITS_TO_U8_PAULI[z as usize * 2 + x as usize]
45}
46
47// 2*zbit + xbit
48const BITS_TO_U8_PAULI: [u8; 4] = [
49 I_U8, // 00: I
50 X_U8, // 01: X
51 Z_U8, // 10: Z
52 Y_U8, // 11: Y
53];
54
55/// Converts a U8 encoding of a TQE gate into a tuple of four u64 values.
56///
57/// # Arguments
58///
59/// - `gate` (`u8`) - The U8 encoding of the TQE gate.
60///
61/// # Returns
62///
63/// - `(u64, u64, u64, u64)` - The tuple of four u64 values representing the TQE gate.
64///
65#[inline(always)]
66pub fn u8_tqe_to_u64(gate: u8) -> (u64, u64, u64, u64) {
67 TQE_TO_U64[gate as usize]
68}
69const TQE_TO_U64: [(u64, u64, u64, u64); 9] = [
70 // XX
71 (0, u64::MAX, 0, u64::MAX),
72 // XY
73 (0, u64::MAX, u64::MAX, u64::MAX),
74 // XZ
75 (0, u64::MAX, u64::MAX, 0),
76 // YX
77 (u64::MAX, u64::MAX, 0, u64::MAX),
78 // YY
79 (u64::MAX, u64::MAX, u64::MAX, u64::MAX),
80 // YZ
81 (u64::MAX, u64::MAX, u64::MAX, 0),
82 // ZX
83 (u64::MAX, 0, 0, u64::MAX),
84 // ZY
85 (u64::MAX, 0, u64::MAX, u64::MAX),
86 // ZZ
87 (u64::MAX, 0, u64::MAX, 0),
88];