quantrs2_sim/
error.rs

1//! Error types for the quantum simulator module.
2
3use quantrs2_core::error::QuantRS2Error;
4use thiserror::Error;
5
6/// Error types for quantum simulation
7#[derive(Debug, Clone, Error)]
8pub enum SimulatorError {
9    /// Invalid number of qubits
10    #[error("Invalid number of qubits: {0}")]
11    InvalidQubits(usize),
12
13    /// Invalid gate specification
14    #[error("Invalid gate: {0}")]
15    InvalidGate(String),
16
17    /// Computation error during simulation
18    #[error("Computation error: {0}")]
19    ComputationError(String),
20
21    /// Gate target out of bounds
22    #[error("Gate target out of bounds: {0}")]
23    IndexOutOfBounds(usize),
24
25    /// Invalid operation
26    #[error("Invalid operation: {0}")]
27    InvalidOperation(String),
28
29    /// GPU not available
30    #[error("GPU not available")]
31    GPUNotAvailable,
32
33    /// Shader compilation failed
34    #[error("Shader compilation failed: {0}")]
35    ShaderCompilationError(String),
36
37    /// GPU execution error
38    #[error("GPU execution error: {0}")]
39    GPUExecutionError(String),
40
41    /// General GPU error
42    #[error("GPU error: {0}")]
43    GpuError(String),
44
45    /// Dimension mismatch
46    #[error("Dimension mismatch: {0}")]
47    DimensionMismatch(String),
48
49    /// Invalid input
50    #[error("Invalid input: {0}")]
51    InvalidInput(String),
52
53    /// Invalid configuration
54    #[error("Invalid configuration: {0}")]
55    InvalidConfiguration(String),
56
57    /// Numerical error
58    #[error("Numerical error: {0}")]
59    NumericalError(String),
60
61    /// Core error
62    #[error("Core error: {0}")]
63    CoreError(#[from] QuantRS2Error),
64
65    /// Unsupported operation
66    #[error("Unsupported operation: {0}")]
67    UnsupportedOperation(String),
68
69    /// Linear algebra error
70    #[error("Linear algebra error: {0}")]
71    LinalgError(String),
72
73    /// Initialization failed
74    #[error("Initialization failed: {0}")]
75    InitializationFailed(String),
76
77    /// Memory allocation error
78    #[error("Memory error: {0}")]
79    MemoryError(String),
80
81    /// Initialization error
82    #[error("Initialization error: {0}")]
83    InitializationError(String),
84
85    /// Operation not supported
86    #[error("Operation not supported: {0}")]
87    OperationNotSupported(String),
88
89    /// Invalid parameter
90    #[error("Invalid parameter: {0}")]
91    InvalidParameter(String),
92
93    /// Not implemented
94    #[error("Not implemented: {0}")]
95    NotImplemented(String),
96
97    /// Memory allocation failed
98    #[error("Memory allocation failed: {0}")]
99    MemoryAllocationFailed(String),
100
101    /// Resource exhausted
102    #[error("Resource exhausted: {0}")]
103    ResourceExhausted(String),
104
105    /// Invalid state
106    #[error("Invalid state: {0}")]
107    InvalidState(String),
108
109    /// Backend error
110    #[error("Backend error: {0}")]
111    BackendError(String),
112}
113
114/// Result type for simulator operations
115pub type Result<T> = std::result::Result<T, SimulatorError>;
116
117impl From<scirs2_core::ndarray::ShapeError> for SimulatorError {
118    fn from(err: scirs2_core::ndarray::ShapeError) -> Self {
119        SimulatorError::DimensionMismatch(err.to_string())
120    }
121}