Table of Contents
Fetching ...

Automated Code Development for PDE Solvers Using Large Language Models

Haoyang Wu, Xinxin Zhang, Lailai Zhu

TL;DR

This work tackles automated code development for PDE solvers by introducing LLM-PDEveloper, a zero-shot, multi-agent framework that translates mathematical descriptions into new solver and boundary-condition modules, thereby self-augmenting a PDE library. The approach uses four LLM agents (Generator, Inspector 1, Inspector 2, Debugger) plus two non-LLM checkers (Checker, Packer) under LangGraph orchestration to iteratively generate, test, and merge code, demonstrated on the XLB lattice Boltzmann library with three tasks: new solver, new BCs, and modification to add extra terms. Results across three LLMs show moderate success, with syntactic errors largely mitigated by rule-based guidance, while semantic errors—misinterpretation of PDEs, weak spatial awareness, and spurious programs—remain challenging. The study highlights actionable fixes for syntactic issues and emphasizes the need for improved semantic reliability and validation in fully automated PDE software development, offering a roadmap for future research toward trustworthy math-to-code PDE systems.

Abstract

Foundation models -- large language models (LLMs) in particular -- have become ubiquitous, shaping daily life and driving breakthroughs across science, engineering, and technology. Harnessing their broad cross-domain knowledge, text-processing, and reasoning abilities for software development, e.g., numerical libraries for solving partial differential equations (PDEs), is therefore attracting growing interest. Yet existing studies mainly automate case setup and execution for end users. We introduce LLM-PDEveloper, a zero-shot, multi-agent LLM framework that automates code development for PDE libraries, specifically targeting secondary developers. By translating mathematical and algorithmic descriptions directly into source code, LLM-PDEveloper generates new solvers/modules and adapts existing ones. This end-to-end math-to-code approach enables a self-augmenting pipeline that continuously expands the codebase of a library, extends its capacities, and broadens its scope. We demonstrate LLM-PDEveloper on three tasks: 1) build a solver for a new PDE, 2) implement new BCs for a given PDE, and 3) modify an existing solver to incorporate additional terms, achieving moderate success rates. Failures due to syntactic errors made by LLMs are analyzed and we propose effective fixes. We also identify the mechanisms underlying certain semantic errors, guiding future research.

Automated Code Development for PDE Solvers Using Large Language Models

TL;DR

This work tackles automated code development for PDE solvers by introducing LLM-PDEveloper, a zero-shot, multi-agent framework that translates mathematical descriptions into new solver and boundary-condition modules, thereby self-augmenting a PDE library. The approach uses four LLM agents (Generator, Inspector 1, Inspector 2, Debugger) plus two non-LLM checkers (Checker, Packer) under LangGraph orchestration to iteratively generate, test, and merge code, demonstrated on the XLB lattice Boltzmann library with three tasks: new solver, new BCs, and modification to add extra terms. Results across three LLMs show moderate success, with syntactic errors largely mitigated by rule-based guidance, while semantic errors—misinterpretation of PDEs, weak spatial awareness, and spurious programs—remain challenging. The study highlights actionable fixes for syntactic issues and emphasizes the need for improved semantic reliability and validation in fully automated PDE software development, offering a roadmap for future research toward trustworthy math-to-code PDE systems.

Abstract

Foundation models -- large language models (LLMs) in particular -- have become ubiquitous, shaping daily life and driving breakthroughs across science, engineering, and technology. Harnessing their broad cross-domain knowledge, text-processing, and reasoning abilities for software development, e.g., numerical libraries for solving partial differential equations (PDEs), is therefore attracting growing interest. Yet existing studies mainly automate case setup and execution for end users. We introduce LLM-PDEveloper, a zero-shot, multi-agent LLM framework that automates code development for PDE libraries, specifically targeting secondary developers. By translating mathematical and algorithmic descriptions directly into source code, LLM-PDEveloper generates new solvers/modules and adapts existing ones. This end-to-end math-to-code approach enables a self-augmenting pipeline that continuously expands the codebase of a library, extends its capacities, and broadens its scope. We demonstrate LLM-PDEveloper on three tasks: 1) build a solver for a new PDE, 2) implement new BCs for a given PDE, and 3) modify an existing solver to incorporate additional terms, achieving moderate success rates. Failures due to syntactic errors made by LLMs are analyzed and we propose effective fixes. We also identify the mechanisms underlying certain semantic errors, guiding future research.

Paper Structure

This paper contains 21 sections, 6 equations, 7 figures, 2 tables.

Figures (7)

  • Figure 1: Workflow of LLM-PDEveloper as detailed in the main text, where 'Math-Algo descriptions' means mathematical and algorithmic descriptions.
  • Figure 2: Experiment on code generation for implementing new BCs of the AD equation: Dirichlet BC at the top and left boundaries, and homogeneous Neumann BC at the remaining ones.
  • Figure 3: Test case for the generated NN solver: lid-driven cavity flow of power-law fluids. Here, the velocity $\mathbf{u} = (1.0, 0.0)$ on the top boundary, and $\mathbf{u} = (0.0, 0.0)$ on the remaining ones.
  • Figure 4: LLM-PDEveloper misinterprets the AD equation for the scalar field $\phi$ by omitting the advection term. (a) Initial Gaussian distribution of $\phi$ at $t=0$. At $t=500$, the reference solution (b) shows the Gaussian peak advected downstream, whereas the peak remains stationary in the erroneous result (c) generated by LLM-PDEveloper.
  • Figure 5: Code snippet of the Tester "test_case.py" generated by the Debugger. The agent intentionally omits the streaming step---responsible for convection---as signaled by its comment 'collision step; streaming is not used for pure ADE'.
  • ...and 2 more figures