tensorlogic_quantrs_hooks/
error.rs1use std::fmt;
4
5#[derive(Debug, Clone, PartialEq)]
7pub enum PgmError {
8 VariableNotFound(String),
10 FactorNotFound(String),
12 DimensionMismatch {
14 expected: Vec<usize>,
15 got: Vec<usize>,
16 },
17 InvalidDistribution(String),
19 ConvergenceFailure(String),
21 InvalidGraph(String),
23}
24
25impl fmt::Display for PgmError {
26 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
27 match self {
28 Self::VariableNotFound(name) => write!(f, "Variable not found: {}", name),
29 Self::FactorNotFound(name) => write!(f, "Factor not found: {}", name),
30 Self::DimensionMismatch { expected, got } => {
31 write!(
32 f,
33 "Dimension mismatch: expected {:?}, got {:?}",
34 expected, got
35 )
36 }
37 Self::InvalidDistribution(msg) => write!(f, "Invalid distribution: {}", msg),
38 Self::ConvergenceFailure(msg) => write!(f, "Convergence failure: {}", msg),
39 Self::InvalidGraph(msg) => write!(f, "Invalid graph: {}", msg),
40 }
41 }
42}
43
44impl std::error::Error for PgmError {}
45
46pub type Result<T> = std::result::Result<T, PgmError>;