---
title: "Recompute a relic abundance with the saved scripts"
description: "Rerun the saved Python model, check it against a time-domain solution and a collision integral, and see three shortcuts that break the answer."
canonical_url: "https://sandboxphysics.com/stories/dark-matter-relics/recompute-a-relic-abundance/"
language: "en"
page_type: "story"
alternate_languages:
  zh-CN: "https://sandboxphysics.com/zh/stories/dark-matter-relics/recompute-a-relic-abundance/"
last_modified: "2026-11-14"
---

[How dark matter was left over](https://sandboxphysics.com/stories/dark-matter-relics/)

# Recompute a relic abundance with the saved scripts

Sandbox Physics · 2026-11-14

This tutorial reruns the Lab's relic model in Python and checks it in ways that do not reuse its own equation. The default case, a 100 GeV particle with $\langle\sigma v\rangle_0=2.136\times10^{-26}\,\mathrm{cm^3\,s^{-1}}$, ends with $Y_\infty=4.373\times10^{-12}$ and $\Omega h^2=0.120$. A separate solution in cosmic time agrees to 0.03 per cent, a direct collision integral reproduces the freeze-in yield to 0.0005 per cent, and the result sits 8 per cent above the published fit of Steigman, Dasgupta and Beacom because this model holds $g_*$ fixed. Three tempting shortcuts give wrong answers, and the scripts save each one.

Everything here is output of a teaching model, not a measurement. The only measured number used is the dark matter density $\Omega h^2=0.120\pm0.001$ from Planck 2018. [Planck Collaboration, 2018, abstract](https://arxiv.org/abs/1807.06209v4)

## Files, versions and units

The scripts need Python 3.9 or later with NumPy and SciPy; the saved files were made with Python 3.9.6, NumPy 2.0.2 and SciPy 1.13.1. The materials are in this collection's materials folder:

- [relic\_model.py](https://sandboxphysics.com/stories/dark-matter-relics/materials/relic_model.py), the reference model that the Lab's TypeScript code mirrors;
- [inputs.json](https://sandboxphysics.com/stories/dark-matter-relics/materials/inputs.json), the constants, solver settings and six presets;
- [run\_relic\_benchmarks.py](https://sandboxphysics.com/stories/dark-matter-relics/materials/run_relic_benchmarks.py) and its saved [relic-benchmarks.json](https://sandboxphysics.com/stories/dark-matter-relics/materials/relic-benchmarks.json);
- [check\_independent\_limits.py](https://sandboxphysics.com/stories/dark-matter-relics/materials/check_independent_limits.py) and its saved [independent-checks.json](https://sandboxphysics.com/stories/dark-matter-relics/materials/independent-checks.json);
- the [README](https://sandboxphysics.com/stories/dark-matter-relics/materials/README.md).

Masses and temperatures are in GeV. Cross-sections are entered in $\mathrm{cm^3\,s^{-1}}$ and converted with $1\,\mathrm{GeV^{-2}}=1.167329\times10^{-17}\,\mathrm{cm^3\,s^{-1}}$. The model holds $g_*=g_{*s}=86.25$, takes $g=2$ internal states and $M_{\mathrm{Pl}}=2.435\times10^{18}\,\mathrm{GeV}$, and converts with $\Omega h^2=2.744\times10^{8}\,(m/\mathrm{GeV})\,Y_\infty$.

```
mkdir ac73-check && cd ac73-check
base=https://sandboxphysics.com/stories/dark-matter-relics/materials
for name in relic_model.py inputs.json run_relic_benchmarks.py check_independent_limits.py relic-benchmarks.json independent-checks.json; do curl -fsSLO "$base/$name"; done
python3 -m venv .venv && .venv/bin/pip install numpy scipy
.venv/bin/python -I run_relic_benchmarks.py inputs.json my-relic-benchmarks.json
.venv/bin/python -I check_independent_limits.py my-independent-checks.json
```

The benchmark run takes about half a minute and the checks a few seconds. Compare your two new files with the saved ones; on another machine the last digits may differ.

## Step 1: the solver and its step size

The model integrates $\mathrm dY/\mathrm d\ln x=-k(x)\,(Y^2-Y_{\mathrm{eq}}^2)$ from $x=10^{-3}$ with 250 steps per e-fold of $x$. Each step uses second-order backward differentiation, which evaluates the right side at the new point. Because the right side is quadratic in $Y$, each step is a quadratic equation with one non-negative root, so no iteration is needed:

```
a = 2 * h / 3 * k[i]
c = (4 * y[i - 1] - y[i - 2]) / 3 + 2 * h / 3 * k[i] * yeq[i] ** 2
y[i] = 2 * c / (1 + math.sqrt(1 + 4 * a * c))
```

Doubling the steps to 500 per e-fold changes $Y_\infty$ by $2.3\times10^{-4}$ for the default case, $3.0\times10^{-5}$ for kination and $5\times10^{-9}$ for freeze-in. With 50 steps per e-fold the default case is off by 1.0 per cent. The settling point in the readouts is the last $x$ at which $Y$ differs from its final value by more than 10 per cent.

**Table 5.1** Presets from relic-benchmarks.json, $m=100\,\mathrm{GeV}$.

| Preset | $\langle\sigma v\rangle_0$, $\mathrm{cm^3\,s^{-1}}$ | Start | $Y_\infty$ | $\Omega h^2$ | Settles by $x$ |
| --- | --- | --- | --- | --- | --- |
| Freeze-out | $2.136\times10^{-26}$ | equilibrium | $4.373\times10^{-12}$ | $0.120$ | $208$ |
| Stronger annihilation | $2.136\times10^{-24}$ | equilibrium | $5.241\times10^{-14}$ | $0.00144$ | $239$ |
| Hot relic | $10^{-38}$ | equilibrium | $5.331\times10^{-3}$ | $1.46\times10^{8}$ | $0.001$ |
| Freeze-in | $2.571\times10^{-45}$ | empty | $4.373\times10^{-12}$ | $0.120$ | $1.59$ |
| Kination, $T_r=20\,\mathrm{MeV}$ | $2.136\times10^{-26}$ | equilibrium | $1.466\times10^{-10}$ | $4.02$ | $8085$ |
| Freeze-out, empty start | $2.136\times10^{-26}$ | empty | $4.373\times10^{-12}$ | $0.120$ | $208$ |

Where to look: the first and last rows are identical to every printed digit, which is the memory loss that defines freeze-out. Common misreading: the hot relic's settling point is the first grid point only because its value never changes by 10 per cent.

## Step 2: checks that do not reuse the model equation

check\_independent\_limits.py recomputes each result by a different route.

**Table 5.2** Independent checks from independent-checks.json.

| Check | Model | Independent value | Agreement |
| --- | --- | --- | --- |
| $F(20)$ from the $s$ integral | $0.86390$ | $0.86390$ | $<10^{-5}$ |
| Default case, solved in cosmic time | $4.3733\times10^{-12}$ | $4.3746\times10^{-12}$ | $0.03\%$ |
| Kination, solved in cosmic time | $1.46582\times10^{-10}$ | $1.46588\times10^{-10}$ | $0.004\%$ |
| Freeze-in, collision double integral | $4.37346\times10^{-12}$ | $4.37348\times10^{-12}$ | $0.0005\%$ |
| Freeze-in, closed form $(3\pi^2/32)a^2\lambda$ | $4.37346\times10^{-12}$ | $4.37819\times10^{-12}$ | $0.11\%$ |
| $\Gamma/H$ at $x=25$, Friedmann $H$ against Steigman eq. 12 | $1.27752$ | $1.27767$ | $0.012\%$ |
| Inverse yield at $x=500$, kination log law | $3.5629\times10^{9}$ | $3.5652\times10^{9}$ | $0.06\%$ |

The cosmic-time solution does not use $Y$ or $x$ at all. It integrates the number density $n(t)$ with the stiff Radau method, takes $H$ from the Friedmann equation and the equilibrium density from the Bessel-function formula in physical units, and only at the end divides by the entropy density. The collision integral computes the production rate as a double integral over pair energy and temperature, with no use of $F$. The Steigman row computes $\Gamma/H$ for slow particles from the Friedmann equation and compares it with the coefficient printed in their eq. (12). [Steigman, Dasgupta and Beacom, 2012, section II.A](https://arxiv.org/abs/1204.3622v3) The log-law row uses only the asymptotic form of D'Eramo and colleagues' eqs. (C16) and (C18). [D'Eramo, Fernandez and Profumo, 2017, appendix C](https://arxiv.org/abs/1703.04793v1)

## Step 3: published values

Two comparisons are with published numbers that come from fuller calculations, so they are expected to differ.

**Table 5.3** Cross-section that gives $\Omega h^2=0.120$ for $m=100\,\mathrm{GeV}$.

| Source | $\langle\sigma v\rangle$, $\mathrm{cm^3\,s^{-1}}$ | $\langle\sigma v\rangle$, $\mathrm{GeV^{-2}}$ |
| --- | --- | --- |
| This model | $2.136\times10^{-26}$ | $1.830\times10^{-9}$ |
| Steigman, Dasgupta and Beacom, eq. 26 fit | $1.980\times10^{-26}$ | $1.696\times10^{-9}$ |
| D'Eramo, Fernandez and Profumo, Fig. 1 | $1.98\times10^{-26}$ | $1.7\times10^{-9}$ |

Both published values include $g_*(T)$, which falls through the QCD transition, and both assume a constant cross-section. This model is 8 per cent higher. The Lee–Weinberg matching estimate, D'Eramo and colleagues' eqs. (C10) and (C12) with $c=\sqrt2-1$, gives $x_f=21.7$ and $Y_\infty=3.97\times10^{-12}$ for a constant cross-section, 3.4 per cent below the model's own constant-cross-section solution of $4.11\times10^{-12}$.

## Step 4: three shortcuts that fail

The script saves three failures on purpose.

1. Forward Euler with the same 250 steps per e-fold. At $x=10^{-3}$ in the default case, the step times the reaction rate is $3\times10^{4}$, so the explicit update overshoots and diverges at $x=0.00102$, after five steps.
2. The slow-particle formula $Y_{\mathrm{eq}}\propto x^{3/2}\mathrm e^{-x}$ used everywhere. Freeze-in happens at $x\simeq1$ to 3, where that formula is wrong, and the yield comes out at 5.7 per cent of the correct value.
3. A constant cross-section in freeze-in. Then the production rate does not fall off at high temperature, and the yield depends on the start: $1.891\times10^{-8}$ from $x=10^{-3}$ and $1.871\times10^{-9}$ from $x=10^{-2}$, a factor of 10.1. The answer would be set by a starting temperature that no measurement fixes.

## Step 5: compare a Lab export

In the [dark matter relic Lab](https://sandboxphysics.com/labs/dark-matter-freeze-out-freeze-in/), press Export this record. The file holds the input, the summary and the solution at 20 points per decade of $x$. Its summary.finalYield for the default case should match the wimpFreezeOut entry in relic-benchmarks.json to about $10^{-7}$, the level at which the TypeScript and Python Bessel functions agree.

```
{"summary": {"finalYield": 4.37327e-12, "omegaH2": 0.119998, "settlingX": 207.64}}
```

The snippet shows the fields to compare, rounded; the exported file prints full precision.

## What these checks do not cover

The model keeps $g_*$ constant, uses Maxwell–Boltzmann statistics, assumes a contact interaction with massless products and ignores co-annihilation, resonances and thresholds. The checks show that the code solves its stated equation correctly and that its scaling matches published work. Whether any real dark matter particle behaves this way is a question for experiments.

## Sources

1. [Planck Collaboration, 2018, abstract](https://arxiv.org/abs/1807.06209v4)
2. [Steigman, Dasgupta and Beacom, 2012, section II.A](https://arxiv.org/abs/1204.3622v3)
3. [D'Eramo, Fernandez and Profumo, 2017, appendix C](https://arxiv.org/abs/1703.04793v1)

## Keep reading

How dark matter was left over · Reading path

### From thermal equilibrium to relentless dark matter

1. [Article **Why did any dark matter survive the hot early universe?**](https://sandboxphysics.com/stories/dark-matter-relics/why-some-dark-matter-survived-the-cooling/)
2. [Article **Equilibrium, expansion and the reaction race**](https://sandboxphysics.com/stories/dark-matter-relics/equilibrium-expansion-and-the-reaction-race/)
3. [Article **The Boltzmann equation and freeze-out**](https://sandboxphysics.com/stories/dark-matter-relics/the-boltzmann-equation-and-freeze-out/)
4. [Article **Freeze-in, hot relics and faster expansion**](https://sandboxphysics.com/stories/dark-matter-relics/freeze-in-hot-relics-and-faster-expansion/)
5. [You are here **Recompute a relic abundance with the saved scripts**](https://sandboxphysics.com/stories/dark-matter-relics/recompute-a-relic-abundance/)
6. [Article **How to read the relentless dark matter paper of D'Eramo and colleagues**](https://sandboxphysics.com/stories/dark-matter-relics/reading-relentless-dark-matter/)
