spectroxide: A code package for computing cosmic microwave background spectral distortions

arXiv:2604.24838 · astro-ph.CO, astro-ph.IM, cs.AI, hep-ph · Submitted 2026-04-27 · Read on arXiv

Listen

Radio episode about this paper

Transcript

Introduction to the show: ident: Astrophysics Radio. Generated commentary on the latest astrophysics papers.

Vera: I'm Vera.

Jocelyn: And I'm Jocelyn, here with Subrahmanyan.

Vera: We're looking at the paper: "spectroxide: A code package for computing cosmic microwave background spectral distortions".

Paper summary: Vera: So we've seen how Spectroxide is this code package that handles cosmic microwave background spectral distortions using AI assistance to run huge physics problems on supercomputers.

Jocelyn: Yeah, and the authors are Baker, Liu, and Mishra-Sharma. They basically built a whole system—code in Rust and a Python interface—that lets you calculate how things get distorted as the universe evolves from very early times down to today.

Subrahmanyan: It’s about taking these complex equations describing how photons scatter and evolve over cosmic time, like Compton scattering and Bremsstrahlung, and making them runnable.

Vera: They're solving this by evolving the photon occupation number on a non-uniform frequency grid as the universe redshifts from five million years after the Big Bang down to zero.

Jocelyn: And they’re keeping energy conservation pretty tight, using two tricks—an implicit time stepping scheme and a specific subtraction method to handle those tricky double Compton

Conclusion: Vera: So to wrap up, this paper is about Spectroxide, which is basically a whole system of code they built to calculate how energy injections into the very early universe change the spectrum of the cosmic microwave background light we see today.

Jocelyn: And those are Baker, Liu, and Mishra-Sharma. They used AI assistance to create this package in Rust and a Python interface, letting people actually run these huge physics calculations without having to deal with all that low-level coding themselves.

Subrahmanyan: The main idea is taking the complex way photons scatter over cosmic time—like Compton scattering or Bremsstrahlung—and making it a runnable computer program that models everything from five million years after the Big Bang right up to now.

Vera: They manage this by evolving the photon occupation number on a non-uniform frequency grid, and they handle energy conservation with two different tricks, making sure the results are reliable even when dealing with those tricky coupling terms.

Jocelyn: The output gives them a mix of different distortion shapes—temperature shift, mu-type, and y-type—and they use this to extract the Bose-Einstein chemical potential, which is a key piece of information for understanding what happened in the very early universe.

Subrahmanyan: So what this means for us is that we can use this tool to test theories about dark matter or other exotic particles that might leave fingerprints on those spectral distortions we see in the CMB.

Vera: It’s a bridge, really, between the abstract math of particle physics and the actual observable light coming from space. It’s turning theoretical ideas into something concrete you can test with real telescope data.

Jocelyn: And they give us these tools, like visibility functions for different shapes and correction terms, so we can really probe different physical effects imprinted on that spectrum.

Subrahmanyan: It’s a practical way to use AI to manage the incredible complexity of coupled differential equations across timescales that are just too vast for traditional methods.

Vera: This package is a concrete way to explore how energy injection shapes the light we see today from those very first moments of cosmic history.

Jocelyn: And they’re setting up parallel processing so you can run many different historical scenarios at once using that run sweep tool, which opens up a whole new way to explore these possibilities.

Subrahmanyan: It gives us a robust framework for testing predictions about physics that happened way before we could ever directly observe it with other methods.

Vera: So this work is about taking the theoretical picture of cosmic evolution and turning it into a runnable calculation to see what kind of distortions we might expect from new physics.

Jocelyn: And the next step is taking these calculations and comparing them to actual observational data to see if they match what we measure out in the sky.

Boston University

astro-ph.CO, astro-ph.IM, cs.AI, hep-ph

Submitted: 2026-04-27

Updated: 2026-12-02

Comments: 35+21 pages, 12 figures, updated to match published version

Journal ref: SciPost Phys. Codebases 90 (2026)

DOI: 10.21468/SciPostPhysCodeb.90

Code: https://github.com/bakerem/spectroxide

License: http://creativecommons.org/licenses/by/4.0/

Importance score: 90/100

The gist: Spectroxide is a code package designed for computing cosmic microwave background (CMB) spectral distortions…

