1use thiserror::Error;
2
3#[derive(Error, Debug, Clone, PartialEq, Eq)]
5pub enum QuantRS2Error {
6 #[error("Invalid qubit ID {0}, must be within the valid range for this operation")]
8 InvalidQubitId(u32),
9
10 #[error("Unsupported operation: {0}")]
12 UnsupportedOperation(String),
13
14 #[error("Failed to apply gate: {0}")]
16 GateApplicationFailed(String),
17
18 #[error("Circuit validation failed: {0}")]
20 CircuitValidationFailed(String),
21
22 #[error("Backend execution failed: {0}")]
24 BackendExecutionFailed(String),
25
26 #[error("Unsupported qubit count {0}: {1}")]
28 UnsupportedQubits(usize, String),
29
30 #[error("Invalid input: {0}")]
32 InvalidInput(String),
33
34 #[error("Computation error: {0}")]
36 ComputationError(String),
37
38 #[error("Linear algebra error: {0}")]
40 LinalgError(String),
41
42 #[error("Routing error: {0}")]
44 RoutingError(String),
45}
46
47pub type QuantRS2Result<T> = Result<T, QuantRS2Error>;
49
50impl From<ndarray::ShapeError> for QuantRS2Error {
51 fn from(err: ndarray::ShapeError) -> Self {
52 QuantRS2Error::InvalidInput(format!("Shape error: {}", err))
53 }
54}
55
56#[cfg(feature = "mps")]
57#[allow(unexpected_cfgs)]
58impl From<ndarray_linalg::error::LinalgError> for QuantRS2Error {
59 fn from(err: ndarray_linalg::error::LinalgError) -> Self {
60 QuantRS2Error::LinalgError(format!("Linear algebra error: {}", err))
61 }
62}