1use quantrs2_core::error::QuantRS2Error;
4use thiserror::Error;
5
6#[derive(Debug, Clone, Error)]
8#[non_exhaustive]
9pub enum SimulatorError {
10 #[error("Invalid number of qubits: {0}")]
12 InvalidQubits(usize),
13
14 #[error("Invalid qubit count: {0}")]
16 InvalidQubitCount(String),
17
18 #[error("Qubit index {index} out of range for {num_qubits} qubits")]
20 InvalidQubitIndex { index: usize, num_qubits: usize },
21
22 #[error("Invalid gate: {0}")]
24 InvalidGate(String),
25
26 #[error("Computation error: {0}")]
28 ComputationError(String),
29
30 #[error("Gate target out of bounds: {0}")]
32 IndexOutOfBounds(usize),
33
34 #[error("Invalid operation: {0}")]
36 InvalidOperation(String),
37
38 #[error("GPU not available")]
40 GPUNotAvailable,
41
42 #[error("Shader compilation failed: {0}")]
44 ShaderCompilationError(String),
45
46 #[error("GPU execution error: {0}")]
48 GPUExecutionError(String),
49
50 #[error("GPU error: {0}")]
52 GpuError(String),
53
54 #[error("Dimension mismatch: {0}")]
56 DimensionMismatch(String),
57
58 #[error("Invalid input: {0}")]
60 InvalidInput(String),
61
62 #[error("Invalid configuration: {0}")]
64 InvalidConfiguration(String),
65
66 #[error("Numerical error: {0}")]
68 NumericalError(String),
69
70 #[error("Core error: {0}")]
72 CoreError(#[from] QuantRS2Error),
73
74 #[error("Unsupported operation: {0}")]
76 UnsupportedOperation(String),
77
78 #[error("Linear algebra error: {0}")]
80 LinalgError(String),
81
82 #[error("Initialization failed: {0}")]
84 InitializationFailed(String),
85
86 #[error("Memory error: {0}")]
88 MemoryError(String),
89
90 #[error("Initialization error: {0}")]
92 InitializationError(String),
93
94 #[error("Operation not supported: {0}")]
96 OperationNotSupported(String),
97
98 #[error("Invalid parameter: {0}")]
100 InvalidParameter(String),
101
102 #[error("Not implemented: {0}")]
104 NotImplemented(String),
105
106 #[error("Memory allocation failed: {0}")]
108 MemoryAllocationFailed(String),
109
110 #[error("Resource exhausted: {0}")]
112 ResourceExhausted(String),
113
114 #[error("Invalid state: {0}")]
116 InvalidState(String),
117
118 #[error("Backend error: {0}")]
120 BackendError(String),
121
122 #[error("Invalid observable: {0}")]
124 InvalidObservable(String),
125}
126
127pub type Result<T> = std::result::Result<T, SimulatorError>;
129
130impl From<scirs2_core::ndarray::ShapeError> for SimulatorError {
131 fn from(err: scirs2_core::ndarray::ShapeError) -> Self {
132 Self::DimensionMismatch(err.to_string())
133 }
134}
135
136impl From<scirs2_core::linalg::LapackError> for SimulatorError {
137 fn from(err: scirs2_core::linalg::LapackError) -> Self {
138 Self::LinalgError(format!("LAPACK error: {err}"))
139 }
140}