1use num_complex::Complex;
2
3#[derive(Debug, thiserror::Error, Clone, PartialEq)]
4pub enum Error {
5 #[error("Invalid number of measurements: {0}")]
11 InvalidNumberOfMeasurements(usize),
12
13 #[error("Control qubit index {0} overlaps with target qubit index {1}")]
21 OverlappingControlAndTargetQubits(usize, usize),
22
23 #[error("Invalid number of qubits: {0}")]
29 InvalidNumberOfQubits(usize),
30
31 #[error("Invalid qubit index: {0} for {1} qubits")]
38 InvalidQubitIndex(usize, usize),
39
40 #[error("State vector is not normalised")]
42 StateVectorNotNormalised,
43
44 #[error("Non-unitary matrix")]
46 NonUnitaryMatrix,
47
48 #[error("Unexpected number of inputs: expected {1}, got {0}")]
55 InvalidNumberOfInputs(usize, usize),
56
57 #[error("Mismatched number of parameters: expected {expected}, got {actual}")]
64 MismatchedNumberOfParameters { expected: usize, actual: usize },
65
66 #[error("An unknown error occurred")]
68 UnknownError,
69
70 #[error("OpenCL error: {0}")]
76 OpenCLError(String),
77
78 #[error("Failed to lock GPU context")]
80 GpuContextLockError,
81
82 #[error("Failed to create circuit from macro: {0}")]
84 CircuitMacroError(String),
85
86 #[error("Invalid input value for operation: {0}")]
88 InvalidInputValue(usize),
89
90 #[error("The state cannot be normalised because it has zero norm.")]
92 ZeroNorm,
93
94 #[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}