quant_iron/
errors.rs

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