1use quantrs2_core::error::QuantRS2Error;
4use thiserror::Error;
5
6#[derive(Debug, Clone, Error)]
8pub enum SimulatorError {
9 #[error("Invalid number of qubits: {0}")]
11 InvalidQubits(usize),
12
13 #[error("Invalid qubit count: {0}")]
15 InvalidQubitCount(String),
16
17 #[error("Qubit index {index} out of range for {num_qubits} qubits")]
19 InvalidQubitIndex { index: usize, num_qubits: usize },
20
21 #[error("Invalid gate: {0}")]
23 InvalidGate(String),
24
25 #[error("Computation error: {0}")]
27 ComputationError(String),
28
29 #[error("Gate target out of bounds: {0}")]
31 IndexOutOfBounds(usize),
32
33 #[error("Invalid operation: {0}")]
35 InvalidOperation(String),
36
37 #[error("GPU not available")]
39 GPUNotAvailable,
40
41 #[error("Shader compilation failed: {0}")]
43 ShaderCompilationError(String),
44
45 #[error("GPU execution error: {0}")]
47 GPUExecutionError(String),
48
49 #[error("GPU error: {0}")]
51 GpuError(String),
52
53 #[error("Dimension mismatch: {0}")]
55 DimensionMismatch(String),
56
57 #[error("Invalid input: {0}")]
59 InvalidInput(String),
60
61 #[error("Invalid configuration: {0}")]
63 InvalidConfiguration(String),
64
65 #[error("Numerical error: {0}")]
67 NumericalError(String),
68
69 #[error("Core error: {0}")]
71 CoreError(#[from] QuantRS2Error),
72
73 #[error("Unsupported operation: {0}")]
75 UnsupportedOperation(String),
76
77 #[error("Linear algebra error: {0}")]
79 LinalgError(String),
80
81 #[error("Initialization failed: {0}")]
83 InitializationFailed(String),
84
85 #[error("Memory error: {0}")]
87 MemoryError(String),
88
89 #[error("Initialization error: {0}")]
91 InitializationError(String),
92
93 #[error("Operation not supported: {0}")]
95 OperationNotSupported(String),
96
97 #[error("Invalid parameter: {0}")]
99 InvalidParameter(String),
100
101 #[error("Not implemented: {0}")]
103 NotImplemented(String),
104
105 #[error("Memory allocation failed: {0}")]
107 MemoryAllocationFailed(String),
108
109 #[error("Resource exhausted: {0}")]
111 ResourceExhausted(String),
112
113 #[error("Invalid state: {0}")]
115 InvalidState(String),
116
117 #[error("Backend error: {0}")]
119 BackendError(String),
120
121 #[error("Invalid observable: {0}")]
123 InvalidObservable(String),
124}
125
126pub type Result<T> = std::result::Result<T, SimulatorError>;
128
129impl From<scirs2_core::ndarray::ShapeError> for SimulatorError {
130 fn from(err: scirs2_core::ndarray::ShapeError) -> Self {
131 Self::DimensionMismatch(err.to_string())
132 }
133}
134
135impl From<scirs2_core::linalg::LapackError> for SimulatorError {
136 fn from(err: scirs2_core::linalg::LapackError) -> Self {
137 Self::LinalgError(format!("LAPACK error: {err}"))
138 }
139}