stabilizer_ch_form_rust/error/
mod.rs

1use thiserror::Error;
2
3pub type Result<T> = std::result::Result<T, Error>;
4
5/// Custom error type for StabilizerCHForm operations.
6#[derive(Error, Debug)]
7pub enum Error {
8    /// Error for invalid qubit index.
9    #[error("Qubit index {0} is out of bounds for {1} qubits.")]
10    QubitIndexOutOfBounds(usize, usize),
11
12    /// Error for invalid number of qubits.
13    #[error("Number of qubits must be greater than zero, got {0}.")]
14    InvalidNumQubits(usize),
15
16    /// Error for duplicate qubit indices in two-qubit gates.
17    #[error("Two-qubit gate requires two different qubit indices, but got the same: {0}.")]
18    DuplicateQubitIndices(usize),
19
20    /// Error for impossible projection during measurement.
21    #[error(
22        "Impossible projection on qubit {qubit_index}: cannot project determined state |{}> onto|{}>.",
23        if *desired { 0 } else { 1 },
24        if *desired { 1 } else { 0 }
25    )]
26    ImpossibleProjection { qubit_index: usize, desired: bool },
27
28    /// Error for mismatched qubit counts in operations involving two states (e.g., inner product).
29    #[error(
30        "The qubit counts of the two states must match for {}, got {} and {}.",
31        operation,
32        left,
33        right
34    )]
35    QubitCountMismatch {
36        operation: &'static str,
37        left: usize,
38        right: usize,
39    },
40
41    /// Error for invalid permutation length.
42    #[error("The length of the permutation ({0}) must match the number of qubits ({1}).")]
43    InvalidPermutationLength(usize, usize),
44
45    /// Error for invalid permutation (not a valid rearrangement).
46    #[error("The provided permutation {0:?} is not a valid permutation of qubit indices.")]
47    InvalidPermutation(Vec<usize>),
48
49    /// Error for invalid qubit state length.
50    #[error("The length of the qubit state ({0}) does not match the number of qubits ({1}).")]
51    InvalidQubitStateLength(usize, usize),
52
53    /// Error for attempting to discard a qubit that cannot be discarded.
54    #[error("Cannot discard qubit {0} because it is not in a proper state")]
55    CannotDiscardQubit(usize),
56
57    /// Error for QASM parsing issues.
58    #[error("QASM parsing error: {0}")]
59    QasmParsingError(String),
60
61    /// Error for Pauli string parsing issues.
62    #[error("Pauli string parsing error: {0}")]
63    PauliStringParsingError(String),
64
65    #[error("IO error: {0}")]
66    Io(#[from] std::io::Error),
67}