# Scientific Coding with Large Language Models: Evidence from Finite Element Analysis

Separate tester agents catch self-verification errors in LLM-written finite element code

Hamdi, Erfan, Shor, Joel, Lejeune, Emma · arXiv · 2026-11-16

- **Problem** LLM-written finite element code can run and look plausible while still computing the wrong result. Execution alone does not show that the numerics are correct.
- **Method** SimpleAgent lets an LLM run its code, read the output and revise it before submitting. A coder-tester setup splits the work so a separate tester agent writes tests and controls final submission.
- **Results** The coder-tester configuration reaches 97.6% Pass@3 and 88.8% Pass3, the highest scores the authors observed. Single-pass Pass3 was 68.8% for Astra and 79.4% for Fable.

## Why a running finite element solver can still be wrong

LLMs are increasingly used to write code for computational research, but a finite element solver can run cleanly and still be wrong. Finite element work ties together element formulations, material behavior, boundary conditions and solver algorithms, and every one of them has to agree. A program that executes and produces plausible output can still implement the wrong computation, so passing execution is not enough.

Verification has to separate harmless numerical discrepancies, such as those from discretization and rounding, from real implementation errors. That is why the study uses tasks with explicit mathematical requirements and independent numerical checks.

The authors ask two linked questions: whether LLMs can implement the specified computations, and whether they can write tests that separate correct code from incorrect code. The study builds on the earlier FEM-Bench work, which used introductory tasks in a single-pass setting. The 17 tasks here are harder, covering history-dependent elastoplastic updates, plate bending, 3D continuum mechanics and time-dependent structural response.

## Two tracks and how a success is counted

The implementation track asks each model for a Python function that matches a prescribed signature and requirements. Each generated function runs on predefined verification inputs, and its outputs are compared with those of a reference implementation. The test track asks for test functions, which count as successful only if they accept the reference and reject every designated Expected Failure case.

Function correctness is the fraction of trials whose implementation agrees with the reference on all verification inputs, averaged over the 17 tasks. Because each task has five trials, this measure is the same thing as an empirical Pass@1, and runs that never submit count as failures. Joint test success rate instead scores each test case, then averages the per-trial fractions, so a suite gets partial credit.

Pass@3 estimates the chance that at least one of three trials succeeds, using the unbiased estimator of Chen et al. over the five trials per task. Pass3 estimates the chance that all three of three trials succeed, so it rewards consistency rather than a single lucky run. A task with three successes in five trials gives 60% function correctness, 100% Pass@3 and 10% Pass3 in the authors' example.

## Single-pass results: strong code, weaker tests

Single-pass function correctness runs from 32.9% for DeepSeek V4 Flash 0731 to 87.1% for Claude Fable 5.1. GPT-6 Astra and Gemini 4 Argon each reach 82.4%, and Gemini 3.1 Pro Preview follows at 80.0%. These numbers show that several models produce working implementations for a substantial share of attempts without any execution feedback. Performance still varies by task, so the Delaunay circular-mesh task is solved in all five trials by 14 of the 15 models.

The Specht shape-function task is different, with only four successes across 75 trials. Those four successes come from Claude Fable 5.1 and Gemini 4 Argon, two each.

The test-generation track gives a different ranking. Joint test success ranges from 34.7% for Gemma 4 31B to 82.6% for GPT-6 Astra. GPT-5.6 Sol reaches 76.5% and GPT-5.6 Luna reaches 74.3% in the same track. Claude Fable 5.1 leads the implementation track but reaches only 49.9% joint test success. GPT-5.6 Luna gets 54.1% function correctness yet ranks third in test generation.

Stronger code, then, doesn't guarantee stronger tests that separate correct from incorrect implementations.

Joint test success averages the per-trial fraction of passing test cases, which gives partial credit when only some tests succeed. Function correctness, by contrast, equals empirical Pass@1 for each task averaged over tasks.

## How SimpleAgent and OpenHands run