Key concepts

Photon Occupation Number n(x)
This represents the number of photons present at a specific frequency (x) in the cosmic microwave background. The solver tracks how this number changes over time and redshift as photons scatter, are created, or are injected into the system.
Coupled Scattering Processes
The evolution of n(x) is governed by three linked physical processes: Compton scattering, double Compton emission (DC), and Bremsstrahlung (BR). These interactions depend on the electron temperature ($T_e$), creating a complex feedback loop in how the photon spectrum evolves.
Spectral Distortion Models
The resulting distortion ($\Delta n$) is modeled as a combination of temperature-shift, $\mu$ (chemical potential), and $y$ (adiabatic) types. The package uses a specific formulation to fit these shapes, allowing extraction of the physical Bose-Einstein chemical potential ($\mu$) from observational data.

Terminology

Summary

Spectroxide is a code package designed for computing cosmic microwave background (CMB) spectral distortions, developed under human physicist supervision with AI assistance (Claude Code) to write approximately 14,500 lines of Rust code, a Python interface, and about 400 automated tests. p. 0

Where the paper says it

edu ¶ smishras@bu. edu Abstract We present spectroxide, a code package for computing cosmic microwave background spectral distortions in which all ∼14,500 lines of Rust code, Python interface, and ∼400 automated tests were written by an AI assistant (Claude Code) under human physicist supervision.

The solver evolves the photon Boltzmann equation incorporating Compton scattering, double Compton emission (DC), and Bremsstrahlung (BR) from a high redshift (z about 5 times 10 6) to the present day, allowing for the computation of spectral distortions arising from arbitrary heat and photon injection within this redshift range. p. 0
Where the paper says it

edu Abstract We present spectroxide, a code package for computing cosmic microwave background spectral distortions in which all ∼14,500 lines of Rust code, Python interface, and ∼400 automated tests were written by an AI assistant (Claude Code) under human physicist supervision. The solver evolves the photon Boltzmann equation under Compton scattering, double Compton emission, and Bremsstrahlung from z ∼ 5 × 106 to the present, computing spectral distortions from arbitrary heat and photon injection within this redshift range.

The physical problem is modeled by evolving the photon occupation number n(x) under three coupled scattering processes—Compton, DC, and BR—which are linked through the electron temperature T e. p. 4

Where the paper says it

The stiffness of these rates, combined with the Compton near-cancellation, makes the system difficult to integrate (Appendix B). The three scattering processes are coupled through the electron temperature Te.

The numerical scheme advances delta n(x, z) on a non-uniform frequency grid from an initial redshift (z start) capturing the full injection history down to z=0. p. 5
Where the paper says it

spectroxide evolves ∆n(x, z) on a non-uniform frequency grid from an initial redshift zstart (chosen to capture the full injection history) down to the present day. At each redshift step, the solver: (i) updates the free electron fraction Xe(z) from a Peebles three-level atom model [45, 46]; (ii) determines Te self-consistently from the current ∆n and heating rate; and (iii) advances ∆n by one coupled Compton + DC/BR time step using the scheme described in Appendix B.

At each redshift step, the solver performs three sequential operations: (i) updates the free electron fraction X e(z) using a Peebles three-level atom model; (ii) determines T e self-consistently based on the current delta n and heating rate; and (iii) advances delta n by one coupled Compton + DC/BR time step, following a scheme detailed in Appendix B. p. 5
Where the paper says it

spectroxide evolves ∆n(x, z) on a non-uniform frequency grid from an initial redshift zstart (chosen to capture the full injection history) down to the present day. At each redshift step, the solver: (i) updates the free electron fraction Xe(z) from a Peebles three-level atom model [45, 46]; (ii) determines Te self-consistently from the current ∆n and heating rate; and (iii) advances ∆n by one coupled Compton + DC/BR time step using the scheme described in Appendix B.

Energy conservation is maintained to sub-percent accuracy through two mechanisms: (i) the implicit time-stepping conserves energy to high accuracy by construction, and (ii) a number-conserving temperature-shift subtraction removes the unobservable G bb component arising from DC/BR photon creation, preventing feedback into rho e and degrading energy balance. p. 1

Where the paper says it

