Differentiable boltzmann code
Author xzackli
11 Stars
Updated Last
1 Year Ago
Started In
January 2021


Dev Build Status codecov

Bolt is a pure-Julia integrator for the Boltzmann equations in cosmology. It can accurately compute the gradient of the CMB power spectrum, with respect to cosmological parameters, using forward-mode automatic differentiation.

It needs a fair bit more physics before it can be applied to modern data. There are some examples showing accurate reproduction of some figures in examples/.

I haven't spent any time optimizing Bolt for performance yet, and in particular the naively implemented source function integrations currently dominate the spectrum cost.

A CMB temperature power spectrum and gradient from Bolt.jl.

Example / Performance

using Bolt
using ForwardDiff

# Cₗ₌₁₀₀ function of baryon density
function cl100(Ω_b::DT) where DT
    par = CosmoParams{DT}(Ω_b=Ω_b)
    bg = Background(par)
    ih = IonizationHistory(Peebles(), par, bg)
    k_grid = quadratic_k(0.1bg.H₀, 1000bg.H₀, 100)
    sf = source_grid(par, bg, ih, k_grid, BasicNewtonian())
    return cltt(100, par, bg, ih, sf)

Δ = 1e-3
print("Result Comparison: ",
    (cl100(0.046 + Δ) - cl100(0.046 - Δ)) / 2Δ, " ",
    ForwardDiff.derivative(cl100, 0.046), "\n")

using BenchmarkTools
print("Simple Finite Difference:\n")
@btime (cl100(0.046 + Δ) - cl100(0.046 - Δ)) / 2Δ
@btime ForwardDiff.derivative(cl100, 0.046)
Result Comparison: 0.00012423928229756477 0.00012423371182564182

Simple Finite Difference:
  13.539 s (26365268 allocations: 2.52 GiB)
  11.160 s (29920717 allocations: 4.97 GiB)