1use thiserror::Error;
2
3use laddu_compile::ReductionError;
4
5pub type RuntimeResult<T> = Result<T, RuntimeError>;
7
8#[derive(Clone, Debug, Error, PartialEq)]
10pub enum RuntimeError {
11 #[error(transparent)]
13 Execution(#[from] ExecutionError),
14 #[error(transparent)]
16 Memory(#[from] laddu_memory::MemoryError),
17 #[error("event scalar `{0}` was requested, but no event lookup was provided")]
19 MissingEventScalar(String),
20 #[error("node #{index} expected {expected}, got {actual}")]
22 TypeMismatch {
23 index: usize,
25 expected: &'static str,
27 actual: &'static str,
29 },
30 #[error("node #{index} has invalid shape: {message}")]
32 InvalidShape {
33 index: usize,
35 message: String,
37 },
38 #[error("matrix solve failed at node #{0}")]
40 SingularMatrix(usize),
41 #[error("event cache has {actual} slots, expected {expected}")]
43 InvalidCache {
44 expected: usize,
46 actual: usize,
48 },
49 #[error("event cache was built for a different cache layout")]
51 InvalidCacheLayout,
52 #[error("event scalar `{0}` was not found in the event batch schema")]
54 MissingEventColumn(String),
55 #[error("data error: {0}")]
57 Data(String),
58 #[error("parameter error: {0}")]
60 Parameter(String),
61 #[error("JIT kernel execution failed with status {0}")]
63 JitExecution(i32),
64 #[error(transparent)]
66 Reduction(#[from] ReductionError),
67 #[error("an MPI peer failed during distributed evaluation")]
69 DistributedPeerFailure,
70 #[error("WGPU execution failed: {0}")]
72 Wgpu(String),
73}
74
75#[derive(Clone, Debug, Error, PartialEq, Eq)]
77pub enum ExecutionError {
78 #[error("fixed thread count must be nonzero")]
80 ZeroThreads,
81 #[error("failed to create Rayon thread pool: {0}")]
83 ThreadPool(String),
84 #[error("f32 CPU execution currently requires scalar arithmetic over raw event caches")]
86 UnsupportedCpuF32Model,
87 #[error("f32 CPU gradients are not implemented yet")]
89 UnsupportedCpuF32Gradient,
90 #[error("GPU backend {0:?} is not available")]
92 GpuUnavailable(crate::GpuBackend),
93 #[error("GPU gradients are not implemented yet")]
95 UnsupportedGpuGradient,
96 #[error("reverse-mode autodiff is currently only supported for f64 CPU execution")]
98 UnsupportedReverseAutodiff,
99 #[error("CPU JIT execution was requested but the `jit` feature is unavailable")]
101 JitUnavailable,
102}