4 Adaptive redshift stepping 44 B. 5 Energy conservation and temperature-shift subtraction 44 B.

While neither the Crank–Nicolson scheme (for Compton) nor the backward-Euler scheme (for DC/BR) conserves energy exactly, the dominant leakage is from the first-order backward-Euler DC/BR coupling. p. 6
Where the paper says it

Because Compton scattering conserves photon number but redistributes energy, the equilibrium temperature generally differs from Tγ, absorbing part of the injected energy as an unobservable temperature shift. Expanding to first order in ∆T /Tγ and µ gives nBE − npl ≈ ∆T Tγ − µ βµ Gbb(x) + µ M(x), (5) where the first term is a temperature shift (unobservable, as discussed above) and M(x) = x βµ − 1 e x (e x − 1)2 (6) is the observable µ-distortion spectral shape, with βµ = 3ζ(3)/ζ(2) ≈ 2.

Energy diagnostics show deviations of 0. p. 2
Where the paper says it

SciPost Physics Submission injection after this epoch instead imprints slight deviations from the Planck spectrum. These spectral distortions encode the thermal history of the universe from z ∼ 2 × 106 to the present, providing information complementary to CMB anisotropies and large-scale structure [3, 4].

3% for heat injection in certain redshift regimes and remain below about 1% across all tested redshifts (3 times 10 cubed at most z h at most 3 times 10 6). p. 8
Where the paper says it

(15) but now includes the present-day value (assuming that T ∝ (1 + z) at all times) of the velocity-dependent cross section. The flatter redshift scaling compared to s-wave shifts the energy injection toward higher redshifts, producing a more µ-dominated spectrum.

The solver yields a numerical delta n(x) that is a mixture of temperature-shift, mu -, and y-type distortions, plus a residual component. p. 6

Where the paper says it

192 fixed by photon number conservation (R x 2M dx = 0). After stripping the unobservable temperature shift, the residual distortion is ∆n ≈ µ M(x).

To avoid the degeneracy between temperature-shift and linearized- mu shapes in linear least-squares fitting, the formulation adopts the approach from Ref. p. 8
Where the paper says it

There are no restrictions on the functional form: the solver handles oscillatory profiles, sharp peaks, broad power laws, and profiles with regions of net cooling, as demonstrated by the stress tests in Sec. The returned result object contains the frequency grid x, the spectral distortion ∆n(x), and the decomposed distortion parameters µ, y, and ∆T /T extracted via the least-squares decomposition described in Appendix B.

[73], where chemical potential is kept inside the Bose-Einstein exponential rather than linearized. p. 4
Where the paper says it

When Te > Tγ, electrons up-scatter photons, transferring energy into the photon field. Because Compton scattering conserves photon number, it can establish a Bose–Einstein distribution but cannot relax the chemical potential µ to zero, which instead requires DC and BR.

The spectral distortion is then modeled as delta n model(x; mu, delta, y) = 1 / e x+ mu - 1 - n pl(x) + delta G bb(x) + y YSZ(x), where delta delta T / T gamma. p. 5
Where the paper says it

It is important to note that this picture applies to small distortions where ∆ρ/ρ ≪ 1; for larger energy releases, nonlinear effects modify the thermalization process [12, 48], which we do not model in this work. More generally, any spectral distortion ∆n(x) contains an unobservable temperatureshift component proportional to Gbb(x).

The package allows fitting delta n to this model using nonlinear least squares on the band x in [0. p. 8
Where the paper says it

There are no restrictions on the functional form: the solver handles oscillatory profiles, sharp peaks, broad power laws, and profiles with regions of net cooling, as demonstrated by the stress tests in Sec. The returned result object contains the frequency grid x, the spectral distortion ∆n(x), and the decomposed distortion parameters µ, y, and ∆T /T extracted via the least-squares decomposition described in Appendix B.

5, 18] (nu in [28, 1020] GHz at T 0 = 2.725 K), extracting the physical Bose-Einstein chemical potential mu. p. 4
Where the paper says it

When Te > Tγ, electrons up-scatter photons, transferring energy into the photon field. Because Compton scattering conserves photon number, it can establish a Bose–Einstein distribution but cannot relax the chemical potential µ to zero, which instead requires DC and BR.

