quantrs2_ml/
error.rs

1use quantrs2_core::error::QuantRS2Error;
2use std::io;
3use thiserror::Error;
4
5/// Type alias for Result with MLError as error type
6pub type Result<T> = std::result::Result<T, MLError>;
7
8/// Error type for Machine Learning operations
9#[derive(Error, Debug)]
10pub enum MLError {
11    /// Error during training or inference
12    #[error("Machine learning error: {0}")]
13    MLOperationError(String),
14
15    /// Error during model creation
16    #[error("Model creation error: {0}")]
17    ModelCreationError(String),
18
19    /// Error in optimization process
20    #[error("Optimization error: {0}")]
21    OptimizationError(String),
22
23    /// Error in data handling
24    #[error("Data error: {0}")]
25    DataError(String),
26
27    /// Error in quantum circuit execution
28    #[error("Circuit execution error: {0}")]
29    CircuitExecutionError(String),
30
31    /// Error during feature extraction
32    #[error("Feature extraction error: {0}")]
33    FeatureExtractionError(String),
34
35    /// Invalid parameter
36    #[error("Invalid parameter: {0}")]
37    InvalidParameter(String),
38
39    /// Invalid input
40    #[error("Invalid input: {0}")]
41    InvalidInput(String),
42
43    /// Invalid configuration
44    #[error("Invalid configuration: {0}")]
45    InvalidConfiguration(String),
46
47    /// Configuration error
48    #[error("Configuration error: {0}")]
49    ConfigurationError(String),
50
51    /// Dimension mismatch error
52    #[error("Dimension mismatch: {0}")]
53    DimensionMismatch(String),
54
55    /// Not implemented
56    #[error("Not implemented: {0}")]
57    NotImplemented(String),
58
59    /// Not supported
60    #[error("Not supported: {0}")]
61    NotSupported(String),
62
63    /// Validation error
64    #[error("Validation error: {0}")]
65    ValidationError(String),
66
67    /// Model not trained
68    #[error("Model not trained: {0}")]
69    ModelNotTrained(String),
70
71    /// Computation error
72    #[error("Computation error: {0}")]
73    ComputationError(String),
74
75    /// I/O error
76    #[error("I/O error: {0}")]
77    IOError(#[from] io::Error),
78
79    /// Quantum error
80    #[error("Quantum error: {0}")]
81    QuantumError(#[from] QuantRS2Error),
82
83    /// Shape error from ndarray
84    #[error("Shape error: {0}")]
85    ShapeError(#[from] scirs2_core::ndarray::ShapeError),
86
87    /// JSON serialization error
88    #[error("JSON error: {0}")]
89    JsonError(#[from] serde_json::Error),
90
91    /// Numerical error during computation
92    #[error("Numerical error: {0}")]
93    NumericalError(String),
94
95    /// Backend error
96    #[error("Backend error: {0}")]
97    BackendError(String),
98}
99
100impl From<String> for MLError {
101    fn from(s: String) -> Self {
102        MLError::ComputationError(s)
103    }
104}