The Neural Compiler: Program-to-Network Translation for Hybrid Scientific Machine Learning
About
Scientific machine learning often requires combining known physics with unknown parameters or correction terms learned from data. Existing approaches either ignore known structure, encode it as a soft penalty, or require hand-written PyTorch code for each equation. We present The Neural Compiler, a system that translates programs written in a first-order Scheme-like expression language into frozen, differentiable PyTorch modules. These modules match the source program to floating-point precision and provide gradients through autograd. In hybrid models, the compiled module encodes known physics exactly while learned components model the unknown remainder. We evaluate the compiler across six experiment domains: Feynman physics equations, Lotka-Volterra dynamics, a damped pendulum, a one-dimensional heat equation, three-dimensional vector mechanics, and compositional generalization. Compiled modules match hand-coded PyTorch implementations numerically for single equations, showing no accuracy loss from compilation. With only 1 to 4 trainable parameters, compiled models recover physical constants to less than 1 percent error in most cases, while standard PINN baselines with more than 8500 parameters show 7 to 93 percent error. Compiled modules also compose with zero error, while neural approximations can accumulate large errors in deep composition chains. The main value of the compiler is not improved accuracy over hand-coded equations, but systematic composability: it generates correct, differentiable modules from symbolic specifications without rewriting each equation by hand. The system supports 51 primitive operations, including vector and matrix algebra, enabling PDE discretizations and hybrid scientific models. This string-in, module-out interface also provides a natural target for large language models that translate scientific descriptions into executable differentiable modules.
Related benchmarks
| Task | Dataset | Result | Rank | |
|---|---|---|---|---|
| Coefficient Learning | Feynman Symbolic Regression in-distribution | MSE2.90e-10 | 45 | |
| Coefficient Learning | Feynman Symbolic Regression 5x extrapolation | MSE6.20e-8 | 45 | |
| Trajectory Prediction | Damped Pendulum ODE unforced (In-distribution) | Trajectory MSE1.50e-5 | 6 | |
| Trajectory Prediction | Damped Pendulum ODE unforced (2x extrapolation) | Trajectory MSE4.00e-6 | 6 | |
| Trajectory Prediction | Damped Pendulum ODE unforced 5x extrapolation | Trajectory MSE5.00e-6 | 6 | |
| Trajectory Prediction | Lotka-Volterra 2x Extrapolation | Trajectory MSE0.0049 | 5 | |
| Trajectory Prediction | Lotka-Volterra 5x Extrapolation | Trajectory MSE0.022 | 5 | |
| Parameter Recovery and Trajectory Prediction | Lotka-Volterra In-distribution | Trajectory MSE0.0024 | 5 | |
| Parameter Recovery | Damped Pendulum ODE unforced | g/L Error0.08 | 4 | |
| Thermal Diffusivity Recovery | 1D Heat Equation (held-out conditions) | MSE (Interpolation)3.70e-15 | 4 |