用大模型自动将老旧科学代码转为可微框架,提升模拟效率与参数优化速度。
Systematic LLM Translation of Legacy Scientific Code to Differentiable Frameworks: Application to a Land Surface Model

- 构建五阶段智能流水线,用大模型分析调用关系并自动修复编译错误。
- 在1.9万行的陆面模型上实现单次反向传播计算完整雅可比矩阵。
- 相比无梯度优化提速8倍,全集成运行快24倍,适合地球系统模型开发者。
可微编程为科学建模带来革命性能力,支持基于梯度的参数估计、敏感性分析和数据同化。然而,将遗留代码迁移到可微框架仍面临挑战。我们提出一个基于大模型的五阶段代理式流水线,将旧版 Fortran 代码转换为 JAX:静态依赖分析确定模块的翻译顺序;迭代编译-修复循环自主纠正错误;使用 Fortran 参考验证器在模块层面确保数值一致性,并完成集成与梯度验证。我们在一个包含19,000行代码的陆面模型 CLM-ml-v2 上实例化并评估该流水线,分析了73个模块翻译任务中的代理行为。最终生成的可微模型可在一次反向传播中计算完整雅可比矩阵,在参数恢复上比无梯度优化少8倍迭代次数,且在集成规模 N=2,048 时相较串行 Fortran 实现24倍的墙钟速度提升。翻译后的模型及流水线基础设施均已开源,可复用于其他地球系统模型组件的可微改造。
原文摘要 · Abstract (English)
Differentiable programming offers transformative capabilities for scientific modeling, enabling gradient-based parameter estimation, sensitivity analysis, and data assimilation. Yet, migrating legacy codebases into differentiable frameworks remains a challenge. We present a five-phase LLM-based agentic pipeline that translates legacy Fortran into JAX: static dependency analysis determines module translation order from the full call graph; iterative compile-repair loops correct errors autonomously; and a Fortran reference oracle enforces numerical parity at the module level before integration and gradient verification. We instantiate and evaluate the pipeline on CLM-ml-v2, a 19,000-line Fortran land surface model, and analyze agent behavior across 73 module translation tasks. The resulting differentiable model computes the complete Jacobian in a single backward pass, recovers physical parameters in eight times fewer steps than gradient-free optimization, and achieves a 24 times wall-clock speedup over sequential Fortran at ensemble size N=2,048. Both the translated model and pipeline infrastructure are released as a reusable framework for differentiating other Earth system model components.
Thank you to arXiv for use of its open access interoperability. PaperDance 不是 arXiv 官方产品;中文卡片由大模型生成,请以原文为准。