[GECCO 2024] Code World Models: Teaching LLMs to Master Evolutionary Dynamics
Code World Models for Parameter Control in Evolutionary Algorithms
This paper introduces Code World Models (CWMs) for adaptive parameter control in Evolutionary Algorithms (EAs). By leveraging LLMs to synthesize executable Python programs that simulate optimizer dynamics, the method enables greedy planning to achieve a 100% success rate on the deceptive Jumpk landscape, significantly outperforming traditional adaptive rules and DQN.
TL;DR
In a fascinating convergence of LLMs and Evolutionary Computation, researchers have demonstrated that LLMs can "program" their own simulators of optimization algorithms. By synthesizing Python-based Code World Models (CWMs), these agents can predict how an optimizer behaves on complex landscapes. This approach solves the "deceptive valley" problem where standard adaptive rules fail, achieving a 100% success rate on Jumpk landscapes and outperforming Deep Q-Networks (DQN) in both efficiency and generalization.
Background: The Parameter Control Paradox
In Evolutionary Algorithms (EAs), specifically the (1+1)-RLSk, the choice of the mutation strength (the number of bits to flip) is the difference between rapid convergence and eternal stagnation.
Classical adaptive rules utilize a simple heuristic: if you improve, keep going; if you fail, reduce mutation strength. While this works for smooth "unimodal" hills, it is disastrous for deceptive landscapes. When an algorithm hits a "valley," it stops improving. Traditional rules then shrink to 1, effectively trapping the algorithm forever. To cross the valley, it actually needs to increase , but it has no "mental model" to realize this—until now.
Methodology: Synthesis and Greedy Planning
The authors propose a three-stage pipeline to give the optimizer "foresight":
- Trajectory Collection: Collect 200–300 trajectories using sub-optimal, problem-agnostic policies (e.g., fixed or random ).
- CWM Synthesis: An LLM is prompted with the mathematical problem description plus a summary of empirical transitions. It synthesizes a Python class that acts as a simulator, providing methods to
predict_next_stateandevaluate_state. - Greedy Planning: Instead of complex tree searches, the agent simply looks one step ahead. It asks its synthesized CWM: "If I use , what is my expected fitness?" and picks the best one.

The "Normalized Fitness" Trick
A key insight in the synthesis is using continuous expected fitness rather than discrete integers. This allows the agent to perceive "gradient" differences between two values even if they both have a high probability of not improving in a single step, effectively maximizing "drift."
Results: Breaking the Deceptive Valley
The most rigorous test was the Jumpk landscape, characterized by a fitness gap that requires flipping exactly bits to cross.
- Failure of Baselines: Standard adaptive rules like EAα achieved a 0% success rate. They reliably "shrank" themselves into a trap.
- The CWM Triumph: CWM-greedy achieved a 100% success rate.
- Comparison to DQN: While DQN struggled (58% success), the CWM was more sample-efficient and generalized far better. A CWM trained on could still solve with a 78% success rate, whereas DQN dropped to 0%.

NK-Landscapes: Learning Without Math
On the NK-Landscape, where no closed-form mathematical model exists, the authors provided the LLM with an empirical transition table. The LLM successfully converted this raw data into a lookup-based simulator that outperformed all baselines. This proves that CWMs don't just "shorthand" known math; they can distill structured logic from noisy data.
Critical Analysis & Takeaways
Why is this better than Neural World Models? Neural models (like those in Dreamer or MuZero) are opaque. A Code World Model is a Python script. You can read it, debug it, and verify if the LLM has correctly understood the hypergeometric distribution behind bit-flipping.
The Future of "Auditable" AI The authors conclude with a provocative thought: CWMs allow us to reconcile the probabilistic nature of LLMs with the formal requirements of evolutionary theory. By forcing the LLM to write code, we translate its "statistical intuition" into an "explicit heuristic" that humans can audit.
Limitations:
- Computational Cost: While synthesis is cheap (~$0.04), it still requires an API call to a high-end LLM.
- Breadth: Currently limited to (1+1) EA variants; extending this to population-based GA or continuous optimization (CMA-ES) is the next frontier.
Conclusion: This work marks a shift from LLMs as "code assistants" to LLMs as "dynamical system modelers," providing a powerful new tool for the automated design of adaptive algorithms.
