//! Error types for PINN benchmark use serde::{Deserialize, Serialize}; use thiserror::Error; /// Result type for PINN benchmark operations pub type Result = std::result::Result; /// Error types for PINN benchmark demo #[derive(Debug, Clone, Error, Serialize, Deserialize)] pub enum PINNBenchmarkError { /// Configuration validation error #[error("Configuration error: {0}")] Configuration(String), /// Training error #[error("Training error: {0}")] Training(String), /// Inference error #[error("Inference error: {0}")] Inference(String), /// Device error #[error("Device error: {0}")] Device(String), /// Computation error #[error("Computation error: {0}")] Computation(String), /// Invalid state error #[error("Invalid state: {0}")] InvalidState(String), /// Serialization error #[error("Serialization error: {0}")] Serialization(String), /// Internal error #[error("Internal error: {0}")] Internal(String), } #[cfg(test)] mod tests { use super::*; #[test] fn test_error_display() { let err = PINNBenchmarkError::Configuration("Invalid learning rate".to_string()); let display = format!("{err}"); assert!(display.contains("Configuration error")); assert!(display.contains("Invalid learning rate")); } #[test] fn test_error_serde() { let err = PINNBenchmarkError::Training("Loss diverged".to_string()); let json = serde_json::to_string(&err).expect("Failed to serialize"); let deserialized: PINNBenchmarkError = serde_json::from_str(&json).expect("Failed to deserialize"); assert_eq!(format!("{err}"), format!("{deserialized}")); } #[test] fn test_result_type() { let ok_result: Result = Ok(42); assert!(ok_result.is_ok()); let err_result: Result = Err(PINNBenchmarkError::Internal("Test".to_string())); assert!(err_result.is_err()); } }