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 /// Unexpected error occurred
56 #[error("An unknown error occurred")]
57 UnknownError,
58
59 /// An error occurred during OpenCL operation
60 ///
61 /// # Arguments:
62 ///
63 /// * `0` - The OpenCL error message
64 #[error("OpenCL error: {0}")]
65 OpenCLError(String),
66
67 /// Failed to lock the global GPU context
68 #[error("Failed to lock GPU context")]
69 GpuContextLockError,
70}
71
72#[cfg(feature = "gpu")]
73impl From<ocl::Error> for Error {
74 fn from(err: ocl::Error) -> Self {
75 Error::OpenCLError(err.to_string())
76 }
77}