将科学方程自动编译为可微模块,实现物理规律与数据学习的精准结合。
The Neural Compiler: Program-to-Network Translation for Hybrid Scientific Machine Learning

- 用类Scheme语言编写方程,自动生成冻结可微的PyTorch模块
- 仅需1-4个参数即可还原物理常数,误差低于1%,远超传统PINN
- 支持模块零误差组合,适合需要系统性构建的科学建模场景
科学机器学习常需结合已知物理规律与未知参数或数据学习项。现有方法或忽略结构、或以软约束编码,或需为每条方程手写PyTorch代码。我们提出神经编译器(The Neural Compiler),将一阶类Scheme表达式程序自动翻译为冻结的可微PyTorch模块,匹配浮点精度并支持autograd梯度传播。在混合模型中,编译模块精确编码已知物理,学习部分建模未知剩余。我们在六类实验中评估:费曼物理方程、洛特卡-沃尔泰拉动力学、阻尼摆、一维热方程、三维矢量力学及组合泛化。编译模块与手工代码数值一致,无精度损失;仅1至4个可训练参数下,物理常数恢复误差普遍低于1%,而标准PINN基线(8500+参数)误差达7%至93%。编译模块组合零误差,神经近似在深层链中累积大误差。核心价值在于系统可组合性:无需逐个重写,即可从符号规范生成正确可微模块。系统支持51种原语操作,含向量矩阵运算,支持偏微分方程离散化与混合科学建模。此“字符串输入、模块输出”接口也为大语言模型提供自然目标,将科学描述转为可执行可微模块。
原文摘要 · Abstract (English)
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.
Thank you to arXiv for use of its open access interoperability. PaperDance 不是 arXiv 官方产品;中文卡片由大模型生成,请以原文为准。