quantrs2_core/
error.rs

1use thiserror::Error;
2
3/// Common error types for quantum operations
4#[derive(Error, Debug, Clone, PartialEq, Eq)]
5pub enum QuantRS2Error {
6    /// Error when a qubit is not in a valid range
7    #[error("Invalid qubit ID {0}, must be within the valid range for this operation")]
8    InvalidQubitId(u32),
9
10    /// Error when an operation is not supported
11    #[error("Unsupported operation: {0}")]
12    UnsupportedOperation(String),
13
14    /// Error when a gate application fails
15    #[error("Failed to apply gate: {0}")]
16    GateApplicationFailed(String),
17
18    /// Error when circuit validation fails
19    #[error("Circuit validation failed: {0}")]
20    CircuitValidationFailed(String),
21
22    /// Error when backend execution fails
23    #[error("Backend execution failed: {0}")]
24    BackendExecutionFailed(String),
25
26    /// Error when unsupported qubit count is requested
27    #[error("Unsupported qubit count {0}: {1}")]
28    UnsupportedQubits(usize, String),
29
30    /// Error when invalid input is provided
31    #[error("Invalid input: {0}")]
32    InvalidInput(String),
33
34    /// Error during computation
35    #[error("Computation error: {0}")]
36    ComputationError(String),
37}
38
39/// Result type for quantum operations
40pub type QuantRS2Result<T> = Result<T, QuantRS2Error>;