Agentic harnesses let the model run code, read the output and revise its implementation before it submits. SimpleAgent gives the model two actions, Python execution and submission, and nothing else. Each Python execution runs in a fresh sandbox preloaded with the task's required imports and supplied helper functions. Execution is stateless, so variables and files from one run aren't available in later runs.

The model still keeps the conversation history, including earlier actions, execution output and exit codes. Submission is only accepted after at least one execution, and only when the latest execution returned exit code 0. A rejected submission returns feedback that explains the unmet requirement, so the model can keep working.

![Figure 1: Overview of agentic harnesses studied.(a) Overview of SimpleAgent. SimpleAgent follows a ReAct-style loop with two actions: Python execution (test) a…](https://refivu.com/papers/fbc5e96e-993c-477a-b7cc-7e022fd35897/figures/figure-23e579889b8df76fb115046c8cd7a188.png?thumb=512)

**Figure 1** :Overview of agentic harnesses studied.(a) Overview of SimpleAgent. SimpleAgent follows a ReAct-style loop with two actions: Python execution (test) and submission (submit). The Python execution action runs code in a fresh sandbox preloaded with the task’s required imports and helper functions. Execution is stateless: variables and files do not persist between executions, while the LLM retains the conversation history and receives execution output and exit codes as observations. Submission is permitted only after at least one execution and only if the most recent execution returned exit code 0. (b) Overview of the OpenHands coding agent. OpenHands is an open-source framework for coding agents. In this study, the agent had access to tools for web browsing, terminal execution, file editing, task tracking, planning, delegation to subagents, and a finish action to end the session. The agent ran inside a Singularity container configured to isolate it from the local reference implementations while retaining internet access.

[Original paper](https://arxiv.org/abs/2611.21176v1) · [CC BY 4.0](https://creativecommons.org/licenses/by/4.0/) · Hamdi, Erfan, Shor, Joel, Lejeune, Emma · Scientific Coding with Large Language Models: Evidence from Finite Element Analysis · Original paper figure · Extracted the figure area from page 8 of the original PDF.

OpenHands is an open-source coding-agent framework, and the authors gave it a wider toolset than SimpleAgent. Files persisted in the workspace across iterations, so the agent could build on earlier implementations and tests. The agent wrote its final code to submission.py and ended the session with the finish action. The authors ran OpenHands in a Singularity container that hides the local reference implementations but keeps internet access.

Both harnesses share the same per-trial limits, which keeps the comparison between them fair. Each trial gets a total token budget of 2,000,000 and at most 200 iterations. A trial also has a wall-time limit of two hours, and each model response is capped at 30,000 output tokens. Appendix C lists the further operational limits, which the authors don't repeat in the main text.

## Agentic gains and the regressions they bring

Execution and revision raise the odds of success for some models, but the gains are uneven across harnesses. For Claude Opus 5, Pass@3 rises from 90.6% in single-pass generation to 96.5% with SimpleAgent. Its Pass3 rises from 65.9% to 77.1% over the same comparison, which is the more demanding consistency measure. Across all model-harness combinations, no Pass3 exceeds 78.8%.

Most gains come from tasks that already had some successful single-pass trials. OpenHands improves reliability on 22 and newly solves nine in the same count of combinations. Execution and revision can also let a model solve a task where no single-pass attempt succeeded. DeepSeek V4 Flash 0731 moves from 32.9% to 65.9% function correctness with SimpleAgent, compared with 44.7% under OpenHands.

The gains come with regressions, and SimpleAgent loses one model-task combination while degrading reliability on 11. OpenHands loses five combinations and degrades 13, which is a larger regression count than SimpleAgent shows. Some losses come from budget exhaustion, since Kimi K3 hit the token budget on all five OpenHands trials for the cohesive-zone T2 task.

Nine of 510 SimpleAgent trials and 83 of 510 OpenHands trials ended at a token or wall-time limit without an evaluated submission.

Budget exhaustion doesn't explain every loss. That drop isn't a budget failure, because all five runs completed and submitted implementations for evaluation. Both failure types add zero successes to the reported metrics, so the metrics don't separate them.

## Splitting coder and tester roles

The coder-tester extension splits SimpleAgent into two agents that keep separate conversation histories. The coder develops the requested function, and the tester evaluates candidates and controls final submission. The design was motivated by the self-verification error analysis, and AgentCoder separates code generation from test design in a similar way.

The tester builds pytest tests from the task specification and runs them against the compiled candidate.

The tester keeps its test suite across iterations and reruns it against each new candidate. It can add tests, or rewrite and remove tests from earlier iterations. The tester sends written feedback to the coder, along with only the names of failing tests. Only the tester can approve final submission, which prevents further coder modifications.

The tester acts as an approximate external oracle, because it writes tests with expected outcomes without seeing the coder's history or source. Requiring the tester's approval means a candidate must pass these checks before it is submitted. With Fable as coder and Astra as tester, the scores are 91.8% Pass@3 and 84.7% Pass3.

## Coder-tester scores and one trajectory

The coder-tester configuration reaches 97.6% Pass@3 and 88.8% Pass3, the highest scores among the configurations the authors evaluated. Single-pass Pass3 was 68.8% for Astra and 79.4% for Fable, so the separated design raises consistency above either model alone. Reversing the roles still helps, with Fable as coder and Astra as tester reaching 91.8% Pass@3 and 84.7% Pass3.

Every one of the 170 coder-tester trials produced a submission, and none stopped at a resource limit.

The tester acts as an approximate external oracle, since it writes tests from the task specification without seeing the coder's history or source. Its feedback gives the coder new evidence, and the retained test suite checks that later candidates fix earlier failures. Astra then found failures under additional loading and mesh configurations.

A later test exposed a rigid-translation violation, which Fable traced to an incorrect shape-function derivative. Fable corrected the derivative in the third candidate, and that final implementation passed all 27 accumulated tester checks.

The authors read this as evidence that a separate tester can catch numerical errors that the coder's own checks miss.

## How failed trajectories were labelled

The labelling started from 249 completed trials whose submitted implementations failed the benchmark evaluation, 146 from SimpleAgent and 103 from OpenHands. The authors first built the codebook by reviewing more than 20 failed trajectories by hand. Pilot judgments by LLMs then exposed category boundaries that the definitions didn't capture well, and the authors refined the definitions and examples after each round.

An OTHER category let judges flag a verification failure outside the existing categories, so the authors could review those cases and revise the codebook.

The label NV marks trajectories with no observable verification, and it cannot co-occur with the six verification categories. A trajectory can receive several codes, but only when each code captures a distinct, supported deficiency. Judges look at subsequent corrections and skip any intermediate flaw that was fixed before submission. Fleiss' κ served as the agreement criterion for deciding when to stop refining the codebook.

The authors leave out raw evaluator output values and model metadata when they prepare the package. GPT-6.1 Sol, Claude Opus 5.5 and Grok 4.7 each assess every package independently with the same codebook.

The authors compared the full label sets from the three judges, and a case kept its shared label set when all three matched. Of the 249 cases, 104 had unanimous label sets, and the other 145 went to adjudication. Astra could retain, remove or add labels, even labels that no initial judge gave. The instructions barred majority voting and deference to any single judge, and Astra's classification became the final label for each adjudicated case.

## What the failed submissions got wrong

Generic Consistency Checks follows closely, assigned to 175 cases (70.3%) across the same failed runs. The two categories co-occur in 137 cases (55.0%), and they appear for all six models and both harnesses. Figure 7 shows the same pattern across models, with these two categories leading in the counts for each model. Inadequate coverage concerns what goes untested, while generic checks concern how little a passing result proves.

Test Accommodation appeared in 30 cases (12.0%), where the agent changed the test or its interpretation rather than the implementation. Unverified Post-Test Modification appeared in 15 cases (6.0%), where the agent edited code after testing and submitted it without rechecking.

Passing the agent's own tests doesn't confirm correctness, because a test suite can pass while the solver still fails. The authors argue that a verifier outside the coder's process must test relevant conditions and use independently justified expected results. That verifier also needs meaningful numerical tolerances and must keep valid tests when they expose a discrepancy.

The coder-tester trajectory in Section 5.2.1 illustrates this corrective role. Model rankings also differed between implementation and test generation, so stronger coding didn't imply stronger testing.

## Limits of the evidence

The coder-tester result rests on one model pairing, Claude Fable 5.1 with GPT-6 Astra, tested in both role assignments. The paper evaluates the coder-tester configuration with only this one pairing, so it can't show how the design performs with other models. Only six of the 15 models were run in the agentic settings, so the harness comparison doesn't cover the whole model set.

Nine of 510 SimpleAgent trials and 83 of 510 OpenHands trials ended at a token or wall-time limit without an evaluated submission. Those 94 excluded trials are left out of the failure analysis, so it covers only the completed failed submissions. Each task has only five trials, so the Pass3 value for a single task rests on a small sample.

The failure labels come from LLM judges applying a codebook, so they describe the judges' reading of each trajectory. Three initial judges disagreed on 145 of the 249 cases, which sent those cases to GPT-6 Astra for adjudication. The paper doesn't test the labels against human coders, so their agreement with human reading remains open.

## Paper info

- **Authors**: Hamdi, Erfan, Shor, Joel, Lejeune, Emma
- **Venue**: arXiv · Preprint
- **First published**: 2026-11-16
- **Added**: 2026-11-17
- **Updated**: 2026-11-16
- **Version**: v1
- **arXiv**: 2611.21176
- **Category**: cs.SE · cs.AI · cs.CE
- **Original paper terms**: [CC BY 4.0](https://creativecommons.org/licenses/by/4.0/)
- **What we show**: Paper info, commentary and permitted figures from the original paper

[Original paper ↗](https://arxiv.org/abs/2611.21176v1) · [PDF ↗](https://arxiv.org/pdf/2611.21176v1)

AI commentary is a separate explanation from the original paper and may contain errors. The original paper and figures follow each source's terms of use and any rights noted separately.

## Abstract

Large language models (LLMs) offer a potential route to automating scientific programming, but their usefulness depends on consistently producing numerically correct code. We extend FEM-Bench to 17 finite element tasks involving nonlinear and history-dependent mechanics and structural dynamics, and evaluate 15 models on implementation and test generation without execution feedback. The best model succeeds in 87.1% of single-pass implementation trials, but rankings differ between tracks. The leading implementer achieves 49.9% joint test success, while the leading tester reaches 82.6%. For six models, we compare single-pass generation with two agentic harnesses that allow code execution and revision. Agentic execution solves some tasks that never succeeded in single-pass trials and improves consistency on others, but gains vary across models and harnesses, and regressions also occur. Claude Opus 5 with SimpleAgent reaches 96.5% Pass@3, the probability of at least one success in three attempts, but 77.1% Pass$^3$, the probability that all three succeed. No model-harness combination exceeds 78.8% Pass$^3$. To understand why agents submit incorrect code after passing their own checks, we analyze 249 failed agentic trajectories and identify six categories of self-verification failure. The most common are inadequate test coverage (73.1%) and reliance on generic consistency checks (70.3%), and in 28.5% of cases the tests share an error with the implementation. Motivated by these findings, an exploratory configuration with separate coder and tester agents achieves the highest observed scores, with 97.6% Pass@3 and 88.8% Pass$^3$. These results identify consistency across attempts and independent verification as the main obstacles to trusting LLM-generated scientific code.

## Quote from the paper

Hamdi, Erfan, Shor, Joel, Lejeune, Emma (2026). Scientific Coding with Large Language Models: Evidence from Finite Element Analysis. arXiv:2611.21176v1. https://arxiv.org/abs/2611.21176v1

**BibTeX**

```
@misc{erfan2026scientific,
  title = {{Scientific Coding with Large Language Models: Evidence from Finite Element Analysis}},
  author = {Hamdi, Erfan and Shor, Joel and Lejeune, Emma},
  year = {2026},
  eprint = {2611.21176},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/2611.21176v1}
}
```

## Other paper commentary

- [PixelBench: Evaluating Language Models for Pixel-Art Creation](https://refivu.com/en/papers/90b0ce48-ae85-4822-b357-e4c1682fdbdd-pixelbench-evaluating-language-models-for-pixel-art-creation.md)
- [Instant Weight-Space Consolidation for Long-Term Memory in LLMs](https://refivu.com/en/papers/d7e910e4-bc6c-4c84-b5c0-2c8df4c15f81-instant-weight-space-consolidation-for-long-term-memory.md)
- [A First Look at System One Decision Models for Malware Detection](https://refivu.com/en/papers/d7188362-7fe4-49a4-b9d4-ee9f2814aa06-a-first-look-at-system-one-decision-models.md)
- [Benchmarking LLM Inference on Desktop-Scale NVIDIA Grace Blackwell Clusters](https://refivu.com/en/papers/bd9d6d1b-ae00-44bf-a5aa-580cfc265437-benchmarking-llm-inference-on-desktop-scale-nvidia-grace.md)
- [When the Cheapest Feasible Router Fails: Auditing Deployment Commitments in Cost-Aware LLM Routing](https://refivu.com/en/papers/d992d0b2-38b5-446b-9139-ac49d02c18fb-when-the-cheapest-feasible-router-fails-auditing-deployment.md)
- [Fast at the Frontier, Wrong at the Fallback: A Commit-Level Analysis of Threshold Decoding in Diffusion Language Models](https://refivu.com/en/papers/ee708681-d281-4f0d-af44-191c6b588143-fast-at-the-frontier-wrong-at-the-fallback.md)
- [EchoSpec: Training Search Agents to Weigh Evidence Above Echoes](https://refivu.com/en/papers/22f39cf0-d41a-4695-8d6b-0d26df622012-echospec-training-search-agents-to-weigh-evidence-above.md)
- [VIVID: A Visual Harness for Agentic Video Editing](https://refivu.com/en/papers/2e7fc25b-04e2-4f48-ad44-5f5675ff1f53-vivid-a-visual-harness-for-agentic-video-editing.md)
- [UniGraph: A Unified Graph-based Index for Dynamic Hybrid Dense-Sparse Vector Retrieval](https://refivu.com/en/papers/a5ee1bb8-7883-49ee-91f4-322d407f8039-unigraph-a-unified-graph-based-index-for-dynamic.md)
- [ReRead: Wrong Predictions, Useful Representations - Correcting Frozen Robot Policies by Re-reading Their Own Representations](https://refivu.com/en/papers/8296ea66-ea3c-4b5e-a10d-c73916f082a8-reread-wrong-predictions-useful-representations-correcting.md)
- [DexFormer 2.0: Towards a Cross-Embodiment Foundation Policy for Dexterous Grasping](https://refivu.com/en/papers/198188b6-2d22-44da-9ba3-93ce7566fc83-dexformer-2-0-towards-a-cross-embodiment-foundation.md)

## Terms in this paper

- [Large Language Models](https://refivu.com/en/terms/f2404476b183-large-language-models)
- [GPT-6 Astra](https://refivu.com/en/terms/b41650762174-gpt-6-astra)
- [OpenHands](https://refivu.com/en/terms/0368eb006bfb-openhands)
- [Fleiss’ κ](https://refivu.com/en/terms/69af20f74138-fleiss)

---

AI-written text can contain mistakes. [Refivu](https://refivu.com/en/papers/fbc5e96e-993c-477a-b7cc-7e022fd35897-scientific-coding-with-large-language-models-evidence-from)
