quant_iron/
errors.rs

1use num_complex::Complex;
2
3#[derive(Debug, thiserror::Error, Clone, PartialEq)]
4pub enum Error {
5    /// There is an invalid number of measurements
6    /// 
7    /// # Arguments:
8    /// 
9    /// * `0` - The invalid number of measurements
10    #[error("Invalid number of measurements: {0}")]
11    InvalidNumberOfMeasurements(usize),
12
13    /// The control qubits and target qubit indices are overlapping
14    /// 
15    /// # Arguments:
16    /// 
17    /// * `0` - The control qubit index
18    /// 
19    /// * `1` - The target qubit index
20    #[error("Control qubit index {0} overlaps with target qubit index {1}")]
21    OverlappingControlAndTargetQubits(usize, usize),
22
23    /// There is an invalid number of qubits
24    /// 
25    /// # Arguments:
26    /// 
27    /// * `0` - The invalid number of qubits
28    #[error("Invalid number of qubits: {0}")]
29    InvalidNumberOfQubits(usize),
30
31    /// A qubit index is invalid for the number of qubits
32    /// 
33    /// # Arguments:
34    /// 
35    /// * `0` - The invalid qubit index
36    /// * `1` - The number of qubits
37    #[error("Invalid qubit index: {0} for {1} qubits")]
38    InvalidQubitIndex(usize, usize),
39
40    /// The state vector is not normalised
41    #[error("State vector is not normalised")]
42    StateVectorNotNormalised,
43
44    /// Input matrix for arbitrary unitary operator was not unitary
45    #[error("Non-unitary matrix")]
46    NonUnitaryMatrix,
47
48    /// Unexpected number of inputs
49    /// 
50    /// # Arguments:
51    /// 
52    /// * `0` - The actual number of inputs
53    /// * `1` - The expected number of inputs
54    #[error("Unexpected number of inputs: expected {1}, got {0}")]
55    InvalidNumberOfInputs(usize, usize),
56
57    /// The number of parameters does not match the number of target qubits.
58    ///
59    /// # Arguments:
60    ///
61    /// * `expected` - The expected number of parameters.
62    /// * `actual` - The actual number of parameters.
63    #[error("Mismatched number of parameters: expected {expected}, got {actual}")]
64    MismatchedNumberOfParameters { expected: usize, actual: usize },
65
66    /// Unexpected error occurred
67    #[error("An unknown error occurred")]
68    UnknownError,
69
70    /// An error occurred during OpenCL operation
71    ///
72    /// # Arguments:
73    ///
74    /// * `0` - The OpenCL error message
75    #[error("OpenCL error: {0}")]
76    OpenCLError(String),
77
78    /// Failed to lock the global GPU context
79    #[error("Failed to lock GPU context")]
80    GpuContextLockError,
81
82    /// Failed to create circuit from macro
83    #[error("Failed to create circuit from macro: {0}")]
84    CircuitMacroError(String),
85
86    /// Invalid input value for operation
87    #[error("Invalid input value for operation: {0}")]
88    InvalidInputValue(usize),
89
90    /// The state cannot be normalised because it has zero norm.
91    #[error("The state cannot be normalised because it has zero norm.")]
92    ZeroNorm,
93
94    /// Invalid Pauli String coefficient
95    #[error("Invalid Pauli String coefficient: {0}")]
96    InvalidPauliStringCoefficient(Complex<f64>),
97}
98
99#[derive(Debug, thiserror::Error, Clone, PartialEq)]
100pub enum CompilerError {
101    #[error("I/O error: {0}")]
102    IOError(String),
103
104    #[error("An unsupported operation was encountered: {0}")]
105    UnsupportedOperator(String),
106
107    #[error("Invalid operands ({0}) for operator {1}")]
108    InvalidOperands(String, String),
109}
110
111#[cfg(feature = "gpu")]
112impl From<ocl::Error> for Error {
113    fn from(err: ocl::Error) -> Self {
114        Error::OpenCLError(err.to_string())
115    }
116}