Spectroxide is implemented in Rust with zero production dependencies and wrapped in a Python interface requiring no compilation. p. 3

Where the paper says it

SciPost Physics Submission tortion solver, written in Rust with zero production dependencies. The code handles heat and photon injection, and is validated against analytic limits, Green’s function approximations [24,28,38], and CosmoTherm public results where available across all thermalization regimes (Sec.

It exposes individual physics building blocks as standalone NumPyvectorized functions, including visibility functions (j bb*, j mu, j y), spectral shapes (mu shape, y shape, G bb), cosmological quantities (Hubble, cosmic time), and distortion decomposition tools. p. 3
Where the paper says it

Sections 3 and 4 describe the two injection mechanisms implemented in spectroxide—heat injection and photon injection—including how each enters the PDE solver and the specific scenarios supported. Section 5 validates the code against analytic limits, spectral shapes, Green’s function approximations, and tabulated Green’s functions provided by CosmoTherm.

Custom injection scenarios are supported via the Custom variant. p. 9
Where the paper says it

The omission is accurate for xinj ≫ 1 where npl is exponentially small; for xinj ≲ 1 the (1 + npl) 2 correction becomes significant (npl ≈ 1/xinj, so the missing factor grows as 1/x2 inj) and should be included via the custom photon source interface described below. More generally, electromagnetic cascades (pair production, photon splitting), interactions with nuclei, and secondary photon production are not modeled; these effects become important for high-energy injection (ω ≳ me) and are left to future work.

The package includes a pure-Python analytic Green’s function for fast approximations and Jupyter notebooks reproducing key results. p. 3
Where the paper says it

SciPost Physics Submission tortion solver, written in Rust with zero production dependencies. The code handles heat and photon injection, and is validated against analytic limits, Green’s function approximations [24,28,38], and CosmoTherm public results where available across all thermalization regimes (Sec.

Furthermore, it supports multi-redshift sweeps using run sweep, which parallelizes across injection redshifts using all available cores. The C code architecture is modular, with dedicated modules for each physical process (e. p. 1
Where the paper says it

7 Convergence tests 46 B. 8 Performance 46 C Code architecture and usage 47 C.

g., kompaneets.rs, double compton.rs, bremsstrahlung.rs) and test-driven development covering over 400 automated tests, including PDE convergence checks.

Green — the paper says it, and the page is printed. Red — no passage carries it, so treat that sentence as unverified. The same check runs on your own text: check a summary against its source, $5.

Improvements for AI systems

  1. Implement independent source validation in testing by requiring Expected values must come from analytic limits, literature, or dimensional analysis to prevent tests calibrated to code output from detecting systematic errors (Bug 1).

  2. Integrate mandatory dimensional checks before numerical output by instructing the system to verify that the BR emission coefficient KBR must be dimensionless after Thomson time normalization, catching errors like the spurious division by ne (Bug 1).

  3. Require a persistent memory file tracking conventions, known bugs, and decisions made in previous sessions to prevent drift across development sessions and ensure continuity for complex codes.

  4. Introduce specialized subagents for adversarial review, framing the task as finding flaws in code written by someone else to leverage sycophancy toward bug detection rather than away from it.

  5. Enforce a strict testing philosophy where every test target must be derived from an independent source (analytic limits, literature values, or dimensional analysis), never from the code's own output to eliminate self-calibrated tests that pass due to internal consistency (Bug 1).

Abstract

We present spectroxide, a code package for computing cosmic microwave background spectral distortions in which all about 12, 000 lines of Rust code, Python interface, and over 950 automated tests were written by an AI assistant (Claude Code) under human physicist supervision. The solver evolves the photon Boltzmann equation under Compton scattering, double Compton emission, and Bremsstrahlung from z about 5 times 10 6 to the present, computing spectral distortions from arbitrary heat and photon injection within this redshift range. No fully open-source code of this kind is publicly available; we validate against analytic limits, published spectra, and publicly available precomputed Green's function tables. We document the development as a case study in AI-assisted scientific computing, highlighting how domain expertise caught physics bugs (incorrect dimensional prefactors, near-cancellation errors) that evaded the full automated test suite, and document the practices and validation methodology we found effective for human--AI collaborative development of scientific software. We make spectroxide publicly available on GitHub.

Sources

Related papers