MadEvolve: Evolutionary Optimization of Cosmological Algorithms with Large Language Models
Organizations: Department of Physics, University of Wisconsin-Madison
Abstract
We develop a general framework to discover scientific algorithms and apply it to three problems in computational cosmology. Our code, MadEvolve, is similar to Google's AlphaEvolve, but places a stronger emphasis on free parameters and their optimization. Our code starts with a baseline human algorithm implementation, and then optimizes its performance metrics by making iterative changes to its code. As a further convenient feature, MadEvolve automatically generates a report that compares the input algorithm with the evolved algorithm, describes the algorithmic innovations and lists the free parameters and their function. Our code supports both auto-differentiable, gradient-based parameter optimization and gradient-free optimization methods. We apply MadEvolve to the reconstruction of cosmological initial conditions, 21cm foreground contamination reconstruction and effective baryonic physics in N-body simulations. In all cases, we find substantial improvements over the base algorithm. We make MadEvolve and our three tasks publicly available at madevolve.org.
Figures & tables
| Application | Baseline | Evolved | Improvement | Generations |
|---|---|---|---|---|
| BAO Reconstruction with StdRec ( ) | 0.752 | 0.924 | 22.8% | 1,165 |
| BAO Reconstruction with IterRec ( ) | 0.933 | 0.959 | 2.8% | 386 |
| 21 cm Tidal Reconstruction ( ) | 0.743 | 0.971 | 30.7% | 342 |
| N-body baryonic displacements (test loss) | 0.613 | 0.230 | 63% | 233 |
| Metric | BAO | Iter. Recon. | Tidal | tSZ |
|---|---|---|---|---|
| Total generations | 1,165 | 386 | 342 | 233 |
| Successful programs | 897 | 323 | 293 | 127 |
| Success rate (%) | 77.0 | 83.7 | 85.7 | 54.5 |
| Improvement rate (%) | 30.4 | 29.8 | 24.8 | 13.4 |
| Model | Success (%) | Impr. (%) | Muts/Impr. | |
|---|---|---|---|---|
| Gemini 3 Pro Preview | 619 | 77.9 | 28.9 | 3.5 |
| GPT-5.2 | 303 | 76.2 | 29.7 | 3.4 |
| o4-mini | 320 | 65.9 | 21.9 | 4.6 |
| Gemini 2.5 Pro | 291 | 82.1 | 28.9 | 3.5 |
| Gemini 3 Flash Preview | 228 | 89.5 | 32.9 | 3.0 |
| GPT-5 | 186 | 84.4 | 20.4 | 4.9 |
| Parameter | Value |
|---|---|
| Box size | Mpc |
| Particle count | |
| Mass resolution | |
| Grid resolution | |
| Initial / final redshift | , |
| Cosmology | , , |
| Algorithm | Correlation | Runtime | Parameters | |
|---|---|---|---|---|
| ( ) | (real space) | (seconds) | ||
| Baseline Zel’dovich (autodiff) | 0.752 | 0.344 | 9.7 | 2 |
| Evolved: Hybrid Augmented | 0.924 | 0.581 | 76.1 | 10 |
| Improvement | +22.8% | +68.9% | – | – |
| Algorithm | Correlation | Runtime | |
|---|---|---|---|
| ( ) | (real space) | (seconds) | |
| Iterative Reconstruction | 32.7 | ||
| Evolved: Iterative Augmented | 37.1 | ||
| Improvement | +2.8% | +13.4% |
| Algorithm | Runtime | Parameters | |
| (wedge region) | (seconds) | ||
| Baseline Tidal Tensor | 0.743 | 38.4 | 1 |
| Evolved: Split-Weight Anisotropic | 0.971 | 81.0 | 9 |
| Improvement | +30.7% | – | – |
| Algorithm | Train Loss | Test Loss | Gen. | |
|---|---|---|---|---|
| (6-sim avg) | (all scales) | Found | ||
| Baseline LDL | 0.371 | 0.613 | 0.943 | 0 |
| Evolved: Physics-Informed | 0.149 | 0.230 | 0.969 | 222 |
| Improvement | 60% | 63% | +2.8% | – |
Automated Algorithm Discovery
Automated algorithm discovery develops methods that generate and test executable algorithms for optimization, science, software, and machine learning.
See all 170 papers