Part V: Discovery Through Simulation and Optimization
Chapter 44: World Models for Discovery

World Models for Discovery

"I dreamed I was a five-step rollout, and when I woke up I had accumulated so much compound error that I could no longer tell if I was a model or reality."

A Recurrent State-Space Model Having an Identity Crisis

Overview

A physicist simulating a plasma instability on a supercomputer waits three days for a single trajectory. A chemist screening reaction conditions runs hundreds of wet-lab experiments to map a yield surface. In both cases, the bottleneck is the same: the real environment (or its faithful numerical simulator) is too expensive to query at the scale that modern optimization and planning algorithms demand. World models offer an escape. They are learned approximations of environment dynamics that trade a small amount of accuracy for orders-of-magnitude speedup, letting an agent "imagine" thousands of future trajectories before committing to a single real action.

This chapter builds world models from the ground up. We start with latent dynamics models, in particular the Recurrent State-Space Model (RSSM) architecture behind DreamerV3, and derive the Evidence Lower Bound (ELBO) objective that trains them (Section 44.1). We then use trained world models for counterfactual reasoning: asking "what would have happened if I had taken a different action?" and quantifying the confidence of those answers (Section 44.2). Finally, we build a complete model-based planner that selects actions by rolling out imagined trajectories inside the world model, and we diagnose the compound error that accumulates over long planning horizons (Section 44.3).

World models sit at the intersection of several threads in this book. They extend the differentiable programming ideas of Chapter 42 to sequential decision problems, complement the numerical simulators of Chapter 43 with learned surrogates, and provide the dynamics backbone for the optimization methods of Chapter 45 and the automated experiment design of Chapter 46.

Prerequisites

This chapter assumes familiarity with PyTorch (tensor operations, autograd, training loops), variational inference at the level of Chapter 32: Bayesian Discovery and Uncertainty, and the basics of reinforcement learning (states, actions, rewards, policies). Prior exposure to recurrent neural networks (GRUs or LSTMs) is helpful but not required; we introduce the relevant mechanics as needed. Readers who have worked through Chapter 42: Differentiable Programming will find the gradient-through-time derivations familiar.

Learning Outcomes

Sections

44.1 Latent Dynamics Models

Recurrent State-Space Models (RSSM), the DreamerV3 architecture, transformer world models, the ELBO training objective, and the distinction between deterministic and stochastic state components.

44.2 Counterfactual Reasoning with World Models

Interventions in latent space, do-calculus over learned dynamics, confidence-calibrated counterfactual predictions, and applications to scientific "what-if" questions.

44.3 Building a World Model Planner

Recipe: build an RSSM world model, train it on Gymnasium trajectories, implement 5-step rollout planning with the Cross-Entropy Method, and diagnose compound error accumulation.

What's Next

With a trained world model and a rollout-based planner in hand, Chapter 45: Optimization for Discovery broadens the optimization toolkit beyond planning. We will see how Bayesian optimization, evolutionary strategies, and gradient-based methods can all benefit from the cheap surrogate evaluations that world models provide, and how to choose among these methods based on the structure of the discovery problem.

Bibliography

Foundational Papers

Hafner, D., Pasukonis, J., Ba, J., & Lillicrap, T. (2023). Mastering diverse domains through world models. arXiv preprint arXiv:2301.04104.

DreamerV3: the state-of-the-art RSSM-based world model agent that masters Atari, DMLab, and Minecraft without domain-specific tuning. The architecture and training objective we implement in this chapter.

Ha, D. & Schmidhuber, J. (2018). World models. arXiv preprint arXiv:1803.10122.

A seminal paper coining the modern usage of "world models," combining a VAE with an RNN to learn compact environment representations for planning.

Schrittwieser, J., et al. (2020). Mastering Atari, Go, Chess and Shogi by planning with a learned model. Nature, 588, 604-609.

MuZero: learns a world model without access to environment rules, combining learned dynamics with Monte Carlo Tree Search.

Transformer World Models

Micheli, V., Alonso, E., & Fleuret, F. (2023). Transformers are sample-efficient world learners. Proceedings of the 11th International Conference on Learning Representations (ICLR).

IRIS: a transformer-based world model that achieves human-level Atari performance with 100k environment interactions, demonstrating the viability of attention-based dynamics models.

Books and Surveys

Zhu, Y., et al. (2024). A survey on world models for autonomous driving. arXiv preprint arXiv:2403.02622.

A comprehensive survey covering world model architectures, training objectives, and applications, with a taxonomy that extends beyond driving to scientific domains.

Sutton, R. S. & Barto, A. G. (2018). Reinforcement Learning: An Introduction, 2nd edition. MIT Press.

The standard RL textbook; Chapter 8 covers model-based planning and the Dyna architecture that prefigures modern world model approaches.

Tools and Libraries

PyTorch

The primary deep learning framework used throughout this chapter for implementing RSSM components and training world models.

Gymnasium (Farama Foundation)

The standard reinforcement learning environment interface, used here to generate training trajectories and evaluate planners.

dreamer-pytorch

Community PyTorch implementation of DreamerV3, useful as a reference for production-grade RSSM training.

Stable-Baselines3

A reliable set of RL algorithm implementations in PyTorch, useful for generating baseline policies and comparison trajectories.