phop_core/error.rs
1//! Error types for the phop engine.
2
3use thiserror::Error;
4
5/// Errors that can arise during data loading, forest evaluation, or discovery.
6#[derive(Debug, Error)]
7pub enum PhopError {
8 /// Underlying I/O failure (e.g. reading a CSV file).
9 #[error("I/O error: {0}")]
10 Io(#[from] std::io::Error),
11
12 /// CSV parsing failure.
13 #[error("CSV error: {0}")]
14 Csv(#[from] csv::Error),
15
16 /// A value could not be parsed as a floating-point number.
17 #[error("parse error: {0}")]
18 Parse(String),
19
20 /// Tensor / array shapes were incompatible.
21 #[error("shape mismatch: {0}")]
22 ShapeMismatch(String),
23
24 /// A forward/backward pass produced non-finite values.
25 #[error("numerical instability: {0}")]
26 NumericalInstability(String),
27
28 /// The optimizer did not reach the configured tolerance.
29 #[error("not converged: {0}")]
30 NotConverged(String),
31
32 /// Failure while evaluating an autograd graph.
33 #[error("evaluation error: {0}")]
34 Eval(String),
35
36 /// Failure in the symbolic distillation / canonicalization stage.
37 #[error("symbolic error: {0}")]
38 Symbolic(String),
39
40 /// Failure in a compute backend (e.g. the CUDA GPU path).
41 #[error("backend error: {0}")]
42 Backend(String),
43}
44
45/// Convenience alias for results returned by phop.
46pub type Result<T> = std::result::Result<T, PhopError>;