Code as Worlds: Agentic Discovery of Executable World Representations for Physical Reasoning

Hanyang Wang, Yimo Cai, Weiliang Chen, Jiawei Chi, Haowen Sun, Qiyu Dai, Yi-Hsin Hung, Xingzhuo Guo, Jinshan Ren, Runmao Yao, Ziwei Liu, Mingsheng Long, Yueqi Duan, Jun Gao, Jiangran Lyu, Fangfu Liu, Jialong WuarXiv 2026

TL;DR

The Code-as-World paradigm represents physical environments as structured, executable code that defines their composition, dynamics, and appearance. By using an agentic, simulation-in-the-loop discovery process, the framework automatically extracts these code representations from text or video and uses them to generate high-fidelity physical supervision. This approach allows relatively small vision-language models (VLMs) to outperform massive proprietary models on quantitative physical reasoning tasks.

What Problem Does This Paper Address?

While modern vision-language models (VLMs) excel at describing what happens in a video (e.g., "a ball rolls down a ramp"), they struggle with quantitative physical reasoning—such as estimating an object's exact velocity, mass, or future trajectory.

The authors identify a fundamental phenomenon–mechanism dichotomy: current models learn surface-level visual patterns (phenomena) but lack explicit representations of the underlying causal factors (mechanisms). Traditional representations fall short:

  • Pixels (video generation) are visually plausible but physically ambiguous.
  • 3D Reconstructions capture geometry but ignore forces and dynamics.
  • Natural Language provides semantic abstractions but lacks continuous, quantitative precision.
Comparison of different physical world representations.

Methods

The paper introduces Code-as-World, which formalizes an Executable World Representation (EWR) as a tuple of three components: $p = (C, E, A)$.

  1. Physical Composition ($C$): Objects, geometry, metric dimensions, mass, and friction.
  2. Dynamic Evolution ($E$): Initial states, forces, and trajectories over time.
  3. Visual Appearance ($A$): Camera parameters, lighting, and textures.

To bridge the gap between raw observations and this structured code, the authors develop an Agentic Discovery Loop inspired by abductive reasoning. Given text or video evidence, an LLM agent proposes an initial EWR hypothesis, compiles and executes it inside a physics simulator (MuJoCo), renders the predicted visual/depth outputs, and verifies them against the original input. Discrepancies are fed back to the agent as structured debugging text, allowing it to iteratively refine the code over multiple rounds.

The propose-instantiate-execute-render-verify loop for agentic discovery.

Once verified, these EWRs provide exact, pixel-aligned ground truth labels for world-space metrics. The authors then train a family of models (Code-as-World-VL) using a two-phase curriculum:

  • Phase 1 (Image-Space Grounding): Supervised fine-tuning on bounding boxes, tracks, and pixel-level velocities.
  • Phase 2 (World-Space Calibration): Reinforcement learning via Group Relative Policy Optimization (GRPO) using exact physical metrics derived from the verified EWRs.

Datasets

The models are trained and evaluated using a mix of existing visual grounding datasets and a newly synthesized dataset:

  • Image-Space Grounding: RefCOCO, RefCOCO+, RefCOCOg, RefCLEF, and GOT-10K (converted into 73,335 quantitative question-answer pairs in pixel space).
  • World-Space Executable-World Dataset (New): 1,585 text-driven and 988 video-driven samples containing synchronized videos, physical states, and exact world-space VQA labels.
  • Evaluation Benchmark: The open-source QuantiPhy validation set, consisting of 159 quantitative question-answer pairs split across four kinematic categories: 2D Static (2S), 2D Dynamic (2D), 3D Static (3S), and 3D Dynamic (3D).

Key Insights and Ideas

  • Code as a Testable Hypothesis: Code serves as an ideal medium for physical intelligence because it is highly compositional, editable, and—crucially—executable. This allows an agent to treat a world model as a hypothesis that can be verified or falsified by a simulator.
  • Decoupling Physics from Rendering: By separating the physical simulation ($C, E$) from visual appearance ($A$), the framework can perform precise counterfactual modifications (e.g., changing an object's mass or initial velocity) and use video diffusion models (like Wan2.2-VACE) to render realistic, physically consistent variations for training data augmentation.
  • Search Beats One-Shot Prediction: Iterative refinement through the agentic loop consistently outperforms one-shot code generation or random sampling (Best-of-5), proving that symbolic feedback from a physics engine provides a strong optimization signal.
Performance improvements across successive agentic discovery loop rounds.

Key Results

The Code-as-World-VL models achieve state-of-the-art performance on the QuantiPhy benchmark, measured by Mean Relative Accuracy (MRA):

  • Outperforming Proprietary Giants: The Code-as-World-VL-9B model achieves an average MRA of 55.4%, surpassing much larger proprietary models like Gemini-3.1-Flash (54.8%) and ChatGPT-5.1 (48.4%).
  • Scaling to Reasoning Models: The Code-as-World-VL-27B (Reasoning) variant, which generates a chain-of-thought trace before outputting its final answer, achieves the highest overall score of 58.6%.
  • Data Synergy: Ablation studies show that combining both text-driven (numerically exact physics) and video-driven (visually realistic distributions) executable worlds yields the best generalization performance.

Limitations and Future Work

  • Scope of Physics Engines: The current implementation is heavily focused on rigid-body dynamics. It does not yet support complex real-world phenomena like fluids, gas dynamics, cloth deformation, or fracture mechanics.
  • Externalized Discovery Loop: While Code-as-World-VL learns from the outputs of the agentic discovery loop, the model itself does not internalize the discovery process. It cannot run its own internal propose-verify simulation loop at inference time. Integrating this loop directly into the model's native architecture remains an open challenge.

Summary updated

BibTeX
@misc{wang2026code,
  author = {Hanyang Wang and Yimo Cai and Weiliang Chen and Jiawei Chi and Haowen Sun and Qiyu Dai and Yi-Hsin Hung and Xingzhuo Guo and Jinshan Ren and Runmao Yao and Ziwei Liu and Mingsheng Long and Yueqi Duan and Jun Gao and Jiangran Lyu and Fangfu Liu and Jialong Wu},
  title = {{Code as Worlds: Agentic Discovery of Executable World Representations for Physical Reasoning}},
  year = {2026},
  eprint = {2608.27549},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/2608.27549},
}
Figure