203 lines
5.4 KiB
Rust
203 lines
5.4 KiB
Rust
//! # RTX Science: Physics-Informed Neural Networks and Scientific Computing
|
|
//!
|
|
//! RTX Science provides comprehensive scientific machine learning capabilities with a focus on
|
|
//! physics-informed neural networks (PINNs), scientific computing primitives, and domain-specific
|
|
//! applications in chemistry, biology, and materials science.
|
|
|
|
#![allow(clippy::module_name_repetitions, clippy::similar_names)]
|
|
//!
|
|
//! ## Core Features
|
|
//!
|
|
//! ### Physics-Informed Neural Networks (PINNs)
|
|
//! - Automatic differentiation for physics laws
|
|
//! - Conservation law enforcement
|
|
//! - PDE constraint integration
|
|
//! - Physics loss functions
|
|
//!
|
|
//! ### Scientific Computing
|
|
//! - High-performance numerical solvers (ODE, PDE)
|
|
//! - Parallel algorithms for large-scale simulations
|
|
//! - GPU-accelerated scientific kernels
|
|
//! - Integration with BLAS, LAPACK, FFTW
|
|
//!
|
|
//! ### Domain Applications
|
|
//! - **Chemistry**: Molecular property prediction, drug discovery
|
|
//! - **Biology**: Protein structure prediction, genomics analysis
|
|
//! - **Materials**: Crystal structure prediction, property modeling
|
|
//!
|
|
//! ## Quick Start
|
|
//!
|
|
//! ```rust
|
|
//! use rtx_science::prelude::*;
|
|
//! use rtx_tensor::{Tensor, Device};
|
|
//!
|
|
//! # async fn example() -> Result<(), Box<dyn std::error::Error>> {
|
|
//! let device = Device::cuda(0)?;
|
|
//!
|
|
//! // Create a simple PINN for the heat equation
|
|
//! let mut pinn = PINN::builder()
|
|
//! .device(&device)
|
|
//! .layers(vec![2, 64, 64, 1]) // [x, t] -> u
|
|
//! .physics_loss(HeatEquation::new(0.1)) // thermal diffusivity = 0.1
|
|
//! .build()?;
|
|
//!
|
|
//! // Training data: boundary and initial conditions
|
|
//! let boundary_data = BoundaryConditions::dirichlet()
|
|
//! .at_boundary(|x, t| 0.0) // u = 0 at boundaries
|
|
//! .at_initial(|x| (x * std::f32::consts::PI).sin()) // u(x,0) = sin(πx)
|
|
//! .generate_samples(1000)?;
|
|
//!
|
|
//! // Train the PINN
|
|
//! pinn.train(boundary_data, 10000).await?;
|
|
//!
|
|
//! // Evaluate the solution
|
|
//! let solution = pinn.predict(&[(0.5, 1.0)]).await?;
|
|
//! println!("u(0.5, 1.0) = {:.6}", solution[0]);
|
|
//! # Ok(())
|
|
//! # }
|
|
//! ```
|
|
//!
|
|
//! ## Advanced Usage
|
|
//!
|
|
//! ### Multi-Physics Simulation
|
|
//! ```rust
|
|
//! # use rtx_science::prelude::*;
|
|
//! # use rtx_tensor::{Tensor, Device};
|
|
//! # async fn example() -> Result<(), Box<dyn std::error::Error>> {
|
|
//! # let device = Device::cuda(0)?;
|
|
//! // Coupled fluid dynamics and heat transfer
|
|
//! let mut multiphysics = MultiPhysicsPINN::builder()
|
|
//! .device(&device)
|
|
//! .add_physics(NavierStokes::new(1e-3, 1.0)) // viscosity, density
|
|
//! .add_physics(HeatEquation::new(0.1)) // thermal diffusivity
|
|
//! .add_coupling(ThermalCoupling::boussinesq(9.8, 1e-3)) // buoyancy
|
|
//! .build()?;
|
|
//! # Ok(())
|
|
//! # }
|
|
//! ```
|
|
//!
|
|
//! ### Molecular Property Prediction
|
|
//! ```rust
|
|
//! # use rtx_science::prelude::*;
|
|
//! # use rtx_tensor::{Tensor, Device};
|
|
//! # async fn example() -> Result<(), Box<dyn std::error::Error>> {
|
|
//! # let device = Device::cuda(0)?;
|
|
//! let mut molecular_model = MolecularGNN::builder()
|
|
//! .device(&device)
|
|
//! .node_features(74) // Atomic features
|
|
//! .edge_features(12) // Bond features
|
|
//! .message_passing_layers(6)
|
|
//! .readout_layers(vec![512, 256, 1])
|
|
//! .build()?;
|
|
//!
|
|
//! // Train on molecular property dataset
|
|
//! let dataset = MolecularDataset::load("molecules.csv")?;
|
|
//! molecular_model.train(&dataset, 100).await?;
|
|
//! # Ok(())
|
|
//! # }
|
|
//! ```
|
|
|
|
// Real scientific computing implementation
|
|
pub mod scientific_computing;
|
|
|
|
// Scientific computing tests
|
|
#[cfg(test)]
|
|
pub mod scientific_computing_tests;
|
|
|
|
#[cfg(test)]
|
|
mod integration_test;
|
|
|
|
// Re-export main scientific computing types
|
|
pub use scientific_computing::*;
|
|
|
|
pub mod error;
|
|
|
|
// Variable extensions for missing methods
|
|
pub mod variable_extensions;
|
|
|
|
// Core PINN functionality
|
|
#[cfg(feature = "pinn")]
|
|
pub mod physics;
|
|
|
|
// Domain-specific applications
|
|
#[cfg(feature = "chemistry")]
|
|
pub mod chemistry;
|
|
|
|
#[cfg(feature = "biology")]
|
|
pub mod biology;
|
|
|
|
#[cfg(feature = "materials")]
|
|
pub mod materials;
|
|
|
|
// Scientific computing infrastructure
|
|
#[cfg(feature = "computing")]
|
|
pub mod computing;
|
|
|
|
/// Missing types for rtx-science compilation
|
|
pub mod types;
|
|
|
|
// Common utilities and integration
|
|
pub mod integration;
|
|
pub mod prelude;
|
|
|
|
// Re-export core types
|
|
pub use error::{Result, ScienceError};
|
|
|
|
// Re-export missing types for compatibility
|
|
pub use rtx_autograd::Variable;
|
|
pub use types::{MemoryPool, OptimizationLevel};
|
|
|
|
#[cfg(feature = "pinn")]
|
|
pub use physics::{BoundaryConditions, PINN, PhysicsLoss};
|
|
|
|
/// Version information
|
|
pub const VERSION: &str = env!("CARGO_PKG_VERSION");
|
|
|
|
/// Feature information
|
|
#[must_use]
|
|
pub fn features() -> Vec<&'static str> {
|
|
let mut features = vec![];
|
|
|
|
#[cfg(feature = "pinn")]
|
|
features.push("pinn");
|
|
|
|
#[cfg(feature = "chemistry")]
|
|
features.push("chemistry");
|
|
|
|
#[cfg(feature = "biology")]
|
|
features.push("biology");
|
|
|
|
#[cfg(feature = "materials")]
|
|
features.push("materials");
|
|
|
|
#[cfg(feature = "computing")]
|
|
features.push("computing");
|
|
|
|
#[cfg(feature = "cuda-enhanced")]
|
|
features.push("cuda-enhanced");
|
|
|
|
#[cfg(feature = "distributed-sci")]
|
|
features.push("distributed-sci");
|
|
|
|
features
|
|
}
|
|
|
|
#[cfg(test)]
|
|
mod tests {
|
|
use super::*;
|
|
|
|
#[test]
|
|
fn test_version() {
|
|
assert!(!VERSION.is_empty());
|
|
}
|
|
|
|
#[test]
|
|
fn test_features() {
|
|
let features = features();
|
|
assert!(!features.is_empty());
|
|
|
|
#[cfg(feature = "pinn")]
|
|
assert!(features.contains(&"pinn"));
|
|
}
|
|
}
|