Manuscript Offprint

arXiv:2610.03631

NeutronGym: Physics-Graded Neutron Instrument Design for LLM Agents

Lijie Ding, Changwoo Do

ABSTRACT

Designing a scientific instrument tests whether language-model agents can do physics rather than recall it, provided the grading cannot be argued with. We introduce NeutronGym, to our knowledge the first executable environment for neutron instrument design: agents build instruments through validating tools, McStas raytraces what they build, and a level-resolved ladder grades syntax, runtime, structure and science with no LLM judge. Procedural families supply unlimited instances of a fixed layout whose design parameters the agent must set, with held-out parameter regimes; a curated slice, McStasBench, adds 16 tasks from published instruments behind memorization probes and a sandbox. Seven models reproduce at most 7 of the 16, none retrieves a reference, and none meets an improvement target. The environment also trains. Reinforcement learning on its reward takes Qwen3-8B from 11% to 77% of held-out instances of a family whose targets come from a hidden design (69% at a second seed), past an untrained Qwen3-32B, and the recipe holds, at one seed each, on three further gated families. The analysis says what that gain is. Without the ladder's partial credit it collapses by 60 points. From reward alone the trained model reaches what a classical optimizer reaches, at the agent's simulation budget, only when handed the closed-form physics (77% against 81%, a gap that does not separate at this size), while frontier models still solve 98–99%. Getting a trustworthy result meant failing four task designs that no-model baselines could solve, and we release the probes that found them.

1 INTRODUCTION

Designing a scientific instrument asks more of an agent than writing code that runs: it must turn a specification into a physical layout, trade competing constraints against each other, and produce a design whose quality is measured by physics rather than by agreement with a reference answer. Neutron scattering instruments are an unusually clean substrate for this. They are designed in simulation long before construction, the community-standard simulator McStas (Lefmann & Nielsen, 1999; Willendrup & Lefmann, 2020) describes an instrument as a text file of components, a Monte Carlo ray trace returns quantitative observables (intensity, divergence, wavelength distribution) in seconds, and passive neutron optics obey a conservation law that gives the deliverable intensity a computable ceiling needing no reference answer.

Turning such a simulator into an evaluation and training substrate raises three problems that are easy to underestimate. Grading: any scalar reward on a simulator can be satisfied in unintended ways; we found nine such failures in our own reward and task generator ( §5.1§5.1). Contamination: many published instruments ship as example files with the simulator, so a model may reproduce a design it has read rather than reasoned about; in a pilot audit, 4 of 7 agent episodes retrieved the reference file through ordinary, permitted tools. Degeneracy: a generated family can look discriminating while admitting one fixed answer, or one rule that copies numbers from the prompt, that solves most instances, so its pass rates measure lookup rather than design; we learned this twice ( §5.2§5.2).

We introduce NeutronGym, an executable, physically verifiable environment for LLM agents designing neutron instruments ( §3§3). Agents act only through 22 validating tools exposed over the Model Context Protocol (Anthropic, 2024); the environment simulates what they build and grades it on a level-resolved ladder (L1 syntax, L2 runtime, L3 structure, L4 science) with no LLM judge.

Procedural families supply unlimited design instances with calibrated targets and disjoint held-out parameter regimes; its curated slice, McStasBench ( §4§4), adds reproduction and improvement tasks built from published instruments, 16 scored per model and arm, behind memorization probes, perturbed variants and two never-public held-out instruments. Every scored task fixes the instrument's layout: the benchmark asks for a published layout rebuilt from its specification, the families for the numeric parameters of a fixed layout, and no scored tier asks for a topology choice (the open-design tier is unscored).

The paper follows what happened when we used it. On the benchmark, real instruments can be reproduced from their specifications, but not reliably: the best model, Claude Sonnet 5, rebuilt 7 of the 16 tasks in a single completion and 5 through the tool loop, no episode retrieved a reference, and no agent met an improvement target ( §4.2§4.2); the open-weights Qwen models (Yang et al., 2025) produced no parseable instrument at all without the tools. Training changed that picture. Reinforcement learning on the environment's reward took Qwen3-8B from 11.3% to 76.7% of held-out instances on a family whose targets come from a hidden design, past an untrained 32B that is no stronger than the 8B there, and the same recipe, at a single seed each, did so on three further gated families ( §5.2§5.2). The analysis then asks what that gain is. Removing the ladder's partial credit costs 60 points; at the agent's simulation budget a classical optimizer matches the trained model only when handed the closed-form physics, which the model recovered from reward alone; and frontier models still solve nearly every instance ( §5.3§5.3). Getting a trustworthy version of that result was the hard part: supervised fine-tuning on the model's own successes degraded it three times, and four task designs failed the gate because a no-model baseline solved them with a fixed answer, a rule copying limits from the prompt, or a whole class of designs ( §5.1§5.1).

References (59)