Files
rustytorch/demos/pinn-benchmark-shared/src/lib.rs
T
2026-03-04 00:08:42 +00:00

83 lines
2.6 KiB
Rust

//! Shared types for `RustyTorch`++ PINN benchmark demo IPC
//!
//! This crate provides all shared data structures for communication between
//! the Tauri frontend and `RustyTorch`++ backend in the PINN benchmark demo.
//!
//! # Modules
//!
//! - [`config`]: PINN benchmark configuration types
//! - [`ipc`]: Inter-process communication message types
//! - [`error`]: Error types for the demo
//!
//! # Example
//!
//! ```rust
//! use pinn_benchmark_shared::config::{ProblemType, BenchmarkConfig};
//! use pinn_benchmark_shared::ipc::{PINNBenchmarkRequest, PINNBenchmarkResponse};
//!
//! // Create a Burgers equation configuration
//! let config = BenchmarkConfig {
//! problem: ProblemType::Burgers1D,
//! hidden_layers: vec![64, 64, 64],
//! learning_rate: 0.001,
//! num_epochs: 1000,
//! num_collocation_points: 10000,
//! num_boundary_points: 100,
//! device: "cpu".to_string(),
//! };
//!
//! // Create initialization request
//! let request = PINNBenchmarkRequest::Initialize { config };
//! ```
#![forbid(unsafe_code)]
#![warn(missing_docs)]
pub mod config;
pub mod error;
pub mod ipc;
pub use config::{BenchmarkConfig, ProblemType};
pub use error::{PINNBenchmarkError, Result};
pub use ipc::{
AccuracyMetrics, BenchmarkResult, ComparisonResult, PINNBenchmarkRequest,
PINNBenchmarkResponse, TrainingProgress,
};
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn test_serde_round_trip_problem_type() {
let problem = ProblemType::Burgers1D;
let json = serde_json::to_string(&problem).expect("Failed to serialize");
let deserialized: ProblemType = serde_json::from_str(&json).expect("Failed to deserialize");
assert_eq!(
std::mem::discriminant(&problem),
std::mem::discriminant(&deserialized)
);
}
#[test]
fn test_serde_round_trip_benchmark_config() {
let config = BenchmarkConfig {
problem: ProblemType::Heat1D,
hidden_layers: vec![32, 32],
learning_rate: 0.001,
num_epochs: 100,
num_collocation_points: 1000,
num_boundary_points: 50,
device: "cpu".to_string(),
};
let json = serde_json::to_string(&config).expect("Failed to serialize");
let deserialized: BenchmarkConfig =
serde_json::from_str(&json).expect("Failed to deserialize");
assert_eq!(config.hidden_layers, deserialized.hidden_layers);
assert!((config.learning_rate - deserialized.learning_rate).abs() < 1e-10);
assert_eq!(config.num_epochs, deserialized.num_epochs);
}
}