用物理单位原理约束代码生成,提升科学计算的可靠性。
Chain of Unit-Physics: A Primitive-Centric Approach to Scientific Code Synthesis
- 以物理基本单元为起点,通过专家测试约束代码生成过程。
- 在燃烧模拟任务中5-6轮内收敛,误差仅3.1×10⁻³%,效率更高。
- 适合需要高精度、可解释性的科学计算场景,如工程仿真与科研建模。
代理型大模型被提出作为科学计算的自主代码生成器,但在高风险问题中的可靠性仍不明确。从自然语言查询生成计算科学软件仍面临两大挑战:(a) 训练期间领域代码表示稀疏;(b) 小规模专家社区难以支持强化学习人类反馈(RLHF)。为此,本文提出反向代码设计思路,构建链式单位物理(Chain of Unit-Physics)框架:一种以第一性原理(或基本单元)为中心的多智能体系统,将人类专家知识编码为单位物理测试,显式约束代码生成。该框架在具有真实物理约束的非平凡燃烧任务上评估,作为科学问题的代表性基准。闭源系统和以代码为中心的代理变体即使具备工具与网络访问能力,仍无法生成正确端到端求解器,表现出四类常见错误:接口(语法/API)幻觉、过度自信假设、数值/物理不一致以及配置脆弱性。开源模型结合思维链(CoT)解码虽减少接口错误,但仍产出错误结果。在该基准任务中,所提框架在5-6次迭代内收敛,与人工专家实现误差相当(均值3.1×10⁻³%),运行速度提升约33.4%,内存使用降低约30%,成本接近中等规模商业API,提供可实用的物理驱动科学代码生成模板。随着数据集与模型演进,零样本代码准确率将进一步提升;但链式单位物理框架更进一步,嵌入了科学代码的基础性第一性原理分析。
原文摘要 · Abstract (English)
Agentic large language models are proposed as autonomous code generators for scientific computing, yet their reliability in high-stakes problems remains unclear. Developing computational scientific software from natural-language queries remains challenging broadly due to (a) sparse representation of domain codes during training and (b) the limited feasibility of RLHF with a small expert community. To address these limitations, this work conceptualizes an inverse approach to code design, embodied in the Chain of Unit-Physics framework: a first-principles (or primitives)-centric, multi-agent system in which human expert knowledge is encoded as unit-physics tests that explicitly constrain code generation. The framework is evaluated on a nontrivial combustion task, used here as a representative benchmark for scientific problem with realistic physical constraints. Closed-weight systems and code-focused agentic variants fail to produce correct end-to-end solvers, despite tool and web access, exhibiting four recurrent error classes: interface (syntax/API) hallucinations, overconfident assumptions, numerical/physical incoherence, and configuration fragility. Open-weight models with chain-of-thought (CoT) decoding reduce interface errors but still yield incorrect solutions. On the benchmark task, the proposed framework converges within 5-6 iterations, matches the human-expert implementation (mean error of $3.1\times10^{-3}$ %), with a $\sim$33.4 % faster runtime and a $\sim$30 % efficient memory usage at a cost comparable to mid-sized commercial APIs, yielding a practical template for physics-grounded scientific code generation. As datasets and models evolve, zero-shot code accuracy will improve; however, the Chain of Unit-Physics framework goes further by embedding first-principles analysis that is foundational to scientific codes.
Thank you to arXiv for use of its open access interoperability. PaperDance 不是 arXiv 官方产品;中文卡片由大模型生成,请以原文为准。