PhysAgentGym: Physical-Law Verifiers for Training Small Code-Reasoning Agents
Abstract
Code-reasoning agents trained from rollouts rely on verifiers, such as expert an- notation, hand-written unit tests, or learned reward models, each of which needs human effort for every new domain. However, in domains governed by closed- form physical laws, whether the laws themselves can serve as automatic verifiers remains unclear. We propose PhysAgentGym, an agentic code-execution gym for classical mechanics of point masses, in which a language model writes a Python program that simulates a physics scenario and a rule-based verifier com- piles natural-language standards into checks on the emitted trajectory. The scores are annotation-free, since physical laws supply the ground truth and neither the agent nor the verifier reads the exact solution, and an audit against these withheld solutions shows that every highly scored test trajectory from Claude Sonnet 4.5, Claude Opus 4.8, GPT-5, and our trained 7B model matches its exact solution. Fine-tuning Qwen2.5-Coder on Claude Sonnet 4.5 rollouts selected by the verifier brings the 7B model statistically on par with Sonnet 4.5 and GPT-5. It matches Sonnet 4.5 on held-out Circular Motion and comes close on held-out Damping, a phenomenon absent from training. Frontier models already reach the highest score the verifier gives in practice, but on harder composite tasks with drag, orbits, and driven and coupled oscillators, where the exact solution earns nearly the full score, the verifier separates correct from wrong physics and Claude Opus 4.8 scores measurably above Sonnet 4.5.