WorksPhysics and Astronomy
bihalofit-JAX: A Differentiable Code for the Nonlinear Matter Bispectrum and its Projected Statistics
Abstract
Theoretical predictions for the nonlinear matter bispectrum and related projected statistics have been historically very expensive to evaluate, leading many analyses to rely on emulators to speed up slow numerical codes. We show in this paper that this need not be the case: improved numerical techniques can be leveraged to directly evaluate predictions for the nonlinear matter bispectrum and projected statistics at speeds preferable for inference. We present bihalofit-JAX, an open-source, fully differentiable code for the nonlinear matter bispectrum based on the BiHalofit fitting formula, which includes numerous related projected statistics such as angular bispectra, skew spectra and aperture statistics. It computes triangles of the matter bispectrum in – per cosmology, one to three orders of magnitude faster than other implementations. It agrees numerically with the original BiHalofit code to better than on average over the cosmologies the formula was calibrated on, where the formula itself is accurate to against simulations. It is also efficiently vectorised such that one can compute e.g. cosmologies in . This speed-up grows even more in the case of the third-order aperture statistics, which we compute in for one cosmology, between and times faster than other publicly available codes. The pipeline is fully differentiable, and we demonstrate its performance in a simple inference problem, comparing the No-U-Turn Sampler (NUTS) to gradient-free inference with the affine-invariant ensemble sampler (emcee).
Introduction
The matter bispectrum (the three-point correlation function of the density field in Fourier space) contains information that is inaccessible to the power spectrum alone [75]. Because it is sensitive to the non-Gaussian structure generated by gravitational collapse, it helps to constrain bias parameters [66, 40] and to break parameter degeneracies [8, 81, 76]. It is also the primary large scale structure probe of primordial non-Gaussianity, whose signature is imprinted in the initial conditions [17, 26, 18, 24]. Exploiting this information in forthcoming galaxy and lensing surveys, however, requires techniques that have lagged well behind those for the power spectrum (two-point correlation function in Fourier space): measurements are costly [86], covariance matrices need large numbers of mocks [67], and theoretical predictions are both expensive [23, 20] and difficult to model accurately [58].
BiHalofit [82] is a widely used analytic fitting formula for the nonlinear matter bispectrum, calibrated directly against -body simulations. It achieves an accuracy of on scales of and redshifts of – for -cold dark matter (CDM) cosmologies ( refers to a constant dark energy equation of state). It includes a prescription for correcting for baryonic effects, which are critically important on small scales [32, 5, 16]. BiHalofit offers a powerful alternative to perturbation-theory approaches, which break down on mildly nonlinear scales and neglect information contained in the nonlinear regime. Existing public implementations of this model, however, have historically been extremely slow to evaluate, particularly for projected statistics such as the weak-lensing convergence bispectrum and mass-aperture statistics [47, 43], which require multiple nested integrals over the matter bispectrum. The reason for this is that the codes available for BiHalofit and its related projected statistics are not sufficiently optimised (particularly for modern hardware e.g. GPUs), and are not efficiently vectorised (important whenever the statistics must be evaluated over large batches of cosmologies, redshifts, or triangle configurations). Due to these difficulties, many analyses have relied on emulators of statistics related to the bispectrum (Heydenreich et al. 2023; Gong et al. 2023; Burger et al. 2024; Gomes et al. 2025a,b; Sugiyama et al. 2025; Linke et al. 2026), which replace computationally expensive codes with fast surrogates trained on evaluations of the codes. Despite their ability to render the inference tractable, emulators introduce additional sources of error [9], and require large training sets (Nygaard et al. 2024), and are intrinsically limited to the parameter space on which they were trained. As such it is preferable to have a fast, vectorised implementation of the underlying model itself (also ideally differentiable), which can be used directly in inference pipelines without the need for emulation.
bihalofit-JAX is a new implementation of BiHalofit and of the projected statistics built on it: projected bispectra, skew spectra and aperture statistics. Its improved performance compared to existing codes comes from its numerical design: a fixed-iteration Newton solve for the nonlinear scale replaces bisection over an adaptively integrated , and fixed quadrature grids, including a change of variables for the aperture statistics, replace adaptive integration. Because every step has a fixed shape and iteration count, the whole calculation compiles once and is batched across cosmologies, redshifts and triangle configurations. We write it in JAX ([11]), which provides the just-in-time (JIT) compilation, GPU portability and automatic differentiation, with no change to the user-facing Python code. The full pipeline is differentiable, so gradients flow from the projected observables back to the cosmological parameters, in the spirit of differentiable pipelines for two-point statistics ([72, 19, 69, 21]). This enables gradient-based samplers ([27, 13, 45, 70]), which can greatly speed up high-dimensional inference (Mootoovaloo et al. 2024; Nygaard et al. 2026).
This paper describes the bihalofit-JAX package, which is summarised in Figure 1. We present the main BiHalofit implementation in § 2. We discuss the projected statistics in § 3: the projected bispectra in § 3.1, skew spectra in § 3.2 and aperture statistics in § 3.3. We compare its speed and numerical agreement with other implementations in § 4, demonstrate its performance in inference in § 5 and conclude in § 6.
Figure 1. Overview of the bihalofit-JAX pipeline. Cosmological parameters are input by the user, with the linear power spectrum (§ 2.2) supplied by one of three interchangeable backends. The BiHalofit kernel then evaluates the nonlinear matter bispectrum, which is Limber-projected onto an observable (e.g. weak-lensing) bispectrum (§ 3.1) and reduced to downstream summary statistics: skew spectra (§ 3.2) and third-order aperture statistics (§ 3.3).
BiHalofit: Model and JAX Implementation
Model
The matter bispectrum is defined as the three-point correlation function of the matter density field in Fourier space:
where is the Fourier transform of the matter density contrast, is the three-dimensional Dirac delta function (coming from assuming statistical homogeneity of the fields), and is the bispectrum, which depends on the magnitudes of the three wavevectors forming a closed triangle in Fourier space. For large scales, the bispectrum can be computed using perturbation theory, but on smaller scales, nonlinear effects become significant, and one has to resort to fitting formulas or simulations to generate theoretical predictions. BiHalofit ([82]) provides the current state-of-the-art for modelling these nonlinear scales, providing an analytic fitting formula for the nonlinear matter bispectrum as a function of cosmology and triangle configuration. It is parameterised by the nonlinear scale and effective spectral index , defined by
where is the dimensionless linear power spectrum. We suppress the redshift dependence throughout for simplicity. These quantities, together with the amplitude of matter perturbations on scales of , , the energy density fraction of matter, , and the tilt of the primordial power spectrum, , fully parameterise the fitting formula. The BiHalofit bispectrum combines a 1-halo and a 3-halo term,
which describe the contribution to the bispectrum from within a halo and from the correlation between three different halos, respectively. Figure 2 shows the two terms separately for equilateral triangles, alongside their sum and the tree-level bispectrum that reduces to on large scales. The 2-halo contribution, which is important on intermediate scales and for squeezed triangles (), is neglected in the formula. Writing (where ) the 1-halo and 3-halo terms are parameterised as
Figure 2. The 1-halo () and 3-halo () terms of the BiHalofit fitting formula, for equilateral triangles at . The tree level bispectrum () is shown for comparison. The cosmological parameters are set to: , , , , , eV, and . The linear power spectrum is generated using baccoemu.
where we have defined
The permutations in Eq. (8) are cyclic over the wavenumbers, and is the second-order perturbation theory kernel,
with fixed by the triangle side lengths via the law of cosines. The coefficients are calibrated against simulations and are fitted power-law functions of , , and the triangle-shape parameters and . Appendix A.§ 1 gives their explicit form in terms of the cosmological parameters. We present the calibration range of the fitting function in the first column of Table 1. We refer the reader to Takahashi et al. [82] for further details about the simulations and fitting procedure used.
| Parameter | BiHalofit | baccoemu | syren-new | BiHalofit baccoemu | BiHalofit syren-new |
| [0.18, 0.45] | [0.06, 0.7] | [0.24, 0.40] | [0.18, 0.45] | [0.24, 0.40] | |
| [0.024, 0.082] | [0.03, 0.07] | [0.04, 0.06] | [0.03, 0.07] | [0.04, 0.06] | |
| [0.54, 0.93] | [0.5, 0.9] | [0.61, 0.73] | [0.54, 0.9] | [0.61, 0.73] | |
| [0.916, 1.013] | exact | [0.92, 1.00] | [0.916, 1.013] | [0.92, 1.00] | |
| [0.50, 1.36] | exact | [0.28, 1.30] | [0.50, 1.36] | [0.50, 1.30] | |
| [eV] | 0.06 | [0, 1] | [0, 0.15] | 0.06 | 0.06 |
| [−1.2, −0.8] | [−2.0, −0.5] | [−1.3, −0.7] | [−1.2, −0.8] | [−1.2, −0.8] | |
| 0 | [−0.5, 0.5] | [−0.7, 0.5] | 0 | 0 | |
| [0, 1.5] | [0, 9] | [0, 3] | [0, 1.5] | [0, 1.5] | |
| [] | 3 | 50 | 9 | 3 | 3 |
Table 1. Parameter ranges that BiHalofit and the two emulated linear power spectrum backends (§ 2.2) were fitted or trained on, and, in the last two columns, their intersections: the region where BiHalofit and the backend are both valid. The BiHalofit ranges are the extremes of the sampling box of the 40 CDM simulations of Takahashi et al. [82]. Note that the simulated cosmologies fill only a thin, curved region of this box, with . The BiHalofit range is converted from with the syren-new formula (Sui et al. [80]). is the cold matter density; the BiHalofit and syren-new bounds are on , which differs by . The “exact” entries mean the quantity is not bounded.
bihalofit-JAX also accepts a Chevallier–Polarski–Linder (CPL) dark-energy equation of state, . It enters only through the background expansion, which sets , and the linear growth in the linear power spectrum, so the fitting formula itself is unchanged. The coefficients were calibrated on constant- simulations, so is an extrapolation that has not been validated against simulations; we provide it for generality, e.g. for forecasts or priors that vary .
In addition to providing a fitting formula for the nonlinear matter bispectrum, BiHalofit also includes a baryonic-feedback correction, calibrated against hydrodynamical simulations of IllustrisTNG (Nelson et al. [61]) and applied as a per-leg multiplicative boost to the dark-matter-only bispectrum:
where is the bispectrum including baryonic-feedback. Writing , the per-leg ratio is
The amplitudes , , centroids , , widths , , and the shape scale and slope are fitted functions of the scale factor alone, and the exponents and are constants; Appendix A.§ 2 gives their explicit form. The correction is calibrated only up to and is set to (no correction) beyond that.
Differentiable Linear Power Spectrum Backends
BiHalofit takes the linear power spectrum as an input (see Eqs. (3) and (10)), traditionally obtained from a Boltzmann-solver such as CAMB (Lewis et al. [52]; Lewis (2026)) or CLASS (Blas et al. [10]). Due to computational cost in inference there is a growing availability of fast, differentiable emulators for , trained on Boltzmann-solver outputs or simulations, and evaluated accurately orders of magnitude faster (Fendt & Wandelt 2007a,b; Mootoovaloo et al. 2022; Aricò et al. 2022; Spurio Mancini et al. 2022; Piras & Spurio Mancini 2023; Bartlett et al. 2024b; Orjuela-Quintana et al. 2026). In this work we make use of this growing ecosystem by supporting various linear power spectrum backends.
bihalofit-JAX currently supports three interchangeable built-in differentiable, fast to evaluate linear power spectrum models. Switching between them requires no other change to the pipeline or user interface. We have designed the backends to be easily extensible, so that users can add their own differentiable linear power spectrum model (e.g. a Boltzmann emulator such as CosmoPower-JAX (Piras & Spurio Mancini [68]) by implementing a single function with the same signature as the built-in backends1. Importantly, the downside of using an emulated linear power spectrum is that the emulator is only valid within its training volume, and will not necessarily extrapolate reliably outside of it. As such we recommend that users check the validity of their cosmology against the training volume of the chosen backend before using it in inference and consult Table 1 for the training ranges of the two emulated backends.
The three backends, and the trade-offs between them, are:
baccoemu: A neural network emulator of the linear cold-matter power spectrum, trained on the outputs of a Boltzmann solver (Aricò et al. [4]), natively supporting massive neutrinos and a dark-energy equation of state. Its network evaluates in float32, so we run it in float32 throughout the calculation. We call its JAX-ported forward
pass directly, batching every cosmology and redshift into a single call rather than looping over the emulator’s own Python interface. An important detail is that baccoemu is trained on a fixed -grid of logarithmically spaced points over , meaning interpolation is required, resulting in a small error which is in principle not present in the other two backends (one can evaluate them at any wavenumber). We discuss this further in § 2.3 and Appendix B. Another disadvantage of this emulator is that it uses a Rectified Linear Unit (ReLU) activation function, which leads to discontinuous derivatives in some regions of parameter space. We therefore do not recommend using this backend when computing derivatives, such as in gradient-based inference.
syren-new: A symbolic-regression fitting formula for the linear matter power spectrum of Sui et al. [80], reimplemented here directly in JAX with no external dependency2. Its amplitude is set by converting to with the fitting formula of Sui et al. [80], which is accurate to , so, as for the other two backends, we then rescale the spectrum to have exactly the requested . Its cost within the full calculation is similar to that of baccoemu (Appendix C). Like baccoemu, it natively supports massive neutrinos and a dark-energy equation of state. The bounds of its training volume are slightly narrower than baccoemu’s (see Table 1), although they match to within the intersecting training region. Note, however, that symbolic-regression emulators are much more successful at extrapolating beyond their training range compared to neural-network emulators. We also highlight that due to the analytical form of the emulator, we have continuous derivatives making this ideal for inference.
Einstein & Hu (1998): The analytic Eisenstein & Hu [28] no-wiggle transfer function (E&H from hereon) (Eisenstein & Hu [28]). It ignores massive neutrinos (though it still accepts a , equation of state) and is the least accurate of the three, but it is dependency-free and useful as a minimal fallback or for isolating BiHalofit-specific behaviour from emulator or symbolic-regression systematics.
We quantify the effect of the backend choice on the final statistics, holding cosmology, the BiHalofit fitting formula and the triangle set fixed, in Appendix C. Relative to syren-new, E&H deviates in the matter bispectrum by a mean of 3% (at most 18%), while baccoemu deviates by a mean of 0.2% (at most 3.3%), over 1000 cosmologies in the region the simulations cover. The differences between syren-new and baccoemu are small compared with the accuracy of the BiHalofit fitting formula itself of up to (Takahashi et al. [82]), whereas E&H is the least accurate of the three.
JAX kernel design
Where the original implementation3 of BiHalofit (Takahashi et al. [82]) locates by bisection against an adaptively integrated , independently per redshift and cosmology, our kernel instead uses a safeguarded (bisection-backed) Newton iteration on Eq. (2), evaluated directly on a fixed -grid and batched across cosmologies and redshifts. The same Newton derivative then evaluates the integral of Eq. (4). This is a more efficient root-finding method, which converges in around steps (compared to steps for the bisection-based method) for both float32 and float644. In addition to fewer iterations, our method is directly optimised for GPU work, where the number of iterations is fixed to avoid host-to-device transfers in operations such as while loops which slow down processes. The kernel also returns the size of the last Newton step, which the code can check against a user-supplied tolerance to validate the convergence. The convergence tests and recommended precision settings are examined in Appendix B.
The linear power spectrum is tabulated on a logarithmically spaced grid to evaluate the integrals of Eqs. (3) and (4). This is done independently for each redshift slice. To avoid further evaluations of the linear power spectrum, we perform linear interpolation of this table in log against log , and use the interpolant to evaluate Eq. (10). A resolution of for keeps the interpolation error on the bispectrum at 0.019% on average and at most 0.18%, below the mean difference of 0.2% between the more accurate linear power spectrum backends, syren-new and baccoemu (Appendix C). These performance parameters can be tuned in our code to trade off speed and accuracy, which we examine in more detail in Appendix B. We show in Figure 3 the full calling signature, building the model once for a fixed triangle/redshift grid and evaluating the bispectrum at one cosmology.

Figure 3. Example of generating a matter bispectrum prediction using bihalofit-JAX. Tutorials are provided alongside the package, including a full example of the weak-lensing bispectrum, skew spectra and mass-aperture statistics.
# Import packages
import numpy as np
from bihalofit_jax import make_bihalofit,
Cosmology
# Build cosmology
cosmo = Cosmology(
omega_cold=np.array([0.3156]),
omega_baryon=np.array([0.0492]),
sigma8_cold=np.array([0.831]),
ns=np.array([0.9645]),
hubble=np.array([0.6727]),
neutrino_mass=np.array([0.0]),
w0=np.array([-1.0]),
wa=np.array([0.0]),
)
# Build JIT-compiled bihalofit kernel
k = np.array([0.1, 0.2, 0.3])
bhf = make_bihalofit(
k1=k, k2=k, k3=k,
expfactors=np.array([1.0]),
pk_source='baccoemu',
N_R=15,
tol=None,
R_min=1e-6,
R_max=40.0,
dtype=np.float32,
validate=False,
term='full',
baryonic_boost=False,
k_lin=None,
)
# Evaluate bispectrum at the cosmology
B = bhf(cosmo)
The full kernel is compiled with a single just-in-time (JIT) compilation: cosmologies are fully batched, the redshift axis makes use of the vmap tool of JAX, and triangle configurations are handled by broadcasting. This design allows the bispectrum to be computed in – ms, far faster than any other implementation of BiHalofit, as we show in § 4.2. Not only this, but it also scales extremely well with the number of cosmologies and redshifts, making it suitable for inference pipelines that require the evaluation of the bispectrum
at many cosmologies and redshifts, or for batch evaluations of the formula for training emulators. The kernel can be evaluated in float32 or float64, with the former being the default. This is critical for GPU performance, since GPUs (especially modern ones) are optimised for float32 operations. We find that the loss of precision in float32 does not significantly affect the accuracy of the bispectrum, and the speed-up gained from using float32 is significant. The design of this base kernel enables the efficient computation of downstream statistics, such as the weak-lensing bispectrum, skew spectra and mass-aperture statistics, since one is required to evaluate the bispectrum many times across redshift and wavenumbers, as we show in § 3 and § 5.
Projected Summary Statistics
Projected Bispectra
In photometric surveys we observe different tracers of the large scale structure of the Universe which are projected along the line of sight. These tracers might include for example galaxy clustering, weak lensing, or CMB lensing. Statistical analyses including correlations of these observables (e.g. angular power spectra or bispectra) have been shown to be a powerful probe of cosmology ([34, 1]). In this section we show how to compute these projected statistics using the BiHalofit kernel. It can be shown that the projected bispectrum (examples include galaxy-galaxy-lensing or lensing-lensing-lensing bispectra) is related to the three-dimensional matter bispectrum in the Limber approximation ([53, 57]) (valid for large )
where and is the kernel corresponding to a given tracer. The matter bispectrum can be computed on nonlinear scales using the BiHalofit model5, which is described in § 2. In the case of galaxy-clustering the kernel is
for a linear bias, . In weak lensing (cosmic shear), one considers the coherent distortion of light rays from source galaxies caused by the large scale structure of the Universe. With a source distribution , the kernel is described by
where we have set . Note that in the full sky there is usually a factor of which appears in the lensing kernel; however we neglect this in the first version of our code since it is negligibly close to unity for (where the Limber approximation is valid). In so-called beyond-Limber statistics these factors would become important on large angular scales. The CMB-lensing kernel has the same functional form but where is now a delta function at . We write for the projected weak-lensing bispectrum, i.e. Eq. (14) with the lensing kernel on all three legs.
A very important effect for cosmic shear, particularly in stage IV surveys, is the impact of intrinsic alignments (IA) of the source galaxies with their local environment [14]. This is typically taken into account using the nonlinear alignment (NLA) model [44, 12], which results in the kernel
where is the source distribution, the linear growth factor normalised to , , and and are free parameters.
We evaluate the Limber integral, Eq. (14), with Gauss–Legendre (GL) quadrature in . By default we use nodes over . The nodes are fixed and shared by all three kernels, so the integral needs one BiHalofit evaluation per node. This is directly compatible with the BiHalofit kernel design, which is optimised for many evaluations of the bispectrum at once.
Each GL node requires the redshift to evaluate the matter bispectrum (BiHalofit), so we calculate (as a default) on a grid of uniformly spaced redshifts up to , and invert it at the nodes using a Catmull–Rom spline (this keeps the result differentiable as the mapping from comoving distance to redshift depends on the cosmology). The clustering and IA kernels also need the evaluation at the same comoving distances, so we interpolate (again using a Catmull–Rom spline) the user-inputted to the node redshifts . With the default settings the mean error is for lensing and IA kernels and with clustering legs (Appendix B.§ 2).
Skew Spectra
Skew spectra compress the bispectrum’s full triangle dependence into a power-spectrum-like function of a single multipole, by cross-correlating a field with a composite (squared/quadratic) map built from another field and fixing one leg of the underlying bispectrum rather than binning all three. A simple example is to construct the square of the (filtered) galaxy overdensity field, , and take the correlation of this with the original field, from which one can show that
where defines the angular power spectrum between the two fields (the skew spectrum) and the matrix is the Wigner-3 symbol which encodes the angular momentum conservation on the sphere.6 Here we have that refers to the angular bispectrum computed using Eq. (14) with the number counts kernel Eq. (15) on each leg (we suppress the redshift information for simplicity). More general constructions are possible, including cross-correlations between different fields and different quadratic combinations of the fields, including filtered combinations of fields [41, 40, 84] (Roskill et al. 2026). These statistics have the key advantage of leveraging the highly developed infrastructure surrounding the efficient estimation of power spectra [2] and their covariances [41], while retaining much of the information content of the bispectrum. Despite this, the modelling of these statistics is still a significant challenge, particularly with regards to computational expense, that we aim to ameliorate here.
To keep our implementation of skew spectra relatively general we implement the formula
where (and equivalently ) is the Wigner-3 symbol
where , and specify the spin-weights7 of the fields being considered, satisfying (conservation of spin). This lets the user compute spin-weighted versions of the skew spectra statistics, which were introduced recently in Roskill et al. (2026). The user can provide a given bispectrum of Eq. (14) and can choose which filters to include on the two legs of the bispectrum, encoded in and . The filters can be used to isolate different scales of interest. We precompute the Wigner-3 symbols needed for the skew spectra using pystools [85]; this is a fixed cost independent of the main calculation. The filters are most commonly top-hats over a band ,
selecting the scales retained in the squared field. Since one might be interested in differentiating with respect to the filters, e.g. to optimise the Fisher information of these statistics, we also provide a smooth band,
with and a ramp width in multipoles. We make it straightforward to implement other filters.
Evaluating the skew spectra requires a double sum over and , which is particularly expensive for wide filters. To speed it up, we provide the option to interpolate the bispectrum on a grid of and values chosen by the user, since the best choice depends on the scales the filter probes and on the accuracy required. Unlike for the other statistics, we do not recommend precision settings, instead we provide a detailed tutorial showing how to choose them for specific cases.
Aperture Statistics
bihalofit-JAX also provides support for third-order aperture statistics [73, 25, 55]. Examples are the mass-aperture statistics, which are built from the weak-lensing convergence of a tomographic bin at sky position , the line-of-sight integral of the matter overdensity weighted by the lensing kernel of Eq. (16) (in the flat-sky approximation),
where is the matter density contrast at transverse comoving position and comoving distance . The third-order aperture-mass statistic is the three-point correlation function of the aperture mass, , a filtered version of the convergence field for a given aperture scale :
where is the filter. One can show that
where is the Fourier-space representation of the filter and is the weak lensing convergence bispectrum (in the flat sky approximation) defined in Eq. (14). We provide functionality for the Crittenden et al. [25] aperture filter8, given by . We implement a general third-order aperture statistic (see e.g. Schneider & Watts [74]; Heydenreich & Linke [42]) by allowing for mixed tracer objects
where closes the Fourier triangle and is the relative angle. Note that we have re-written the integration variables to be in terms of .
In the case of the Crittenden filter, the integrand is a product of three sharply peaked functions: is maximal at , so leg draws its signal from . Only two of those peaks can be targeted directly in its numerical computation. Once and are chosen, follows from the triangle closure, and for a ‘squeezed’ configuration such as the third filter needs , which the inequality permits only for
Given that is large, the signal therefore resides in a region around , which narrows as and increase. This makes a fixed grid on and highly inaccurate for squeezed configurations, prompting codes to use an adaptive integration scheme that refines the grid where more resolution is needed. This is shown for a given grid of and in the top row of Figure 4.
Figure 4. The integrand in the plane, with the bispectrum set to unity and integrated out on a fine uniform grid, for an equilateral, a scalene and a squeezed aperture triplet (left to right). Quadrature nodes are overlaid in cyan: sampled on and independently (top) and on and the ratio (bottom).
We would like to work with a fixed grid, rather than use an adaptive scheme since we want to limit as far as possible the host-to-device transfers which slow down our code and make it less useful for GPU work. To make this possible we replace the integration variable by the ratio , such that the integral becomes
with . Figure 4 shows why this is the natural coordinate. The thin region of signal now sits at the fixed, known location instead of moving with and , and is covered by construction: carries a global Gauss-Legendre rule of nodes in over $1\leq\ell_{1}\leq10/\theta_{\min}$, with the smallest aperture, while the nodes are placed in panels of two GL nodes each, spaced geometrically in from to and mirrored about , which spans Eq. (27) over the whole range, and carries a GL rule of nodes over . By default we set , and $N_{\varphi}=64 ({xref}Appendix B.3). This setup enables a straightforward JIT compilation and fast computation in JAX, forming the key numerical improvement compared to other implementations which we show explicitly in {xref}Section 4`.
Benchmarks
Benchmark setup
Comparison codes and settings
We compare bihalofit-JAX with independent implementations of the BiHalofit fitting formula9 in speed and numerical precision. This is distinct from the physical accuracy, which is set by the formula itself. We include in this comparison: the original code of Takahashi et al. [82] referred to hereafter as T20; fastnc (Sugiyama et al. [79]); the C++ (CPU) and CUDA (GPU) builds of threepoint (Heydenreich & Linke [42]; Heydenreich et al. [43])10; and its Python/numba port threepoint-py11 (Linke & Burger [54]). They differ in how they compute and (Eqs. (2)–(4)) and in how they batch and parallelise the calculation. T20 is a standalone program whose cosmology and redshift are fixed at compile time, so we compile it as a library with added entry points that set the cosmology and pass the linear power spectrum as a table; the fitting formula is unchanged. The other codes are driven through their public interfaces.
We use an NVIDIA RTX PRO 6000 Blackwell GPU and an AMD EPYC 9654 CPU, restricted to 24 of its 96 cores, with JAX 0.4.38, CUDA 12.9 for the GPU build of threepoint and GCC 11.5 for the C and C++ codes.
Only bihalofit-JAX evaluates several cosmologies in one call. The other codes run one cosmology at a time, so their time for cosmologies is times that for one13. Within a cosmology, threepoint uses OpenMP in its set-up and aperture statistics. fastnc uses threads for and one core for the bispectra, and threepoint-py and T20 run on one core.
We use syren-new as the linear power spectrum throughout (except for threepoint-py which computes its own E&H spectrum), since it runs in both float32 and float64 and so allows comparisons at the precision of the codes that run only in float64. The backends are
compared in Appendix C. We exclude build and compilation times, since this is a one-off cost that is negligible over an MCMC run: for bihalofit-JAX it is 1–3 s for the matter bispectrum, 4–7 s for and 25–40 s for the skew spectra and . We include per-cosmology setup, which an MCMC run pays at every step, such as the bispectrum precomputation of threepoint-py and the start-up of threepoint, which runs one process per cosmology. The timing of bihalofit-JAX includes evaluating the linear power spectrum. The codes that accept one (T20, fastnc and threepoint) are instead given each cosmology’s syren-new spectrum as a precomputed table on the default grid of bihalofit-JAX (below), which is not included in their comparison. threepoint-py cannot take a table and computes its own E&H spectrum as part of its set-up.
With regard to precision, bihalofit-JAX is timed at the following settings: Newton iterations, GL nodes over , uniformly spaced redshifts up to for , and log-spaced points over . Every code reads on this grid, in the timings and in the accuracy comparisons. The other codes use their default settings. Some of these are less accurate than typical settings of bihalofit-JAX (Appendix B), and matching its accuracy would make them slower. We keep these defaults because a lower numerical precision can still be subdominant to the physical accuracy of BiHalofit (making it a reasonable choice), and to avoid modifying core functions of the other codes. The other codes evaluate the Limber approximation at (flat sky), which we use in bihalofit-JAX for the sake of comparison, although it is possible to use (curved sky) instead.
Cosmologies and source distributions
All timings and comparisons use one set of 1000 cosmologies, drawn as a Latin hypercube over the sampling box of the simulations on which BiHalofit was calibrated (Takahashi et al. [82]) and kept only where they lie inside the training range of syren-new (last column of Table 1, with massless neutrinos). This is with the exception of the CPU version of threepoint, whose projection assumes a CDM expansion history: it is compared at . A timing with cosmologies uses the first , and the codes that run one cosmology at a time are timed on the first (, , , , , ). The matter bispectrum is compared on all 1000 cosmologies and the projected statistics on the first 30 (calculations are more expensive so we avoid making as many calls), each with its own Smail source distribution,
with drawn over , and . The same is used on all three legs, tabulated from to on 1001 linearly spaced points and passed to every code. Timings of the lensing statistics use the first cosmology’s for all cosmologies, since bihalofit-JAX fixes the source distribution at compilation. The results in this section are therefore valid for this set of source distributions, and care must be taken particularly when using very narrow or high redshift distributions.
Matter bispectrum
We time the matter bispectrum at for a fixed set of 10,160 triangles14 (triangles formed from 75 logarithmically-spaced wavenumbers between 0.01 and ), for one and for 500 cosmologies (described in § 4.1.2). For one cosmology bihalofit-JAX takes ms and ms on CPU and GPU respectively in float32, times faster than the fastest other implementation, T20, and times faster than the slowest (threepoint_py). At this scale the GPU is slower than the CPU because the overhead of launching the kernel dominates the cost of the calculation. The advantage of having a GPU compatible code becomes clear when evaluating many cosmologies at once, where the GPU can batch the calculations: for 500 cosmologies it takes ms on GPU ( ms on CPU), against s for T20, a speed-up of , and against threepoint-py. These results are summarised in Table 2.
| Stat. | Workload | bihalofit-JAX [ms] | threepoint [ms] | threepoint_py [ms] | fastnc [ms] | T20 [ms] | ||||||
| GPU | CPU | GPU | CPU | CPU | CPU | CPU | ||||||
| fp32 | fp64 | fp32 | fp64 | fp64 | fp64 | fp64 | fp64 | fp64 | ||||
| 10,160 | 1 | 1.44 | 1.52 | 0.932 | 1.41 | 304 | 1,615 | 1,910 | 45.8 | 14.7 | ||
| (triangles) | 500 | 1.75 | 15.3 | 62.7 | 146 | 152,030 | 807,459 | 955,239 | 22,910 | 7,353 | ||
| 9,799 | 1 | 2.48 | 9.11 | 25.3 | 43.7 | 367 | 1,081 | 50,843 | 1,139 | – | ||
| (triangles) | 500 | 83.4 | 2,741 | 8,514 | 17,060 | 183,534 | 540,428 | 569,289 | – | |||
| 39 | 1 | 7.66 | 163 | 10,125 | 9,870 | – | – | – | – | – | ||
| (multipoles) | 500 | 1,399 | 73,913 | 263,036 | 507,975 | – | – | – | – | – | ||
| 84 | 1 | 5.95 | 252 | 1,059 | 1,506 | 67,663 | 148,343 | 71,256 | 20,283 | – | ||
| (triplets) | 500 | 2,113 | 143,529 | 400,378 | 853,978 | – |
Table 2. Wall time of the statistics considered in this work (matter bispectrum, lensing bispectrum, skew spectra and mass-aperture statistics) across different implementations. These are evaluated for one and 500 cosmologies, for the devices (CPU/GPU) and floating-point precision available to the respective codes. The matter bispectrum is evaluated at . The missing entries reflect the fact that the code does not compute the statistic: only bihalofit-JAX computes skew spectra, and T20 computes only the matter bispectrum. The 500 cosmologies run in sequential batches to fit in GPU memory: 250 cosmologies per batch for and the float32 skew spectra, 25 for the float64 skew spectra and the float32 , and 12 for the float64 . 500 times the time for one cosmology, as these codes run one cosmology at a time.
To pin down the numerical differences between the codes we evaluate the 273 closed triangles of 19 logarithmic -bins in () at on all 1000 cosmologies of the benchmark set (§ 4.1.2). Every code receives the same linear power spectrum table and the that bihalofit-JAX uses in the formula (the requested times the linear growth); threepoint_py is compared with bihalofit-JAX run on its E&H spectrum. Figure 5 shows the fractional differences between the codes. We find that T20 and threepoint_py agree with bihalofit-JAX to better than 0.02% on average (maximum 0.08%) at every redshift, and fastnc to 0.02% (maximum 0.2%). The CPU build of threepoint agrees to 0.01% at but differs by 0.7% on average at (maximum 1.2%). We emphasise that this is at the default settings of bihalofit-JAX (§ 4.1.1).
Figure 5. Mean (solid) and maximum (dashed) fractional differences between independent implementations and bihalofit-JAX against . This is shown for an average over the 1000 cosmologies of the benchmark set and the triangles in each bin, at four redshifts (), for the syren-new linear power spectrum.
Lensing bispectra
We calculate the weak-lensing bispectrum (without intrinsic alignments) for the auto-correlation of a single source population, on the 9,799 triangles, , formed from 62 log-spaced integer multipoles between and 1000. threepoint and fastnc are given the syren-new spectrum as a table together with , and scale it to each redshift with a linear growth factor.
For a single cosmology bihalofit-JAX computes in ms on GPU and ms on CPU in float32, at least times faster than the fastest other code, threepoint on GPU, and for 500 cosmologies at least times faster (Table 2). Note that the GPU is faster than the CPU for the weak-lensing bispectrum considered here, in contrast to the matter bispectrum (§ 4.2), because the cost of launching the kernel is now subdominant to the cost of the calculation.
To assess the differences between the codes, we evaluate the weak-lensing bispectrum for the cosmologies and source distributions described in § 4.1.2, taking the mean and maximum fractional differences over the set of results. We find that the CPU version of threepoint agrees with bihalofit-JAX to 0.3% on average (at most 1.4%; Figure 6, left), and its GPU build differs by 7% on average (at most 19%). fastnc, at settings chosen to agree with threepoint to about 1% but with its default line-of-sight redshift bins, agrees to 3% on average (at most 20%), and threepoint_py to 0.13% (at most 2.7%). Note that this comparison is for the default accuracy settings of bihalofit-JAX, as described in § 4.1.1.
Figure 6. Mean (solid) and maximum (dashed) fractional differences compared to bihalofit-JAX (at float64) for the lensing bispectrum against (left, in 12 logarithmic bins of the 9,799 triangles) and for against the largest aperture of the triplet (right, for 84 triplets). This is calculated over the 30 cosmologies of § 4.1.2, at the drawn except for the CPU build of threepoint, which is at .
Skew spectra
To examine the performance of the skew spectra implementation in bihalofit-JAX, we time the skew spectrum for a representative case of a top-hat filter over with 39 output multipoles, with number-count kernels on all three legs (Eq. (18)) with linear bias and a Gaussian redshift distribution, , given by
with and . We keep the other precision settings at their defaults, described in § 4.1.1. The bispectrum is interpolated on 68 nodes per side15, which reproduces the exact double sum to a median error of
0.14% (at most 1%, at , and 0.4% for ). For a single cosmology this takes ms on GPU in float32 and s on a CPU restricted to 24 cores, and Table 2 also gives the times for 500 cosmologies. These times grow quickly if one requests many multipoles over a large filter, even on a GPU in float32. No other code we compare with computes skew spectra.
Mass-aperture statistics
We analyse the performance of the mass-aperture statistics in the various implementations, evaluating Eq. (25) for a set of 84 aperture triplets drawn from . We use the Crittenden filter and the same lensing tracer on all three legs. bihalofit-JAX integrates all triplets on one diagonal grid of GL nodes in , from to with the smallest aperture in radians, ratio panels of two nodes each and angles. The other settings are held at their defaults, as described in § 4.1.1.
threepoint integrates each triplet adaptively up to of that triplet, with 400 redshift nodes over on CPU and the 256 compiled into its GPU build, and is given the apertures largest first, the order in which it is fastest. threepoint_py uses its default settings: a bispectrum table of 20 multipoles and 20 angles over , and 200 redshift points in its Limber integral. For fastnc we use , , 80 logarithmically spaced between and and 60 angles, with its default line-of-sight redshift bins.
For one cosmology, bihalofit-JAX evaluates all 84 triplets in 6 ms on GPU and 1.1 s on CPU in float32. On GPU this is times faster than the threepoint CUDA build, demonstrating the advantage of a fixed grid over an adaptive integrator: one can leverage the fact that GPUs are highly efficient at computing large numbers of operations. threepoint integrates each triplet adaptively, so its cost per triplet grows as the triplet is squeezed, whereas the cost of our fixed grid does not depend on the triplet shape. threepoint_py runs on a single core and repeats a s bispectrum precomputation for every cosmology, whereas our build and compilation are paid once. Even on CPU we find bihalofit-JAX to be times faster than threepoint and times faster than fastnc in float32, the fastest of the other codes ( and times in float64).
Comparing the numerical precision for the cosmologies and source distributions of § 4.1.2, we find that the CPU build of threepoint agrees to 0.4% on average with bihalofit-JAX (Figure 6, right). For 10 of the 2,520 inputs its adaptive integrator returns a wrong value without warning, off by 5–53%, and these set its maximum. The GPU build of threepoint differs from bihalofit-JAX by 6% on average (at most 20%) and returns exact zeros for 10 of the 84 triplets (we exclude these from the comparison). fastnc agrees to 3% on average (at most 17%). threepoint_py, at the default settings its own examples use, differs by 22% on average (at most 200%).
Gradient-Based Inference
Likelihood Construction
This section is intended primarily as a test of the use of bihalofit-JAX in inference. We consider a simplified scenario to test our code against the original T20 code. We run a mock cosmological parameter inference on the weak lensing bispectrum for an autocorrelation of the Smail-type source distribution of Eq. (29) with , , and . We evaluate the Limber integral from to , with linearly spaced redshifts in the T20 evaluation and the default comoving-distance nodes over in bihalofit-JAX (the other precision settings are held at their defaults: , uniformly spaced redshifts up to for , and log-spaced points over ). We create a mock data vector from the BiHalofit prediction using T20, evaluated at a fiducial cosmology of , , , , , , , and . We then project it onto the weak-lensing bispectrum with the Limber integral of Eq. (14), using the lensing kernel of Eq. (16) on all three legs (§ 3.1). The same and kernel are used as in bihalofit-JAX, so that the only difference between the mock and the model is the BiHalofit implementation: T20 for in the data vector and bihalofit-JAX in the model.
Both bihalofit-JAX and T20 use the syren-new linear power spectrum backend, so that the comparison isolates the BiHalofit kernel implementation and the sampler rather than also mixing in a linear power spectrum discrepancy.
We assume for simplicity a diagonal, Gaussian covariance in the flat-sky limit for the binned data vector ([81, 46, 47]),
for each triangle bin , where is the observed lensing power spectrum, the sum of the signal and the shape noise. In the Limber approximation the signal is
with the lensing kernel of Eq. (16) and the nonlinear matter power spectrum. The factor is equal to 1 if all the ’s are different, 2 if two are repeated and 6 if all three are the same, and is the number of Fourier-mode triangles falling in that bin triplet,
with the survey solid angle and the two inner integrals over each bin’s width. We evaluate with the Core Cosmology Library (CCL) ([22]), using its Halofit power spectrum, at the fiducial cosmology, and by direct quadrature over . We then add a shape noise of and a source density of 27 arcmin, and assume a sky fraction ().
The data vector consists of in the 126 closed triangles of 12 logarithmically spaced multipole bins between and , evaluated at the geometric bin centres ( with ). Sampling proceeds on the Gaussian log-likelihood
with the mock data vector above and the model under consideration evaluated at the sampled parameters .
Results
We sample the two cosmological parameters that are important for the lensing-bispectrum, and (the mock has , so ), with and fixed at their fiducial values16. The priors are uniform in and over , the validity range of the syren-new linear power spectrum (Table 1), and , which takes the lower bound of BiHalofit’s calibrated range. We use two independent samplers on this likelihood: the No-U-Turn Sampler (NUTS) via numpyro (Phan et al. [65]), using exact gradients of the likelihood from jax.grad, and an affine-invariant ensemble sampler via emcee (Foreman-Mackey et al. [33]) as a gradient-free comparison. Additionally, we perform a Fisher-matrix forecast (Fisher [31]; Tegmark et al. [83]),
where is the vector of parameters and the covariance. We compute the derivatives via jax.jacfwd. Finally, we also run emcee directly on the original, non-differentiable T20 code. Note that we use float64 for bihalofit-JAX paired with NUTS since we found gradients to be more stable at this precision (it is run in float32 with emcee). All four recover the fiducial cosmology within their statistical uncertainty, and their marginal uncertainties agree closely with one another, as shown in Figure 7.
Figure 7. Posterior constraints on , with , recovered from the mock lensing bispectrum data vector with and fixed. bihalofit-JAX with NUTS is shown in grey, bihalofit-JAX with emcee in red, T20 with emcee in dark green, and the Fisher forecast is shown in blue. The dotted lines mark the injected cosmology. All four agree and recover the injected cosmology to better than .
The samplers work in the logarithms of the parameters, . NUTS runs 8 chains with 600 warm-up steps and a target acceptance probability of 0.8, drawing in chunks of 500 until the chains converge. Both emcee runs, with bihalofit-JAX and with T20, use 32 walkers for the same 1000 steps. For each parameter we calculate the effective sample size, the number of statistically independent samples in the chains (Gelman et al. [35]),
where is the number of chains (or walkers), the number of post-warm-up steps per chain, and the integrated autocorrelation time. We report the minimum over the two parameters.
The lensing bispectrum alone leaves a strong degeneracy between and , consistent with the well-known bispectrum degeneracy direction. This causes problems for NUTS, so we apply a standard covariance-whitening (Cholesky-decomposition) approach (Lewis & Bridle [51]; Brooks et al. [13]; Lewis [48]), with the covariance obtained analytically from the Fisher matrix evaluated at the fiducial cosmology
where is the fiducial cosmology, and the Cholesky factor.
Overall we find that bihalofit-JAX with NUTS draws samples (minimum ESS 3277) in 95.4 s, and bihalofit-JAX with emcee draws steps (minimum ESS 3712) in 14.0 s. This is shown in Table 3. We find that emcee is both faster in wall-clock time and more efficient in ESS/s on this low-dimensional posterior because of both the increased cost of computing derivatives and the precision required to compute them (we use float64 with NUTS). T20 with emcee, run for the same 1000 steps with 32 processes, needs 5335 s to reach a comparable ESS, which is slower in ESS/s than bihalofit-JAX with emcee despite parallelising the model calls across 32 processes. This is because the bihalofit-JAX model call is vectorised and GPU-optimised. Independent comparisons of gradient-based and gradient-free sampling on cosmological likelihoods report a comparable finding (Reymond et al. [69]; Mootoovaloo et al. 2024; Ruiz-Zapatero et al. [72]): once the cost of the gradient is included, the advantage of gradient-based samplers is modest, or absent, at low to moderate dimensionality, and it is expected to reassert
| Code | Sampler | Samples | Wall time [s] | Min. ESS | ESS/s | Relative ESS/s |
| bihalofit-JAX | emcee | 14.0 | 3712 | 265 | 1 | |
| bihalofit-JAX | NUTS | 95.4 | 3277 | 34.3 | 0.13 | |
| T20 | emcee | 5335 | 3292 | 0.617 | 0.0023 |
caption: Table 3. Sampling efficiency for the mock inference of § 5. The samples column gives the number of chains (walkers) times the samples in each; both emcee runs take 1000 steps. The minimum ESS is over (, ), and the relative ESS/s is normalised to bihalofit-JAX with emcee. Wall times include compilation and, for NUTS, warm-up. The bihalofit-JAX runs use the GPU of § 4.1.1 (emcee in float32, NUTS in float64). For T20, the 32 CPU processes are run in float64.
:::
itself at higher dimensionality, where ensemble-sampler acceptance rates degrade sharply.
Discussion and Conclusion
In this paper we have presented a new open source code, bihalofit-JAX, for the matter bispectrum and related projected statistics such as projected bispectra, skew spectra and aperture statistics. Bispectrum-related statistics are notoriously more complicated and expensive to compute, leading to intricate approaches such as neural network emulators which are designed to replace the numerical calculations. We have shown here that these emulators are in fact not needed for these types of problems, where the calculations can be made far more efficient and optimised for GPUs. We have achieved this goal by utilising fixed grids which can be evaluated extremely efficiently on GPUs, and designing carefully around the differentiability of the code (care has to be taken beyond just re-writing codes in JAX). This can be seen very clearly by comparing our code to other implementations, where our code computes the matter bispectrum for 500 different cosmologies in ms, around times faster than the next fastest implementation and times faster than the slowest.
The BiHalofit formula has been re-implemented many times in various public and private codes, and we aim to provide a better validated version for the community to use. This code will be useful for many types of cosmological analyses, such as the construction of emulators for the matter bispectrum (where emulators are more relevant due to expensive simulations required to generate accurate nonlinear predictions) which will greatly benefit from simpler, fast models that can be used to train against as a baseline. bihalofit-JAX could present useful progress in analytical understanding of the constraining power and degeneracy-breaking potential of different bispectrum-based statistics applied to stage-IV surveys.
Several improvements remain possible. The main limitation of our approach is the use of fixed integration grids: evaluating the formulae far outside the regime we tested could silently degrade the precision. We validated the precision settings over Latin hypercubes of inputs in Appendix B (for the aperture statistics for lensing only, the case the other codes can check), but a more robust implementation would refine the grids adaptively, in a way that remains efficient on GPUs and limits host-to-device transfers. Whether such a scheme works reliably across the full parameter space would need to be checked carefully. One other small point worth making is that the code could be made more memory efficient by splitting the calculation into chunks. This would be important for the skew spectra, where the large double sum over multipoles is memory intensive for GPU work.
The code also computes one type of statistic at a time, for a single redshift distribution in the case of projected statistics. Many analyses combine several tracers in one data vector, and we expect the code could be batched more efficiently over tracers, which we plan to implement in a future release.
The computation could be accelerated further by emulating the nonlinear scale, , and the effective spectral index, , of Eqs. (2) and (4). Symbolic regression, as in Bartlett et al. [6], can give simple, differentiable and extremely fast approximations to these intermediate quantities. We do not adopt this here because the code is already fast and this way keeps numerical control. Emulating the full BiHalofit formula would be much harder: it would need a large network and training set, and would likely be slower (because of the number of nodes) and less accurate than emulating the intermediate quantities. A flexible code is also easier to modify than an emulator is to retrain, for example to inject a nonlinear power spectrum in place of the linear one. Related to this, it might be worth also providing utility in a future version to run the linear power spectrum backend directly with CLASS or CAMB, if speed is less of a concern but higher fidelity results are required, e.g. over a range of cosmologies outside the training range of the emulated backends.
Availability
bihalofit-JAX is open source under the MIT licence and available at https://github.com/AlexRossell/bihalofit-jax. It is available on PyPI and can be installed with pip install bihalofit-jax, with the optional baccoemu backend enabled by installing bihalofit-jax[baccoemu]. The repository contains the documentation and tutorial notebooks for each statistic in this paper. Software: JAX (Bradbury et al. [11]), NumPy (Harris et al. [39]), baccoemu (Angulo et al. [3]), numpyro (Phan et al. [65]), emcee (Foreman-Mackey et al. [33]), GetDist (Lewis (2019)), CCL (Chisari et al. [22]), syren-new (Sui et al. [80]) and pyshtools (Wieczorek & Meschede [85]). The codes compared in § 4 are used as described in § 4.1, at the following versions: the BiHalofit code of Takahashi et al. [82] as released on the authors’ website, fastnc v1.2.3, threepoint-py v1.0.0 (Linke & Burger [54]), and threepoint at commit 08de964 for the CPU build and 33c389b for the GPU build.
Acknowledgements
We thank Pedro Ferreira for encouraging us to write this paper, as well as Deaglan Bartlett, Christopher Everett and David Alonso, for interesting discussions. We thank Andrina Nicola and Léa Harscouet for making available their filter-squared bispectrum code. AR acknowledges support from STFC. MZ acknowledges that the project that gave rise to these results received the support of a fellowship from the ‘La Caixa’ Foundation (ID 100010434); the fellowship code is LCF/BQ/PI25/12100027. We acknowledge the use of the DIPC Supercomputing Center and thank Raúl Angulo for the use of the new GPU. The software development for this work was assisted by Claude Code, for which we take full responsibility. The paper was written by us with minimal assistance from Large Language Models.
Appendix
Fitting-Formula Coefficients
BiHalofit Fitting-Formula Coefficients
Using for the effective spectral index, , , and the triangle-shape parameters , of § 2, the coefficients of Eqs. (8)–(10) are power laws, most conveniently written in log form, matching the presentation in Takahashi et al. [82]. The fitting parameters of the 1-halo term, , are
and those of the 3-halo term, , are
bihalofit-JAX evaluates the minimisation of Eq. (41) with a smooth-min, to keep derivatives continuous.
Baryonic-Feedback Correction Coefficients
Eq. (13) gives the baryon-feedback ratio, where Takahashi et al. [82] fits all of these as functions of the scale factor , apart from the constant exponents and ,
As noted in § 2, the fit is calibrated only to .
Precision settings
This appendix tests the precision settings of the three numerical components of the pipeline: the BiHalofit kernel (§ 2.3), the projection integral (§ 3.1) and the aperture-mass integral (§ 3.3).
BiHalofit kernel
The BiHalofit formula in bihalofit-JAX is evaluated on a linear power spectrum grid of points, and its solve takes Newton iterations (§ 2.3). We test here the convergence of these precision parameters for the syren-new linear power spectrum backend, since baccoemu has a fixed . We find similar results for the E&H backend. To test the convergence of these parameters over a robust range of inputs we generate 1000 points of a Latin hypercube of cosmologies in the intersection of the training ranges of syren-new and BiHalofit, shown in the last column of Table 1. We evaluate BiHalofit at on all 542 closed triangles of 25 logarithmic -bins in (). Figure 8 shows the relative error of against a reference with and , varying one setting at a time (every grid is log-spaced over ), in float32 and float6417. The error falls rapidly with and reaches machine precision at , and at the grid error is on average and at most .
Figure 8. Relative error of the BiHalofit matter bispectrum against Newton iteration count (left) and linear power spectrum grid density (right). Solid lines with markers are the mean and dashed lines the maximum over the input cosmologies, triangles and redshifts.
Projection integral
The accuracy of the Limber integral, Eq. (14), is controlled by the number of GL nodes, . In the case of the projected bispectra one could consider different tracer combinations which might have different convergence properties. We test all twenty tracer combinations considered in this work, with the syren-new backend, in float64 and float32, against in the same precision. In all cases places its GL nodes over . The other settings are converged (, uniformly spaced redshifts up to for , and log-spaced points over the range ). This is shown in Figure 9. Each combination is evaluated on the 1,258 closed triangles, formed from 30 log-spaced integer multipoles between and 1000. We evaluate a 200 point Latin Hypercube over cosmology and redshift distributions. The cosmologies are drawn from the last column of Table 1. Lensing and IA legs use Smail source distributions, Eq. (29), with , and , and the IA redshift index of Eq. (17) is drawn from . Counts legs use Gaussian lens distributions with mean and width . All are tabulated on 5000 linearly spaced points over .
Figure 9. The error in the projected bispectrum for a given number of GL nodes, , used in the numerical evaluation of the integral in Eq. (14), in float64 (left) and float32 (right). We denote for brevity: M for lensing, N for counts, I for intrinsic alignment, K for CMB lensing, one letter per leg. We use the syren-new linear power spectrum. Lines show the mean over the 200-point Latin Hypercube of cosmologies, redshift distributions and triangles, (details elucidated in the text). The black line is the maximum over all combinations, cosmologies and triangles, the dotted line marks 0.1% and the dash-dotted line the default .
The error is set by the number of counts legs, through the width of the lens sample relative to the node spacing. At the worst combination has a mean error of 0.05% (0.001% without a counts leg) and a maximum over all triangles of 2%; at these rise to 2.7% and 60%. The float32 error reaches its floor at .
Mass-aperture quadrature
Figure 10 shows the convergence of the diagonal-grid quadrature of § 3.3 for the mass-aperture statistics , over the 84 aperture triplets drawn from . The grid has GL nodes in over ( for ), panels of two GL nodes each in , spaced geometrically from to and mirrored about (so nodes), and GL nodes over . Each plot of Figure 10 varies one of , and in float32 and float64, with the other two at their defaults (, , ), and compares the results with a float64 reference that is finer on the varied axis only (, or ). Every run, including these references, shares the remaining settings: GL nodes over , , uniformly spaced redshifts up to , log-spaced points over , and tabulated on 1024 linearly spaced points over . This is the same in both test and reference, so that the curve isolates the parameter under consideration. The convergence is tested by computing an average over 200 cosmologies, drawn from the last column of Table 1, each paired with one of ten Smail source distributions (, , ).
Figure 10. Convergence of the quadrature in (left), (centre; nodes) and (right). Each axis is varied with the other two at their defaults and compared with a float64 reference finer on that axis only, using the syren-new linear power spectrum. Blue: float64; orange: float32. Solid lines: mean over triplets, cosmologies and source distributions; dotted: maximum; dashed: 0.1%.
Linear power spectrum backend benchmarks
Relative accuracy
The linear power spectrum (§ 2.2) enters every statistic considered in this work, so it is important to understand what effect any mismodelling there might introduce. To assess this we run bihalofit-JAX at its default settings in float32 (, ), the precision of the baccoemu network, with each backend, and compare E&H and baccoemu with syren-new. For the matter bispectrum (Figure 11), baccoemu differs from syren-new by a mean of 0.2–0.3% (at most 3.3%) and the Eisenstein & Hu spectrum by a mean of 3% (at most 18%), with little dependence on or redshift. For the projected bispectrum (Figure 12) the means are 0.13–0.22% and 1.1–2.8%, largest for the combinations with counts legs (up to 3.2% and 25% at the worst triangle). The skew spectra and aperture statistics are weighted sums over triangles of the same bispectrum, so for the same tracers their differences are expected to be bounded by those of ; this is what we find for the combinations of the convergence tests, with means of 0.1–0.2% for baccoemu and 1.1–2.5% for E&H, and maxima below 1.5% and 13%. These differences isolate the effect of the linear power spectrum and say nothing about the accuracy of BiHalofit against simulations.
Figure 11. Mean (solid) and maximum (dashed) fractional differences of the matter bispectrum for different linear power spectrum backends, compared to the syren-new backend. We show this against for bihalofit-JAX with the Eisenstein & Hu (E&H) and baccoemu linear power spectra, over 1000 cosmologies and the triangles in each bin, at four redshifts. The triangles are those of Figure 5, the cosmologies are those of the benchmark set (§ 4.1) and all runs use float32, the precision of the baccoemu network.
Figure 12. Mean difference of the projected bispectrum for bihalofit-JAX in float32 with the Eisenstein & Hu (left) and baccoemu (right) linear power spectrum, relative to syren-new, averaged over the 200 cosmologies of the convergence tests and the triangles with each , for the twenty tracer combinations (M lensing, N counts, I intrinsic alignment, K CMB lensing) at the default . The black line is the maximum over every combination, cosmology and triangle.
Performance
The methodology of timing here follows the same procedure that was described in § 4. Table 4 gives the wall time of bihalofit-JAX with each backend, for the workloads of § 4. baccoemu costs within 20% of syren-new. The E&H backend is slower on the GPU, by about 2 ms in float32 and 5–7 ms in float64 per call, and within 35% on the CPU. The extra time is the solution of the linear growth ODE, which the other backends avoid: timed alone on the GPU it takes 2–8 ms, against under 0.5 ms for a whole call of the other two.
| Stat. | Workload | syren-new [ms] GPU fp32 | syren-new [ms] GPU fp64 | syren-new [ms] CPU fp32 | syren-new [ms] CPU fp64 | E&H [ms] GPU fp32 | E&H [ms] GPU fp64 | E&H [ms] CPU fp32 | E&H [ms] CPU fp64 | baccoemu [ms] GPU fp32 | baccoemu [ms] CPU fp32 | |
| 10,160 (triangles) | 1 | 1.44 | 1.52 | 0.932 | 1.41 | 3.6 | 8.35 | 0.859 | 1.05 | 1.55 | 0.832 | |
| 500 | 1.75 | 15.3 | 62.7 | 146 | 4.45 | 22.2 | 61.3 | 139 | 1.9 | 57.1 | ||
| 9,799 (triangles) | 1 | 2.48 | 9.11 | 25.3 | 43.7 | 4.57 | 15.5 | 23.5 | 49.8 | 2.51 | 26.4 | |
| 500 | 83.4* | 2,741* | 8,514 | 17,060 | 87.1* | 2,758* | 8,230 | 17,015 | 86.2* | 8,090 | ||
| 39 (multipoles) | 1 | 7.66 | 163 | 10,125 | 9,870 | 11 | 168 | 8,908 | 9,296 | 7.81 | 9,182 | |
| 500 | 1,399* | 73,913* | 263,036 | 507,975 | 1,377* | 74,024* | 237,169 | 477,948 | 1,376* | 240,367 | ||
| 84 (triplets) | 1 | 5.95 | 252 | 1,059 | 1,506 | 8.68 | 257 | 1,417 | 1,499 | 5.96 | 1,125 | |
| 500 | 2,113* | 143,529* | 400,378 | 853,978 | 2,061* | 150,572* | 359,205 | 810,050 | 2,082* | 367,053 |
Table 4. Wall time of bihalofit-JAX for each linear power spectrum backend, measured as in Table 2 (a CPU restricted to 24 cores). baccoemu is listed in float32 only, since its network evaluates in float32. *Runs in the sequential batches of Table 2. The syren-new columns are those of Table 2; each entry is the median over 1–10 processes.
Sui et al. [80] find that syren-new is and times faster than baccoemu on a CPU and a GPU (at 200 wavenumbers, against the 600 that baccoemu always computes), whereas here the two cost the same, since the difference in the cost of their linear power spectra is subdominant in the full calculation. Their CPU times are averaged over calls of one cosmology each and their GPU times are per cosmology in batches of 2000, so most of their difference between CPU and GPU comes from batching; for one cosmology the fixed cost of a GPU call dominates, and we find the CPU faster.
This paper was built using the Open Journal of Astrophysics LaTeX template. The OJA is a journal which provides fast and easy peer review for new papers in the astro-ph section of the arXiv, making the reviewing process simpler for authors and referees alike. Learn more at http://astro.theoj.org.
References
- [1]Abbott, T. M. C., Adamow, M., Aguena, M., et al. 2026, Dark Energy Survey Year 6 Results: Cosmological Constraints from Galaxy Clustering and Weak Lensing, https://arxiv.org/abs/2601.14559
- [2]Alonso, D., Sanchez, J., & Slosar, A. 2019, Monthly Notices of the Royal Astronomical Society, 484, 4127–4151, doi: 10.1093/mnras/stz093DOI
- [3]Angulo, R. E., Zennaro, M., Contreras, S., et al. 2021, MNRAS. https://arxiv.org/abs/2004.06245
- [4]Aricò, G., Angulo, R., & Zennaro, M. 2022, Open Research Europe, 1, 152, doi: 10.12688/openreseurope.14310.2DOI
- [5]Aricò, G., Angulo, R. E., Hernández-Monteagudo, C., Contreras, S., & Zennaro, M. 2021, Monthly Notices of the Royal Astronomical Society, 503, 3596–3609, doi: 10.1093/mnras/stab699DOI
- [6]Bartlett, D. J., Wandelt, B. D., Zennaro, M., Ferreira, P. G., & Desmond, H. 2024a, Astronomy & Astrophysics, 686, A150, doi: 10.1051/0004-6361/202449854DOI
- [8]Bernardeau, F., van Waerbeke, L., & Mellier, Y. 1997, Weak Lensing Statistics as a Probe of Omega and Power Spectrum. https://arxiv.org/abs/astro-ph/9609122
- [9]Bevins, H. T. J., Gessey-Jones, T., & Handley, W. J. 2025, Monthly Notices of the Royal Astronomical Society, 544, 375–390, doi: 10.1093/mnras/staf1590DOI
- [10]Blas, D., Lesgourgues, J., & Tram, T. 2011, Journal of Cosmology and Astroparticle Physics, 2011, 034–034, doi: 10.1088/1475-7516/2011/07/034DOI
- [11]Bradbury, J., Frostig, R., Hawkins, P., et al. 2018, JAX: composable transformations of Python+NumPy programs, http://github.com/jax-ml/jax
- [12]Bridle, S., & King, L. 2007, New J. Phys., 9, 444. https://arxiv.org/abs/0705.0166
- [13]Brooks, S., Gelman, A., Jones, G., & Meng, X.-L. 2011, Handbook of Markov Chain Monte Carlo (Chapman and Hall/CRC), doi: 10.1201/b10905DOI
- [14]Brown, M. L., Taylor, A. N., Hambly, N. C., & Dye, S. 2002, Monthly Notices of the Royal Astronomical Society, 333, 501–509, doi: 10.1046/j.1365-8711.2002.05354.xDOI
- [16]Burger, P. A., Aricò, G., Linke, L., et al. 2026, Astronomy & Astrophysics, 705, A170, doi: 10.1051/0004-6361/202556061DOI
- [17]Cabass, G., Ivanov, M. M., Philcox, O. H. E., Simonović, M., & Zaldarriaga, M. 2022, Physical Review Letters, 129, 201301, doi: 10.1103/physrevlett.129.201301
- [18]Cabass, G., Philcox, O. H. E., Ivanov, M. M., et al. 2025, BOSS Constraints on Massive Particles during Inflation: The Cosmological Collider in Action. https://arxiv.org/abs/2404.01894
- [19]Campagne, J.-E., Lanusse, F., Zuntz, J., et al. 2023, The Open Journal of Astrophysics, 6, doi: 10.21105/astro.2302.05163
- [20]Chen, S.-F., Vlah, Z., & White, M. 2024, JCAP, 11, 012, doi: 10.1088/1475-7516/2024/11/012DOI
- [21]Chiarenza, S., Bonici, M., Camera, S., et al. 2026, Blast.jl: Differentiable Non-Number Power Spectra for Joint Clustering, Shear, and CMB lensing Analyses. https://arxiv.org/abs/2609.01855
- [22]Chisari, N. E., Alonso, D., Krause, E., et al. 2019, The Astrophysical Journal Supplement Series, 242, 2, doi: 10.3847/1538-4365/ab1658
- [23]Chudaykin, A., Ivanov, M. M., Philcox, O. H., & Simonović, M. 2020, Physical Review D, 102, doi: 10.1103/physrevd.102.063533DOI
- [24]Chudaykin, A., Ivanov, M. M., & Philcox, O. H. E. 2025, Reanalyzing DESI DR1: 3 Constraints on Inflation from Galaxy Power Spectra & Bispetrica. https://arxiv.org/abs/2512.04266
- [25]Crittenden, R. G., Natarajan, P., Pen, U.-L., & Theuns, T. 2002, The Astrophysical Journal, 568, 20
- [26]D’Amico, G., Lewandowski, M., Senatore, L., & Zhang, P. 2025, Physical Review D, 111, doi: 10.1103/physrevd.111.063514DOI
- [27]Duane, S., Kennedy, A. D., Pendleton, B. J., & Roweth, D. 1987, Phys. Lett. B, 195, 216, doi: 10.1016/0370-2693(87)91197-XDOI
- [28]Eisenstein, D. J., & Hu, W. 1998, ApJ, 496, 605. https://arxiv.org/abs/astro-ph/9710912
- [31]Fisher, R. A. 1935, Journal of the Royal Statistical Society, 98, 39. http://www.jstor.org/stable/2342435
- [32]Foreman, S., Coulton, W., Villasca-Navarro, F., & Barreira, A. 2020, Monthly Notices of the Royal Astronomical Society, 498, 2887–2911, doi: 10.1093/mnras/staa2523DOI
- [33]Foreman-Mackey, D., Hogg, D. W., Lang, D., & Goodman, J. 2013, PASP, 125, 306. https://arxiv.org/abs/1202.3665
- [34]García-García, C., Zapatero, J. R., Alonso, D., et al. 2021, JCAP, 10, 030, doi: 10.1088/1475-7516/2021/10/030
- [35]Gelman, A., Carlin, J. B., Stern, H. S., et al. 2013, Bayesian Data Analysis, 3rd edn., Chapman & Hall/CRC Texts in Statistical Science Series (Boca Raton, Florida: CRC). https://stat.columbia.edu/~gelman/book/
- [39]Harris, C. R., et al. 2020, Nature, 585, 357, doi: 10.1038/s41586-020-2649-2
- [40]Harscouet, L., Alonso, D., Nicola, A., & Slosar, A. 2026, The Open Journal of Astrophysics, 9, doi: 10.33232/001c.155341
- [41]Harscouet, L., Cowell, J. A., Ereza, J., et al. 2025, The Open Journal of Astrophysics, 8, doi: 10.33232/001c.128309
- [42]Heydenreich, S., & Linke, L. 2023, threepoint: Covariance of third-order aperture statistics, Astrophysics Source Code Library, record ascl:2306.054. http://ascl.net/2306.054
- [43]Heydenreich, S., Linke, L., Burger, P., & Schneider, P. 2023, Astronomy & Astrophysics, 672, A44, doi: 10.1051/0004-6361/202244820
- [44]Hirata, C. M., & Seljak, U. 2004, Phys. Rev. D, 70, 063526. https://arxiv.org/abs/astro-ph/0406275
- [45]Hoffman, M. D., & Gelman, A. 2011, The No-U-Turn Sampler: Adaptively Setting Path Lengths in Hamiltonian Monte Carlo. https://arxiv.org/abs/1111.4246
- [46]Joachimi, B., Shi, X., & Schneider, P. 2009, Astronomy & Astrophysics, 508, 1193–1204, doi: 10.1051/0004-6361/200912906
- [47]Kayo, I., Takada, M., & Jain, B. 2012, Monthly Notices of the Royal Astronomical Society, 429, 344–371, doi: 10.1093/mnras/sts340
- [48]Lewis, A. 2013, Physical Review D, 87, doi: 10.1103/physrevd.87.103529
- [51]Lewis, A., & Bridle, S. 2002, Phys. Rev. D, 66, 103511. https://arxiv.org/abs/astro-ph/0205436
- [52]Lewis, A., Challinor, A., & Lasenby, A. 2000, ApJ, 538, 473, doi: 10.1086/309179
- [53]Limber, D. N. 1953, ApJ, 117, 134, doi: 10.1086/145672
- [54]Linke, L., & Burger, P. 2026, llinkel/threepoint_py: First Release: A python-only code to calculate third-order cosmic shear statistics, v1.0.0, Zenodo, doi: 10.5281/zenodo.19072610
- [55]Linke, L., Pyne, S., Joachimi, B., et al. 2024, Astronomy & Astrophysics, 691, A312, doi: 10.1051/0004-6361/202451032
- [57]LoVerde, M., & Afshordi, N. 2008, Physical Review D, 78, doi: 10.1103/physrevd.78.123506
- [58]McCullagh, N., Jeong, D., & Szalay, A. S. 2015, Monthly Notices of the Royal Astronomical Society, 455, 2945–2958, doi: 10.1093/mnras/stv2525
- [61]Nelson, D., Springel, V., Pillepich, A., et al. 2019, Computational Astrophysics and Cosmology, 6, 2, doi: 10.1186/s40668-019-0028-x
- [65]Phan, D., Pradhan, N., & Jankowiak, M. 2019, arXiv e-prints. https://arxiv.org/abs/1912.11554
- [66]Philcox, O. H. E., & Ivanov, M. M. 2022, Physical Review D, 105, doi: 10.1103/physrevd.105.043517
- [67]Philcox, O. H. E., Ivanov, M. M., Zaldarriaga, M., Simonović, M., & Schmittfull, M. 2021, Physical Review D, 103, doi: 10.1103/physrevd.103.043508
- [68]Piras, D., & Spurio Mancini, A. 2023, The Open Journal of Astrophysics, 6, doi: 10.21105/astro.2305.06347
- [69]Reymond, L., Reeves, A., Zhang, P., & Refregier, A. 2025, SwiftC: fast differentiable angular power spectra beyond Limber. https://arxiv.org/abs/2505.22718
- [70]Robnik, J., Luca, G. B. Di, Silvestri, E., & Seljak, U. 2026, Microcanonical Hamiltonian Monte Carlo. https://arxiv.org/abs/2212.08549
- [72]Ruiz-Zapatero, J., Alonso, D., García-García, C., et al. 2024, The Open Journal of Astrophysics, 7, doi: 10.21105/astro.2310.08306
- [73]Schneider, P., van Waerbeke, L., Jain, B., & Kruse, G. 1998, Monthly Notices of the Royal Astronomical Society, 296, 873, doi: 10.1046/j.1365-8711.1998.01422.x
- [74]Schneider, P., & Watts, P. 2005, Astronomy & Astrophysics, 432, 783–795, doi: 10.1051/0004-6361:20041923
- [75]Scoccimarro, R. 2000, The Astrophysical Journal, 544, 597–615, doi: 10.1086/317248
- [76]Sefusatti, E., Crocce, M., Pueblas, S., & Scoccimarro, R. 2006, Physical Review D, 74, doi: 10.1103/physrevd.74.023522
- [79]Sugiyama, S., Gomes, R. C. H., & Jarvis, M. 2024, Fast modeling of the shear three-point correlation function. https://arxiv.org/abs/2407.01798
- [80]Sui, C., Bartlett, D. J., Pandey, S., et al. 2025, Astronomy & Astrophysics, 698, A1, doi: 10.1051/0004-6361/202452854
- [81]Takada, M., & Jain, B. 2004, Monthly Notices of the Royal Astronomical Society, 348, 897–915, doi: 10.1111/j.1365-2966.2004.07410.x
- [82]Takahashi, R., Nishimichi, T., Namikawa, T., et al. 2020, ApJ, 895, 113, doi: 10.3847/1538-4357/ab908d
- [83]Tegmark, M., Taylor, A. N., & Heavens, A. F. 1997, The Astrophysical Journal, 480, 22–35, doi: 10.1086/303939
- [84]Verdiani, F., Harscouet, L., Zennaro, M., Alonso, D., & Hadzhyska, B. 2026, JCAP, 06, 027, doi: 10.1088/1475-7516/2026/06/027
- [85]Wieczorek, M. A., & Meschede, M. 2018, Geochemistry, Geophysics, Geosystems, 19, 2574, doi: https://doi.org/10.1029/2018GC007529
- [86]Xie, Y., Zhao, R., Gu, G., et al. 2026, Efficient estimators for power spectrum and bispectrum multipole measurements. https://arxiv.org/abs/2605.04864










