temporal_neural_solver/core/
errors.rs1use thiserror::Error;
4use std::time::Duration;
5
6#[derive(Error, Debug)]
8pub enum TemporalSolverError {
9 #[error("Dimension mismatch: expected {expected}, got {got}")]
10 DimensionMismatch { expected: usize, got: usize },
11
12 #[error("Solver error: {0}")]
13 SolverError(String),
14
15 #[error("Numerical error: {0}")]
16 NumericalError(String),
17
18 #[error("Certificate validation failed: error {error} exceeds threshold {threshold}")]
19 CertificateError { error: f64, threshold: f64 },
20
21 #[error("Hardware verification failed: {reason}")]
22 HardwareError { reason: String },
23
24 #[error("Benchmark error: {message}")]
25 BenchmarkError { message: String },
26
27 #[error("Statistical validation failed: {test} with p-value {p_value}")]
28 StatisticalError { test: String, p_value: f64 },
29
30 #[error("Integrity verification failed: {component}")]
31 IntegrityError { component: String },
32
33 #[error("Timeout error: operation took {duration:?}, limit was {limit:?}")]
34 TimeoutError { duration: Duration, limit: Duration },
35
36 #[error("Configuration error: {parameter} = {value} is invalid")]
37 ConfigError { parameter: String, value: String },
38
39 #[error("IO error: {0}")]
40 IoError(#[from] std::io::Error),
41
42 #[error("Serialization error: {0}")]
43 SerializationError(#[from] serde_json::Error),
44
45 #[error("Unknown error: {0}")]
46 Unknown(String),
47}
48
49pub type Result<T> = std::result::Result<T, TemporalSolverError>;
51
52#[derive(Error, Debug)]
54pub enum ValidationError {
55 #[error("Insufficient samples: got {got}, need at least {required}")]
56 InsufficientSamples { got: usize, required: usize },
57
58 #[error("Performance regression detected: {metric} increased by {percentage:.1}%")]
59 PerformanceRegression { metric: String, percentage: f64 },
60
61 #[error("Statistical assumption violated: {assumption}")]
62 AssumptionViolated { assumption: String },
63
64 #[error("Hardware requirement not met: {requirement}")]
65 HardwareRequirement { requirement: String },
66
67 #[error("Reproducibility check failed: {details}")]
68 ReproducibilityFailed { details: String },
69}
70
71#[derive(Debug, Clone)]
73pub struct Warning {
74 pub category: WarningCategory,
75 pub message: String,
76 pub impact: ImpactLevel,
77 pub suggestion: Option<String>,
78}
79
80#[derive(Debug, Clone)]
81pub enum WarningCategory {
82 Performance,
83 Hardware,
84 Configuration,
85 Statistical,
86 Reproducibility,
87}
88
89#[derive(Debug, Clone)]
90pub enum ImpactLevel {
91 Low,
92 Medium,
93 High,
94 Critical,
95}
96
97impl Warning {
98 pub fn new(
99 category: WarningCategory,
100 message: String,
101 impact: ImpactLevel,
102 suggestion: Option<String>,
103 ) -> Self {
104 Self {
105 category,
106 message,
107 impact,
108 suggestion,
109 }
110 }
111
112 pub fn performance(message: String) -> Self {
113 Self::new(
114 WarningCategory::Performance,
115 message,
116 ImpactLevel::Medium,
117 None,
118 )
119 }
120
121 pub fn hardware(message: String, suggestion: String) -> Self {
122 Self::new(
123 WarningCategory::Hardware,
124 message,
125 ImpactLevel::High,
126 Some(suggestion),
127 )
128 }
129
130 pub fn configuration(message: String, suggestion: String) -> Self {
131 Self::new(
132 WarningCategory::Configuration,
133 message,
134 ImpactLevel::Medium,
135 Some(suggestion),
136 )
137 }
138}