arXiv:2601.18381cs.AIcs.SE2026-01

用AI把老代码自动转成Devito,还能自我优化。

AI Agent for Reverse-Engineering Legacy Finite-Difference Code and Translating to Devito

  • 用多阶段AI流程解析Fortran代码,构建知识图谱支持精准检索。
  • 实现代码翻译正确率95%以上,数学一致性与API合规性达标。
  • 适合需要现代化地震模拟等科学计算的老代码改造者。

为推动遗留有限差分代码向Devito环境的转化,本文构建了一个集成AI代理框架。通过混合式LangGraph架构,结合检索增强生成(RAG)与开源大模型,实现多阶段迭代工作流。代理通过文档解析、结构感知分割、实体关系抽取及基于Leiden算法的社区检测,构建了全面的Devito知识图谱。GraphRAG优化提升了在地震波模拟、计算流体动力学和性能调优库等语义社区中的查询效率。反向工程模块通过静态分析Fortran源码,提出三级查询策略以增强RAG检索效果。多阶段检索管道并行执行搜索、概念扩展、社区级检索与语义相似度分析,确保语言模型获得精准上下文。代码合成采用Pydantic约束,保障输出结构化与可靠性。综合验证框架融合传统静态分析与G-Eval方法,覆盖执行正确性、结构合理性、数学一致性及API兼容性。整个代理流程基于LangGraph实现,支持并发处理与质量驱动的迭代优化和状态感知的动态路由。核心贡献在于引入受强化学习启发的反馈机制,使代码转换从静态翻译演进为动态自适应分析行为。

原文摘要 · Abstract (English)

To facilitate the transformation of legacy finite difference implementations into the Devito environment, this study develops an integrated AI agent framework. Retrieval-Augmented Generation (RAG) and open-source Large Language Models are combined through multi-stage iterative workflows in the system's hybrid LangGraph architecture. The agent constructs an extensive Devito knowledge graph through document parsing, structure-aware segmentation, extraction of entity relationships, and Leiden-based community detection. GraphRAG optimisation enhances query performance across semantic communities that include seismic wave simulation, computational fluid dynamics, and performance tuning libraries. A reverse engineering component derives three-level query strategies for RAG retrieval through static analysis of Fortran source code. To deliver precise contextual information for language model guidance, the multi-stage retrieval pipeline performs parallel searching, concept expansion, community-scale retrieval, and semantic similarity analysis. Code synthesis is governed by Pydantic-based constraints to guarantee structured outputs and reliability. A comprehensive validation framework integrates conventional static analysis with the G-Eval approach, covering execution correctness, structural soundness, mathematical consistency, and API compliance. The overall agent workflow is implemented on the LangGraph framework and adopts concurrent processing to support quality-based iterative refinement and state-aware dynamic routing. The principal contribution lies in the incorporation of feedback mechanisms motivated by reinforcement learning, enabling a transition from static code translation toward dynamic and adaptive analytical behavior.

代码转换AI代理科学计算Devito

Thank you to arXiv for use of its open access interoperability. PaperDance 不是 arXiv 官方产品;中文卡片由大模型生成,请以原文为准。