Skip to main content

ruvector_consciousness/
error.rs

1//! Error types for consciousness computation.
2
3use std::time::Duration;
4
5/// Primary error type for consciousness computations.
6#[derive(Debug, thiserror::Error)]
7pub enum ConsciousnessError {
8    /// Φ computation did not converge within budget.
9    #[error("phi did not converge after {iterations} iterations (current={current:.6}, delta={delta:.2e})")]
10    PhiNonConvergence {
11        iterations: usize,
12        current: f64,
13        delta: f64,
14    },
15
16    /// Numerical instability (NaN/Inf in matrix operations).
17    #[error("numerical instability at partition {partition}: {detail}")]
18    NumericalInstability { partition: usize, detail: String },
19
20    /// Compute budget exhausted.
21    #[error("budget exhausted: {reason}")]
22    BudgetExhausted { reason: String, elapsed: Duration },
23
24    /// Invalid input.
25    #[error("invalid input: {0}")]
26    InvalidInput(#[from] ValidationError),
27
28    /// System too large for exact computation.
29    #[error("system size {n} exceeds exact limit {max} — use approximate mode")]
30    SystemTooLarge { n: usize, max: usize },
31}
32
33/// Validation errors raised before computation.
34#[derive(Debug, thiserror::Error)]
35pub enum ValidationError {
36    #[error("dimension mismatch: {0}")]
37    DimensionMismatch(String),
38
39    #[error("non-finite value at element ({row}, {col})")]
40    NonFiniteValue { row: usize, col: usize },
41
42    #[error("TPM rows must sum to 1.0 (row {row} sums to {sum:.6})")]
43    InvalidTPM { row: usize, sum: f64 },
44
45    #[error("parameter out of range: {name} = {value} (expected {expected})")]
46    ParameterOutOfRange {
47        name: String,
48        value: String,
49        expected: String,
50    },
51
52    #[error("empty system: need at least 2 elements")]
53    EmptySystem,
54}
55
56pub type Result<T> = std::result::Result<T, ConsciousnessError>;