← Latest papers
🤖 AI

Systematic LLM Translation of Legacy Scientific Code to Differentiable Frameworks: Application to a Land Surface Model

This paper presents a five-phase LLM-based agentic pipeline that successfully translates a 19,000-line legacy Fortran land surface model into a differentiable JAX framework, achieving significant performance gains in parameter recovery and computational speed while ensuring numerical parity through automated error correction and verification.

Original authors: Aya Lahlou, Linnia Hawkins, Pierre Gentine

Published 2026-06-09
📖 5 min read🧠 Deep dive

Original authors: Aya Lahlou, Linnia Hawkins, Pierre Gentine

Original paper licensed under CC BY 4.0 (http://creativecommons.org/licenses/by/4.0/). This is an AI-generated explanation of the paper below. It is not written or endorsed by the authors. For technical accuracy, refer to the original paper. Read full disclaimer

Imagine you have a massive, incredibly complex, and slightly dusty old library of instructions written in a forgotten language (Fortran). This library tells a computer exactly how to simulate the Earth's land surface—how plants breathe, how soil heats up, and how water moves. It's been running for decades, and it works perfectly, but it's "legacy" code: it's hard to read, hard to change, and it can't easily learn from new data.

The authors of this paper wanted to take this old library and translate it into a modern, super-smart language (JAX) that allows the computer to not just run the simulation, but to learn from it. They built a team of AI agents (digital workers) to do this translation automatically.

Here is how they did it, explained through simple analogies:

1. The Problem: The "Black Box" Library

The old code is like a giant, tangled ball of yarn. If you want to change one thread (a parameter), you have to pull the whole thing apart to see what happens. Also, the old code can't tell you why a result happened or how to tweak it to get a better result. It just gives you an answer.

2. The Solution: The "Five-Phase AI Construction Crew"

Instead of hiring a human to rewrite the whole thing (which would take years), the authors created a five-step automated pipeline using Large Language Models (LLMs). Think of this as a construction crew with specific roles:

  • Phase 1: The Architect (Dependency Analysis)
    Before building anything, the AI reads the entire blueprint to understand how the rooms connect. It figures out which parts of the code depend on which other parts. This ensures they translate the code in the right order (like building the foundation before the roof) so nothing gets lost.
  • Phase 2: The Project Manager (State Documentation)
    The AI creates a digital "logbook" (files like plan.md and CHANGELOG.md). If the AI gets stuck or makes a mistake, it writes it down. This acts as the crew's memory, so if the AI takes a break or restarts, it knows exactly where it left off and what went wrong last time.
  • Phase 3: The Quality Control Inspector (Fortran Oracle)
    This is the most critical step. The AI translates a small chunk of the old code into the new language. Then, it runs both the old version and the new version side-by-side with the exact same inputs. It checks: "Do the numbers match perfectly?" If the new code says "5.0" and the old code says "5.0001," the AI knows it made a mistake and has to fix it.
  • Phase 4: The Repair Loop (Iterative Translation)
    If the Quality Control Inspector finds a mismatch, the AI doesn't give up. It enters a "repair loop." It reads the error, guesses what went wrong, fixes the code, and tests it again. It does this over and over until the numbers match perfectly. The paper found that this AI crew could fix about 81% of its own mistakes without human help.
  • Phase 5: The Final Assembly & Stress Test (Integration & Differentiability)
    Once all the small chunks are translated and tested, the AI stitches them together into one big model. Then, it performs a special "stress test" to ensure the model can calculate gradients (slopes).
    • Analogy: Imagine driving a car. The old code could tell you where you are. The new code can tell you exactly which way to turn the steering wheel and how hard to press the gas to get to your destination faster. This is what "differentiable" means.

3. The Results: What Did They Achieve?

They applied this process to a 19,000-line land surface model (CLM-ml-v2). Here is what happened:

  • Perfect Translation: The new AI-translated model produced results that were mathematically identical to the old Fortran model. It wasn't an approximation; it was a perfect clone.
  • Super Speed: When they ran the model on a computer chip designed for AI (a GPU) with thousands of different scenarios at once, it was 24 times faster than the old code running on a standard processor.
  • Learning Speed: When they tried to tune the model to find the best settings (parameter estimation), the new model found the answer in 8 times fewer steps than the old methods. It's like finding a needle in a haystack by using a magnet instead of looking at every piece of hay one by one.

4. Why This Matters

The paper shows that we don't need to throw away our decades of scientific work to use modern AI. We can use AI to translate our old, trusted scientific code into a new format that is just as accurate but much faster and capable of learning.

The authors released their "construction crew" (the pipeline) and the translated model as open tools, hoping other scientists can use this same method to upgrade their own old scientific software.

In short: They built a robot team that read an old, dusty instruction manual, rewrote it into a modern language, double-checked every single word to ensure it was perfect, and proved that the new version works 24 times faster and can learn from data much better than the old one.

Drowning in papers in your field?

Get daily digests of the most novel papers matching your research keywords — with technical summaries, in your language.

Try Digest →