betaFeedback

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 1000010000 triangles of the matter bispectrum in ∼1\sim1–2 ms2\ \rm{ms} per cosmology, one to three orders of magnitude faster than other implementations. It agrees numerically with the original BiHalofit code to better than 0.02%0.02\% on average over the cosmologies the formula was calibrated on, where the formula itself is accurate to ∼20%\sim20\% against simulations. It is also efficiently vectorised such that one can compute e.g. 500500 cosmologies in ∼2 ms\sim 2\ \rm{ms}. This speed-up grows even more in the case of the third-order aperture statistics, which we compute in ∼6 ms\sim 6\ \rm{ms} for one cosmology, between 3×1033\times10^3 and 2.4×1042.4\times10^4 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 NN-body simulations. It achieves an accuracy of ∼20%\sim20\% on scales of k<3 h Mpc−1k < 3\,h\,\mathrm{Mpc}^{-1} and redshifts of z=0z = 0–1.51.5 for ww-cold dark matter (wwCDM) cosmologies (ww 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 σ2(R)\sigma^2(R), 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:

⟨δ(k1)δ(k2)δ(k3)⟩=(2π)3δ(3)(k1+k2+k3)Bδ(k1,k2,k3)(1)\langle\delta(\mathbf{k}_1)\delta(\mathbf{k}_2)\delta(\mathbf{k}_3)\rangle= (2\pi)^3\delta^{(3)}(\mathbf{k}_1+\mathbf{k}_2+\mathbf{k}_3)B_{\delta}(k_1,k_2,k_3) \tag*{(1)}

where δ(k)\delta(\mathbf{k}) is the Fourier transform of the matter density contrast, δ(3)\delta^{(3)} is the three-dimensional Dirac delta function (coming from assuming statistical homogeneity of the fields), and Bδ(k1,k2,k3)B_{\delta}(k_1,k_2,k_3) 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 kNLk_{\mathrm{NL}} and effective spectral index neffn_{\mathrm{eff}}, defined by

σ2(kNL−1)=1,(2)\sigma^2(k_{\mathrm{NL}}^{-1}) = 1, \tag*{(2)}
σ2(R)=∫dln⁡k ΔL2(k)e−k2R2,(3)\sigma^2(R) = \int\mathrm{d}\ln k\,\Delta_{\mathrm{L}}^2(k)e^{-k^2R^2}, \tag*{(3)}
neff+3=−dln⁡σ2(R)dln⁡R∣R=kNL−1,(4)n_{\mathrm{eff}}+3 = -\left.\frac{\mathrm{d}\ln\sigma^2(R)}{\mathrm{d}\ln R}\right|_{R=k_{\mathrm{NL}}^{-1}}, \tag*{(4)}

where ΔL2(k)≡k3PL(k)/(2π2)\Delta_{\mathrm{L}}^2(k) \equiv k^3P_{\mathrm{L}}(k)/(2\pi^2) 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 8 h−1 Mpc8\,h^{-1}\,\mathrm{Mpc}, σ8\sigma_8, the energy density fraction of matter, Ωm\Omega_{\mathrm{m}}, and the tilt of the primordial power spectrum, nsn_{\mathrm{s}}, fully parameterise the fitting formula. The BiHalofit bispectrum combines a 1-halo and a 3-halo term,

Bδ(k1,k2,k3)=B1h(k1,k2,k3)+B3h(k1,k2,k3),(5)B_{\delta}(k_1,k_2,k_3) = B_{1\mathrm{h}}(k_1,k_2,k_3) + B_{3\mathrm{h}}(k_1,k_2,k_3), \tag*{(5)}

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 B3hB_{3\mathrm{h}} reduces to on large scales. The 2-halo contribution, which is important on intermediate scales and for squeezed triangles (kmin⁡/kmax⁡≪1k_{\min}/k_{\max}\ll1), is neglected in the formula. Writing qi≡ki/kNLq_i \equiv k_i/k_{\mathrm{NL}} (where i∈{1,2,3}i \in\{1,2,3\}) the 1-halo and 3-halo terms are parameterised as

Figure 2. The 1-halo (B1hB_{1h}) and 3-halo (B3hB_{3h}) terms of the BiHalofit fitting formula, for equilateral triangles at z=0z=0. The tree level bispectrum (BtreeB_{\rm tree}) is shown for comparison. The cosmological parameters are set to: Ωcb=0.3156\Omega_{\rm cb}=0.3156, Ωb=0.0492\Omega_b=0.0492, h=0.6727h=0.6727, ns=0.9645n_s=0.9645, σ8=0.831\sigma_8=0.831, Mν=0.00M_\nu=0.00 eV, w0=−1w_0=-1 and wa=0w_a=0. The linear power spectrum is generated using baccoemu.

B1h(k1,k2,k3)=T(q1)T(q2)T(q3),(6)B_{1\mathrm{h}}(k_1,k_2,k_3) = T(q_1)T(q_2)T(q_3), \tag*{(6)}
T(q)=cnq(anqαn+bnqβn)(1+cnq),(7)T(q) = \frac{c_nq}{(a_nq^{\alpha_n}+b_nq^{\beta_n})(1+c_nq)}, \tag*{(7)}
B3h(k1,k2,k3)=2I(k1)I(k2)I(k3)[F2(k1,k2)+dnq3]PE(k1)PE(k2)+2 perms.,(8)B_{3\mathrm{h}}(k_1,k_2,k_3) = 2I(k_1)I(k_2)I(k_3)\left[F_2(k_1,k_2)+d_nq_3\right]P_{\mathrm{E}}(k_1)P_{\mathrm{E}}(k_2)+2\ \mathrm{perms.}, \tag*{(8)}

where we have defined

I(ki)=11+enqi,(9)I(k_i) = \frac{1}{1+e_n q_i}, \tag*{(9)}
PE(ki)≡1+fnqi21+gnqi+hnqi2PL(ki)+(pnqi)3mnqiμn+nnqiνn11+(pnqi)3.(10)P_E(k_i) \equiv\frac{1+f_n q_i^2}{1+g_n q_i+h_n q_i^2}P_L(k_i) +\frac{(p_n q_i)^3}{m_n q_i^{\mu_n}+n_n q_i^{\nu_n}}\frac{1}{1+(p_n q_i)^3}. \tag*{(10)}

The permutations in Eq. (8) are cyclic over the wavenumbers, and F2F_2 is the second-order perturbation theory kernel,

F2(k1,k2)=57+12cos⁡θ12(k1k2+k2k1)+27cos⁡2θ12,(11)F_2(k_1,k_2)=\frac{5}{7}+\frac{1}{2}\cos\theta_{12}\left(\frac{k_1}{k_2}+\frac{k_2}{k_1}\right)+\frac{2}{7}\cos^2\theta_{12}, \tag*{(11)}

with cos⁡θ12\cos\theta_{12} fixed by the triangle side lengths via the law of cosines. The coefficients (an,bn,cn,αn,βn,γn,dn,en,fn,gn,hn,mn,nn,μn,νn,pn)(a_n,b_n,c_n,\alpha_n,\beta_n,\gamma_n,d_n,e_n,f_n,g_n,h_n,m_n,n_n,\mu_n,\nu_n,p_n) are calibrated against simulations and are fitted power-law functions of neffn_{\rm eff}, log⁡σ8\log\sigma_8, and the triangle-shape parameters r1=kmin⁡/kmax⁡r_1=k_{\min}/k_{\max} and r2=(kmid+kmin⁡−kmax⁡)/kmax⁡r_2=(k_{\rm mid}+k_{\min}-k_{\max})/k_{\max}. 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.

ParameterBiHalofitbaccoemusyren-newBiHalofit ∩\cap baccoemuBiHalofit ∩\cap syren-new
Ωcb\Omega_{\mathrm{cb}}[0.18, 0.45][0.06, 0.7][0.24, 0.40][0.18, 0.45][0.24, 0.40]
Ωb\Omega_{\mathrm{b}}[0.024, 0.082][0.03, 0.07][0.04, 0.06][0.03, 0.07][0.04, 0.06]
hh[0.54, 0.93][0.5, 0.9][0.61, 0.73][0.54, 0.9][0.61, 0.73]
nsn_{\mathrm{s}}[0.916, 1.013]exact[0.92, 1.00][0.916, 1.013][0.92, 1.00]
σ8\sigma_8[0.50, 1.36]exact[0.28, 1.30][0.50, 1.36][0.50, 1.30]
MνM_\nu [eV]0.06[0, 1][0, 0.15]0.060.06
w0w_0[−1.2, −0.8][−2.0, −0.5][−1.3, −0.7][−1.2, −0.8][−1.2, −0.8]
waw_a0[−0.5, 0.5][−0.7, 0.5]00
zz[0, 1.5][0, 9][0, 3][0, 1.5][0, 1.5]
kmax⁡k_{\max} [h Mpc−1h\,\mathrm{Mpc}^{-1}]350933

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 wwCDM simulations of Takahashi et al. [82]. Note that the simulated cosmologies fill only a thin, curved region of this box, with Ωmh2∈[0.130,0.156]\Omega_{\mathrm{m}}h^2 \in[0.130, 0.156]. The BiHalofit σ8\sigma_8 range is converted from AsA_{\mathrm{s}} with the syren-new formula (Sui et al. [80]). Ωcb=Ωm−Ων\Omega_{\mathrm{cb}} = \Omega_{\mathrm{m}} - \Omega_\nu is the cold matter density; the BiHalofit and syren-new bounds are on Ωm\Omega_{\mathrm{m}}, which differs by Ων≲0.004\Omega_\nu\lesssim0.004. The “exact” entries mean the quantity is not bounded.

bihalofit-JAX also accepts a Chevallier–Polarski–Linder (CPL) dark-energy equation of state, w(a)=w0+wa(1−a)w(a)=w_0+w_a(1-a). It enters only through the background expansion, which sets Ωm(z)\Omega_m(z), and the linear growth in the linear power spectrum, so the fitting formula itself is unchanged. The coefficients were calibrated on constant-ww simulations, so wa≠0w_a\ne0 is an extrapolation that has not been validated against simulations; we provide it for generality, e.g. for forecasts or priors that vary waw_a.

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:

Bb(k1,k2,k3)Bδ(k1,k2,k3)=Rb(k1)Rb(k2)Rb(k3),(12)\frac{B_b(k_1,k_2,k_3)}{B_\delta(k_1,k_2,k_3)}=R_b(k_1)R_b(k_2)R_b(k_3), \tag*{(12)}

where BbB_b is the bispectrum including baryonic-feedback. Writing ξ≡log⁡10k\xi\equiv\log_{10}k, the per-leg ratio is

Rb(k)=A0e−(∣ξ−μ0∣/σ0)α0−A1e−((ξ−μ1)/σ1)2+[1+(k/ks)α2]β2.(13)R_b(k)=A_0e^{-(|\xi-\mu_0|/\sigma_0)^{\alpha_0}}-A_1e^{-((\xi-\mu_1)/\sigma_1)^2}+\left[1+(k/k_s)^{\alpha_2}\right]^{\beta_2}. \tag*{(13)}

The amplitudes A0A_0, A1A_1, centroids μ0\mu_0, μ1\mu_1, widths σ0\sigma_0, σ1\sigma_1, and the shape scale ksk_s and slope β2\beta_2 are fitted functions of the scale factor aa alone, and the exponents α0\alpha_0 and α2\alpha_2 are constants; Appendix A.§ 2 gives their explicit form. The correction is calibrated only up to z=5z=5 and is set to Rb=1R_b=1 (no correction) beyond that.

Differentiable Linear Power Spectrum Backends

BiHalofit takes the linear power spectrum PL(k,z)P_L(k,z) 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 PLP_L, 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:

  1. 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 w0waw_0w_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 kk-grid of Nk=600N_k = 600 logarithmically spaced points over 10−4≤k≤50 h Mpc−110^{-4} \le k \le50\,h\,\mathrm{Mpc}^{-1}, 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.

  1. 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 σ8\sigma_8 to AsA_{\mathrm{s}} with the fitting formula of Sui et al. [80], which is accurate to ∼0.1%\sim0.1\%, so, as for the other two backends, we then rescale the spectrum to have exactly the requested σ8\sigma_8. Its cost within the full calculation is similar to that of baccoemu (Appendix C). Like baccoemu, it natively supports massive neutrinos and a w0waw_0w_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 ≲1%\lesssim1\% 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.

  1. 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 w0w_0, waw_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 ∼20%\sim20\% (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 kNLk_{\mathrm{NL}} by bisection against an adaptively integrated σ2(R)\sigma^2(R), independently per redshift and cosmology, our kernel instead uses a safeguarded (bisection-backed) Newton iteration on Eq. (2), evaluated directly on a fixed kk-grid and batched across cosmologies and redshifts. The same Newton derivative then evaluates the neffn_{\mathrm{eff}} integral of Eq. (4). This is a more efficient root-finding method, which converges in around NR∼10N_R \sim10 steps (compared to ∼17\sim17 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 kk 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 PLP_{\mathrm{L}} against log kk, and use the interpolant to evaluate Eq. (10). A resolution of Nk=600N_k = 600 for 10−4≤k≤50 h Mpc−110^{-4} \le k \le50\,h\,\mathrm{Mpc}^{-1} 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.

Example of generating a matter bispectrum prediction using bihalofit-JAX

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 ∼1\sim1–22 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 ℓ≫1\ell\gg1)

Bijk(ℓ1,ℓ2,ℓ3)=∫dχχ4Wi(χ)Wj(χ)Wk(χ)×Bδ(kℓ1,kℓ2,kℓ3;z(χ)),(14)B_{ijk}(\ell_1,\ell_2,\ell_3) = \int\frac{\mathrm{d}\chi}{\chi^4} W_i(\chi)W_j(\chi)W_k(\chi) \times B_{\delta}(k_{\ell_1},k_{\ell_2},k_{\ell_3}; z(\chi)), \tag*{(14)}

where kℓi≡(ℓi+1/2)/χk_{\ell_i} \equiv(\ell_i + 1/2)/\chi and Wi(χ)W_i(\chi) 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

Wcounts(χ)=b ng(z(χ)) H(z(χ))(15)W_{\mathrm{counts}}(\chi) = b\,n_g(z(\chi))\,H(z(\chi)) \tag*{(15)}

for a linear bias, bb. 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 n(z)n(z), the kernel is described by

Wlensing(χ)=32ΩmH02χa(χ)∫z(χ)∞dz′n(z′)χ(z′)−χχ(z′),(16)W_{\mathrm{lensing}}(\chi) = \frac{3}{2}\Omega_m H_0^2 \frac{\chi}{a(\chi)} \int_{z(\chi)}^{\infty} \mathrm{d}z' n(z') \frac{\chi(z')-\chi}{\chi(z')}, \tag*{(16)}

where we have set c=1c = 1. Note that in the full sky there is usually a factor of (ℓ+2)!/(ℓ−2)!(ℓ+1/2)−2\sqrt{(\ell+2)!/(\ell-2)!(\ell+1/2)^{-2}} 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 ℓ≥10\ell\ge10 (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 n(z)n(z) is now a delta function at zsource≈1089z_{\mathrm{source}} \approx1089. We write BγB_\gamma 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

WIA(χ)=fIA(z(χ)) n(z(χ)) H(z(χ)),(17)W_{\mathrm{IA}}(\chi) = f_{\mathrm{IA}}(z(\chi))\,n(z(\chi))\,H(z(\chi)), \tag*{(17)}
fIA(z)=−AIAC1ρcritΩmD(z)(1+z1+zpivot)η,f_{\mathrm{IA}}(z) = -A_{\mathrm{IA}} C_1\rho_{\mathrm{crit}} \frac{\Omega_{\mathrm{m}}}{D(z)} \left(\frac{1+z}{1+z_{\mathrm{pivot}}}\right)^\eta,

where n(z)n(z) is the source distribution, D(z)D(z) the linear growth factor normalised to D(0)=1D(0)=1, C1ρcrit=0.0134C_1\rho_{\mathrm{crit}}=0.0134, zpivot=0.62z_{\mathrm{pivot}}=0.62 and AIAA_{\mathrm{IA}} and η\eta are free parameters.

We evaluate the Limber integral, Eq. (14), with Gauss–Legendre (GL) quadrature in χ\chi. By default we use Nχ=160N_\chi=160 nodes over 10≤χ≤5800 h−1Mpc10 \le\chi\le5800\,h^{-1}\mathrm{Mpc}. 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 z(χj)z(\chi_j) to evaluate the matter bispectrum (BiHalofit), so we calculate (as a default) χ(z)\chi(z) on a grid of Nzbg=2000N_z^{\mathrm{bg}}=2000 uniformly spaced redshifts up to z=10z=10, 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 n(z(χ))n(z(\chi)) at the same comoving distances, so we interpolate (again using a Catmull–Rom spline) the user-inputted n(z)n(z) to the node redshifts z(χj)z(\chi_j). With the default settings the mean error is ≲0.001%\lesssim0.001\% for lensing and IA kernels and ≲0.05%\lesssim0.05\% 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, gg, and take the correlation of this with the original field, from which one can show that

Cℓg2g=∑ℓ1,ℓ2(2ℓ1+1)(2ℓ2+1)4π(ℓ1ℓ2ℓ000)2Bggg(ℓ,ℓ1,ℓ2),(18)C_\ell^{g^2 g} = \sum_{\ell_1,\ell_2} \frac{(2\ell_1+1)(2\ell_2+1)}{4\pi} \begin{pmatrix} \ell_1 & \ell_2 & \ell\\ 0 & 0 & 0 \end{pmatrix}^{2} B_{ggg}(\ell,\ell_1,\ell_2), \tag*{(18)}

where ⟨(g2)ℓmgℓ′m′∗⟩≡δℓℓ′δmm′Cℓg2g\langle(g^2)_{\ell m}g^*_{\ell' m'}\rangle\equiv\delta_{\ell\ell'}\delta_{mm'}C_\ell^{g^2g} defines the angular power spectrum between the two fields (the skew spectrum) and the matrix is the Wigner-3jj symbol which encodes the angular momentum conservation on the sphere.6 Here we have that BgggB_{ggg} 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

Cℓ(jk)i=∑ℓ1,ℓ2(2ℓ1+1)(2ℓ2+1)4πMa(ℓ,ℓ1,ℓ2)Mb(ℓ,ℓ1,ℓ2)×Fℓ1Fℓ2B2jk(ℓ,ℓ1,ℓ2),(19)C_\ell^{(jk)i} = \sum_{\ell_1,\ell_2} \frac{(2\ell_1+1)(2\ell_2+1)}{4\pi} M_a(\ell,\ell_1,\ell_2)M_b(\ell,\ell_1,\ell_2) \times F_{\ell_1}F_{\ell_2}B_{2jk}(\ell,\ell_1,\ell_2), \tag*{(19)}

where MaM_a (and equivalently MbM_b) is the Wigner-3jj symbol

Ma=(ℓ1ℓ2ℓs1,as2,asa),(20)M_a = \begin{pmatrix} \ell_1 & \ell_2 & \ell\\ s_{1,a} & s_{2,a} & s_a \end{pmatrix}, \tag*{(20)}

where s1,as_{1,a}, s2,as_{2,a} and sas_a specify the spin-weights7 of the fields being considered, satisfying s1,a+s2,a+sa=0s_{1,a}+s_{2,a}+s_a=0 (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 Fℓ1F_{\ell_1} and Fℓ2F_{\ell_2}. The filters can be used to isolate different scales of interest. We precompute the Wigner-3jj 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 [ℓlo,ℓhi][\ell_{\mathrm{lo}},\ell_{\mathrm{hi}}],

FℓTH={1,ℓlo≤ℓ≤ℓhi,0,otherwise,(21)F_\ell^{\mathrm{TH}} = \begin{cases} 1, & \ell_{\mathrm{lo}} \le\ell\le\ell_{\mathrm{hi}}, \\ 0, & \text{otherwise}, \end{cases} \tag*{(21)}

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,

Fℓ(ℓlo,ℓhi,w)=σ(ℓ−ℓlo+12w)σ(ℓhi+12−ℓw),(22)F_\ell(\ell_{\mathrm{lo}},\ell_{\mathrm{hi}},w) = \sigma\left(\frac{\ell-\ell_{\mathrm{lo}}+\frac{1}{2}}{w}\right)\sigma\left(\frac{\ell_{\mathrm{hi}}+\frac{1}{2}-\ell}{w}\right), \tag*{(22)}

with σ(x)=(1+e−x)−1\sigma(x)=(1+e^{-x})^{-1} and ww a ramp width in multipoles. We make it straightforward to implement other filters.

Evaluating the skew spectra requires a double sum over ℓ1\ell_1 and ℓ2\ell_2, which is particularly expensive for wide filters. To speed it up, we provide the option to interpolate the bispectrum on a grid of ℓ1\ell_1 and ℓ2\ell_2 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 ii at sky position φ\varphi, the line-of-sight integral of the matter overdensity weighted by the lensing kernel of Eq. (16) (in the flat-sky approximation),

κi(φ)=∫dχ Wlensingi(χ) δ(χφ,χ),(23)\kappa^{i}(\varphi) = \int\mathrm{d}\chi\, W_{\mathrm{lensing}}^{i}(\chi)\,\delta(\chi\varphi,\chi), \tag*{(23)}

where δ(x,χ)\delta(\boldsymbol{x},\chi) is the matter density contrast at transverse comoving position x\boldsymbol{x} and comoving distance χ\chi. The third-order aperture-mass statistic is the three-point correlation function of the aperture mass, MapM_{\mathrm{ap}}, a filtered version of the convergence field for a given aperture scale θ\theta:

Mapi(φ,θ)=∫d2φ′ uθ(∣φ−φ′∣,θ)κi(φ′),(24)M_{\mathrm{ap}}^{i}(\varphi,\theta) = \int\mathrm{d}^{2}\varphi' \, u_{\theta}(\lvert\varphi-\varphi'\rvert,\theta)\kappa^{i}(\varphi'), \tag*{(24)}

where uθu_{\theta} is the filter. One can show that

⟨Map3⟩(θ1,θ2,θ3)=∫d2ℓ1(2π)2d2ℓ2(2π)2Bγ(ℓ1,ℓ2,∣ℓ1+ℓ2∣)×u^(ℓ1θ1)u^(ℓ2θ2)u^(∣ℓ1+ℓ2∣θ3),(25)\langle M_{\mathrm{ap}}^{3}\rangle(\theta_{1},\theta_{2},\theta_{3}) = \int\frac{\mathrm{d}^{2}\ell_{1}}{(2\pi)^{2}} \frac{\mathrm{d}^{2}\ell_{2}}{(2\pi)^{2}} B_{\gamma}(\ell_{1},\ell_{2},\lvert\ell_{1}+\ell_{2}\rvert) \times\hat{u}(\ell_{1}\theta_{1})\hat{u}(\ell_{2}\theta_{2})\hat{u}(\lvert\ell_{1}+\ell_{2}\rvert\theta_{3}), \tag*{(25)}

where u^\hat{u} is the Fourier-space representation of the filter and BγB_{\gamma} 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 u^(η)=12η2e−η2/2\hat{u}(\eta)=\frac{1}{2}\eta^{2}e^{-\eta^{2}/2}. We implement a general third-order aperture statistic (see e.g. Schneider & Watts [74]; Heydenreich & Linke [42]) by allowing for mixed tracer objects

⟨X1X2X3⟩(θ1,θ2,θ3)=28π3∫0∞dℓ1∫0∞dℓ2∫0πdφ ℓ1ℓ2B(ℓ1,ℓ2,ℓ3)u^(ℓ1θ1)u^(ℓ2θ2)u^(ℓ3θ3),(26)\langle X_{1}X_{2}X_{3}\rangle(\theta_{1},\theta_{2},\theta_{3}) = \frac{2}{8\pi^{3}}\int_{0}^{\infty}\mathrm{d}\ell_{1}\int_{0}^{\infty}\mathrm{d}\ell_{2}\int_{0}^{\pi}\mathrm{d}\varphi\,\ell_{1}\ell_{2} B(\ell_{1},\ell_{2},\ell_{3})\hat{u}(\ell_{1}\theta_{1})\hat{u}(\ell_{2}\theta_{2})\hat{u}(\ell_{3}\theta_{3}), \tag*{(26)}

where ℓ3=ℓ12+ℓ22+2ℓ1ℓ2cos⁡φ\ell_{3}=\sqrt{\ell_{1}^{2}+\ell_{2}^{2}+2\ell_{1}\ell_{2}\cos\varphi} closes the Fourier triangle and φ=ϕ2−ϕ1\varphi=\phi_{2}-\phi_{1} is the relative angle. Note that we have re-written the integration variables to be in terms of φ\varphi.

In the case of the Crittenden filter, the integrand is a product of three sharply peaked functions: u^(η)\hat{u}(\eta) is maximal at η=2\eta=\sqrt{2}, so leg ii draws its signal from ℓi≃2/θi\ell_{i}\simeq\sqrt{2}/\theta_{i}. Only two of those peaks can be targeted directly in its numerical computation. Once ℓ1\ell_{1} and ℓ2\ell_{2} are chosen, ℓ3\ell_{3} follows from the triangle closure, and for a ‘squeezed’ configuration such as θ3≫θ1,θ2\theta_{3}\gg\theta_{1},\theta_{2} the third filter needs ℓ3≃2/θ3≪ℓ1\ell_{3}\simeq\sqrt{2}/\theta_{3}\ll\ell_{1}, which the inequality ℓ3≥∣ℓ1−ℓ2∣\ell_{3}\geq\lvert\ell_{1}-\ell_{2}\rvert permits only for

∣ℓ1−ℓ2∣≲2θ3.(27)\lvert\ell_{1}-\ell_{2}\rvert\lesssim\frac{\sqrt{2}}{\theta_{3}}. \tag*{(27)}

Given that θ3\theta_{3} is large, the signal therefore resides in a region around ℓ2=ℓ1\ell_{2}=\ell_{1}, which narrows as ℓ1\ell_{1} and ℓ2\ell_{2} increase. This makes a fixed grid on ℓ1\ell_{1} and ℓ2\ell_{2} 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 ℓ1\ell_{1} and ℓ2\ell_{2} in the top row of Figure 4.

Figure 4. The ⟨Map3⟩\langle M_{\mathrm{ap}}^{3}\rangle integrand in the (ℓ1,ℓ2)(\ell_1,\ell_2) plane, with the bispectrum set to unity and φ\varphi 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 ℓ1\ell_1 and ℓ2\ell_2 independently (top) and on ℓ1\ell_1 and the ratio ρ=ℓ2/ℓ1\rho=\ell_2/\ell_1 (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 ℓ2\ell_{2} integration variable by the ratio ρ=ℓ2/ℓ1\rho=\ell_{2}/\ell_{1}, such that the integral becomes

⟨X1X2X3⟩=28π3∫0∞dℓ1∫0∞dρ∫0πdφ ℓ13ρB(ℓ1,ρℓ1,ℓ3)×u^(ℓ1θ1)u^(ρℓ1θ2)u^(ℓ3θ3),(28)\langle X_{1}X_{2}X_{3}\rangle= \frac{2}{8\pi^{3}}\int_{0}^{\infty}\mathrm{d}\ell_{1}\int_{0}^{\infty}\mathrm{d}\rho\int_{0}^{\pi}\mathrm{d}\varphi\,\ell_{1}^{3}\rho B(\ell_{1},\rho\ell_{1},\ell_{3}) \times\hat{u}(\ell_{1}\theta_{1})\hat{u}(\rho\ell_{1}\theta_{2})\hat{u}(\ell_{3}\theta_{3}), \tag*{(28)}

with ℓ3=ℓ11+ρ2+2ρcos⁡φ\ell_{3}=\ell_{1}\sqrt{1+\rho^{2}+2\rho\cos\varphi}. Figure 4 shows why this is the natural coordinate. The thin region of signal now sits at the fixed, known location ρ=1\rho=1 instead of moving with ℓ1\ell_{1} and θ3\theta_{3}, and is covered by construction: ℓ1\ell_{1} carries a global Gauss-Legendre rule of NℓN_{\ell} nodes in ln⁡ℓ1\ln\ell_{1} over $1\leq\ell_{1}\leq10/\theta_{\min}$, with θmin⁡\theta_{\min} the smallest aperture, while the ρ\rho nodes are placed in NρN_{\rho} panels of two GL nodes each, spaced geometrically in ∣ln⁡ρ∣\lvert\ln\rho\rvert from 3×10−33\times10^{-3} to ln⁡(10/θmin⁡)\ln(10/\theta_{\min}) and mirrored about ρ=1\rho=1, which spans Eq. (27) over the whole ℓ1\ell_{1} range, and φ\varphi carries a GL rule of NφN_{\varphi} nodes over [0,π][0,\pi]. By default we set Nℓ=96N_{\ell}=96, Nρ=48N_{\rho}=48 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 kNLk_{\mathrm{NL}} and neffn_{\mathrm{eff}} (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 NcosmoN_{\mathrm{cosmo}} cosmologies is NcosmoN_{\mathrm{cosmo}} times that for one13. Within a cosmology, threepoint uses OpenMP in its set-up and aperture statistics. fastnc uses threads for ⟨Map3⟩\langle M_{\mathrm{ap}}^{3}\rangle 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 BγB_\gamma and 25–40 s for the skew spectra and ⟨Map3⟩\langle M_{\mathrm{ap}}^{3}\rangle. 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 z=0z=0 syren-new spectrum as a precomputed table on the default kk 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: NR=15N_R=15 Newton iterations, Nχ=160N_\chi=160 GL nodes over 10≤χ≤5800 h−1 Mpc10\leq\chi\leq5800\,h^{-1}\,\mathrm{Mpc}, Nbgz=2000N_{\mathrm{bg}}^z=2000 uniformly spaced redshifts up to z=10z=10 for χ~(z)\tilde{\chi}(z), and Nk=600N_k=600 log-spaced points over 10−4≤k≤50 h Mpc−110^{-4}\leq k\leq50\,h\,\mathrm{Mpc}^{-1}. Every code reads PLP_L 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 ∼20%\sim20\% 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 k=ℓ/χk = \ell/\chi (flat sky), which we use in bihalofit-JAX for the sake of comparison, although it is possible to use k=(ℓ+1/2)/χk = (\ell+1/2)/\chi (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 Λ\LambdaCDM expansion history: it is compared at w0=−1w_0=-1. A timing with NcosmoN_{\rm cosmo} cosmologies uses the first NcosmoN_{\rm cosmo}, and the codes that run one cosmology at a time are timed on the first (Ωcb=0.298\Omega_{\rm cb}=0.298, Ωb=0.047\Omega_{\rm b}=0.047, h=0.696h=0.696, σ8=0.751\sigma_8=0.751, ns=0.937n_{\rm s}=0.937, w0=−1.03w_0=-1.03). 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,

n(z)∝(z/z0)αexp⁡[−(z/z0)β],(29)n(z) \propto(z/z_0)^\alpha\exp\left[-(z/z_0)^\beta\right], \tag*{(29)}

with (z0,α,β)(z_0,\alpha,\beta) drawn over z0∈[0.15,0.60]z_0 \in[0.15,0.60], α∈[1,3]\alpha\in[1,3] and β∈[0.8,2]\beta\in[0.8,2]. The same n(z)n(z) is used on all three legs, tabulated from z=0z=0 to z=5z=5 on 1001 linearly spaced points and passed to every code. Timings of the lensing statistics use the first cosmology’s n(z)n(z) for all NcosmoN_{\rm cosmo} 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 z=1z=1 for a fixed set of 10,160 triangles14 (triangles formed from 75 logarithmically-spaced wavenumbers between 0.01 and 3 h Mpc−13\,h\,\mathrm{Mpc}^{-1}), for one and for 500 cosmologies (described in § 4.1.2). For one cosmology bihalofit-JAX takes ∼0.932\sim0.932 ms and ∼1.4\sim1.4 ms on CPU and GPU respectively in float32, ∼15\sim15 times faster than the fastest other implementation, T20, and ∼103\sim10^3 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 ∼2\sim2 ms on GPU (∼60\sim60 ms on CPU), against ∼7\sim7 s for T20, a speed-up of ∼4×103\sim4 \times10^3, and ∼5×105\sim5 \times10^5 against threepoint-py. These results are summarised in Table 2.

Stat.WorkloadNcosmoN_{\mathrm{cosmo}}bihalofit-JAX [ms]threepoint [ms]threepoint_py [ms]fastnc [ms]T20 [ms]
GPUCPUGPUCPUCPUCPUCPU
fp32fp64fp32fp64fp64fp64fp64fp64fp64
BδB_{\delta}10,16011.441.520.9321.413041,6151,91045.814.7
(triangles)5001.7515.362.7146152,030§^{\S}807,459§^{\S}955,239§^{\S}22,910§^{\S}7,353§^{\S}
BγB_{\gamma}9,79912.489.1125.343.73671,08150,8431,139–
(triangles)50083.4∗^{*}2,741∗^{*}8,51417,060183,534§^{\S}540,428§^{\S}2.54×1072.54 \times10^{7} §^{\S}569,289§^{\S}–
Cℓg2gC_{\ell}^{g_{2}g}3917.6616310,1259,870–––––
(multipoles)5001,399∗^{*}73,913∗^{*}263,036507,975–––––
⟨Map3⟩\langle M_{\mathrm{ap}}^{3}\rangle8415.952521,0591,50667,663148,34371,25620,283–
(triplets)5002,113∗^{*}143,529∗^{*}400,378853,9783.38×1073.38 \times10^{7} §^{\S}7.42×1077.42 \times10^{7} §^{\S}3.56×1073.56 \times10^{7} §^{\S}1.01×1071.01 \times10^{7} §^{\S}–

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 z=1z = 1. 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 BγB_{\gamma} and the float32 skew spectra, 25 for the float64 skew spectra and the float32 ⟨Map3⟩\langle M_{\mathrm{ap}}^{3}\rangle, and 12 for the float64 ⟨Map3⟩\langle M_{\mathrm{ap}}^{3}\rangle. §^{\S}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 kk-bins in [0.01,3] h Mpc−1[0.01,3]\,h\,\mathrm{Mpc}^{-1} (Δln⁡k=0.3\Delta\ln k=0.3) at z∈{0,0.5,1,1.5}z \in\{0,0.5,1,1.5\} on all 1000 cosmologies of the benchmark set (§ 4.1.2). Every code receives the same linear power spectrum table and the σ8(z)\sigma_8(z) that bihalofit-JAX uses in the formula (the requested σ8\sigma_8 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 z=0z=0 but differs by 0.7% on average at z=1.5z=1.5 (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 kmax⁡=max⁡(k1,k2,k3)k_{\max} = \max(k_1, k_2, k_3). This is shown for an average over the 1000 cosmologies of the benchmark set and the triangles in each kmax⁡k_{\max} bin, at four redshifts (z∈{0,0.5,1,1.5}z \in\{0, 0.5, 1, 1.5\}), for the syren-new linear power spectrum.

Lensing bispectra

We calculate the weak-lensing bispectrum BγB_\gamma (without intrinsic alignments) for the auto-correlation of a single source population, on the 9,799 triangles, ℓ1≤ℓ2≤ℓ3≤ℓ1+ℓ2\ell_1 \leq\ell_2 \leq\ell_3 \leq\ell_1+\ell_2, formed from 62 log-spaced integer multipoles between ℓ=20\ell=20 and 1000. threepoint and fastnc are given the z=0z=0 syren-new spectrum as a table together with σ8\sigma_8, and scale it to each redshift with a linear growth factor.

For a single cosmology bihalofit-JAX computes BγB_\gamma in ∼2.5\sim2.5 ms on GPU and ∼25\sim25 ms on CPU in float32, at least ∼150\sim150 times faster than the fastest other code, threepoint on GPU, and for 500 cosmologies at least ∼2×103\sim2 \times10^3 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 BγB_{\gamma} against ℓmax⁡=max⁡(ℓ1,ℓ2,ℓ3)\ell_{\max} = \max(\ell_1, \ell_2, \ell_3) (left, in 12 logarithmic bins of the 9,799 triangles) and for ⟨Map3⟩\langle M_{\mathrm{ap}}^{3}\rangle 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 w0w_0 except for the CPU build of threepoint, which is at w0=−1w_0 = -1.

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 ℓ∈[20,400]\ell\in[20,400] with 39 output multipoles, with number-count kernels on all three legs (Eq. (18)) with linear bias b=1.5b=1.5 and a Gaussian redshift distribution, ng(z)n_g(z), given by

ng(z)=12πσzexp⁡(−(z−zˉ)22σz2),(30)n_g(z)=\frac{1}{\sqrt{2\pi\sigma_z}}\exp\left(-\frac{(z-\bar{z})^2}{2\sigma_z^2}\right), \tag*{(30)}

with zˉ=0.5\bar{z}=0.5 and σz=0.1\sigma_z=0.1. 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 ℓ=20\ell= 20, and 0.4% for ℓ≥50\ell\ge50). For a single cosmology this takes ∼8\sim8 ms on GPU in float32 and ∼10\sim10 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 θ1≤θ2≤θ3\theta_1 \le\theta_2 \le\theta_3 drawn from θ∈{1,2,4,8,16,32,64}\theta\in\{1, 2, 4, 8, 16, 32, 64\}. We use the Crittenden filter and the same lensing tracer on all three legs. bihalofit-JAX integrates all triplets on one diagonal grid of Nℓ=96N_{\ell} = 96 GL nodes in ln⁡ℓ1\ln\ell_1, from ℓ1=1\ell_1 = 1 to 10/θmin⁡10/\theta_{\min} with θmin⁡\theta_{\min} the smallest aperture in radians, Nρ=48N_{\rho} = 48 ratio panels of two nodes each and Nφ=64N_{\varphi} = 64 angles. The other settings are held at their defaults, as described in § 4.1.1.

threepoint integrates each triplet adaptively up to ℓ=10/θmin⁡\ell= 10/\theta_{\min} of that triplet, with 400 redshift nodes over 0≤z≤50 \le z \le5 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 1≤ℓ≤200001 \le\ell\le20000, and 200 redshift points in its Limber integral. For fastnc we use Lmax⁡=30L_{\max} = 30, Mmax⁡=40M_{\max} = 40, 80 logarithmically spaced t1t_1 between 0.1′0.1' and 600′600' 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 ∼104\sim10^4 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 ∼11\sim11 s bispectrum precomputation for every cosmology, whereas our build and compilation are paid once. Even on CPU we find bihalofit-JAX to be ∼140\sim140 times faster than threepoint and ∼20\sim20 times faster than fastnc in float32, the fastest of the other codes (∼100\sim100 and ∼13\sim13 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 z0=0.3z_0 = 0.3, α=2\alpha= 2, and β=1\beta= 1. We evaluate the Limber integral from z=0z = 0 to z=3.5z = 3.5, with nz=200n_z = 200 linearly spaced redshifts in the T20 evaluation and the default Nχ=160N_{\chi} = 160 comoving-distance nodes over 10≤χ≤5800 h−1Mpc10 \le\chi\le5800\,h^{-1}\mathrm{Mpc} in bihalofit-JAX (the other precision settings are held at their defaults: NR=15N_R = 15, Nzbg=2000N^{\mathrm{bg}}_z = 2000 uniformly spaced redshifts up to z=10z = 10 for χ(z)\chi(z), and Nk=600N_k = 600 log-spaced points over 10−4≤k≤50 h Mpc−110^{-4} \le k \le50\,h\,\mathrm{Mpc}^{-1}). We create a mock data vector from the BiHalofit prediction using T20, evaluated at a fiducial cosmology of Ωm=0.3156\Omega_{\mathrm{m}} = 0.3156, Ωb=0.0492\Omega_{\mathrm{b}} = 0.0492, h=0.6727h = 0.6727, ns=0.9645n_s = 0.9645, σ8=0.831\sigma_8 = 0.831, w0=−1w_0 = -1, wa=0w_a = 0, and Mν=0.0 eVM_\nu= 0.0\,\mathrm{eV}. We then project it onto the weak-lensing bispectrum BγB_{\gamma} with the Limber integral of Eq. (14), using the lensing kernel of Eq. (16) on all three legs (§ 3.1). The same χ(z)\chi(z) 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 BδB_{\delta} 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 BγB_{\gamma} data vector ([81, 46, 47]),

Cov⁡ii=s123C~(ℓ1,i)C~(ℓ2,i)C~(ℓ3,i)Ntri(ℓ1,i,ℓ2,i,ℓ3,i),(31)\operatorname{Cov}_{ii} = s_{123}\frac{\widetilde{C}(\ell_{1,i})\widetilde{C}(\ell_{2,i})\widetilde{C}(\ell_{3,i})}{N_{\mathrm{tri}}(\ell_{1,i},\ell_{2,i},\ell_{3,i})}, \tag*{(31)}

for each triangle bin ii, where C~(ℓ)=Cγ(ℓ)+σϵ2/nˉ\widetilde{C}(\ell) = C_{\gamma}(\ell) + \sigma_{\epsilon}^{2}/\bar{n} is the observed lensing power spectrum, the sum of the signal and the shape noise. In the Limber approximation the signal is

Cγ(ℓ)=∫dχχ2Wlensing2(χ)Pδ(ℓ+12χ;χ),(32)C_{\gamma}(\ell) = \int\frac{\mathrm{d}\chi}{\chi^2} W_{\mathrm{lensing}}^2(\chi) P_{\delta}\left(\frac{\ell+ \frac{1}{2}}{\chi}; \chi\right), \tag*{(32)}

with WlensingW_{\mathrm{lensing}} the lensing kernel of Eq. (16) and PδP_{\delta} the nonlinear matter power spectrum. The factor s123∈{1,2,6}s_{123} \in\{1, 2, 6\} is equal to 1 if all the ℓ\ell’s are different, 2 if two are repeated and 6 if all three are the same, and NtriN_{\mathrm{tri}} is the number of Fourier-mode triangles falling in that bin triplet,

Ntri(ℓ1,ℓ2,ℓ3)=Ωs(2π)3∫ℓ1ℓ1′ℓ1′dℓ1′∫ℓ2ℓ2′ℓ2′dℓ2′∫02πdφ 1[∣ℓ⃗1+ℓ⃗2∣∈ℓ3-bin],(33)N_{\mathrm{tri}}(\ell_1,\ell_2,\ell_3) = \frac{\Omega_s}{(2\pi)^3}\int_{\ell_1}^{\ell_1'} \ell'_1\mathrm{d}\ell'_1 \int_{\ell_2}^{\ell_2'} \ell'_2\mathrm{d}\ell'_2 \int_0^{2\pi}\mathrm{d}\varphi\ \mathbf{1}\left[\left|\vec{\ell}_1 + \vec{\ell}_2\right| \in\ell_3\text{-bin}\right], \tag*{(33)}

with Ωs\Omega_s the survey solid angle and the two inner integrals over each bin’s width. We evaluate CγC_{\gamma} with the Core Cosmology Library (CCL) ([22]), using its Halofit power spectrum, at the fiducial cosmology, and NtriN_{\mathrm{tri}} by direct quadrature over (ℓ1′,ℓ2′,φ)(\ell'_1,\ell'_2,\varphi). We then add a shape noise of σϵ=0.26\sigma_{\epsilon} = 0.26 and a source density of nˉ=\bar{n} = 27 arcmin−2^{-2}, and assume a sky fraction fsky=0.4f_{\mathrm{sky}} = 0.4 (Ωs=4πfsky\Omega_{\mathrm{s}} = 4\pi f_{\mathrm{sky}}).

The data vector consists of BγB_\gamma in the 126 closed triangles of 12 logarithmically spaced multipole bins between ℓ=50\ell= 50 and ℓ=2000\ell= 2000, evaluated at the geometric bin centres (ℓ1≤ℓ2≤ℓ3\ell_1 \le\ell_2 \le\ell_3 with ℓ3<ℓ1+ℓ2\ell_3 < \ell_1 + \ell_2). Sampling proceeds on the Gaussian log-likelihood

−2ln⁡L(θ)=∑i1Covii[Bγtruth(ℓ1,i,ℓ2,i,ℓ3,i)−Bγ(ℓ1,i,ℓ2,i,ℓ3,i;θ)]2(34)-2\ln L(\theta) = \sum_i \frac{1}{\mathrm{Cov}_{ii}}\left[B_\gamma^{\mathrm{truth}}(\ell_{1,i},\ell_{2,i},\ell_{3,i}) - B_\gamma(\ell_{1,i},\ell_{2,i},\ell_{3,i};\theta)\right]^2 \tag*{(34)}

with BγtruthB_\gamma^{\mathrm{truth}} the mock data vector above and Bγ(θ)B_\gamma(\theta) the model under consideration evaluated at the sampled parameters θ\theta.

Results

We sample the two cosmological parameters that are important for the lensing-bispectrum, Ωm\Omega_{\mathrm{m}} and σ8\sigma_8 (the mock has Mν=0M_\nu= 0, so Ωm=Ωcb\Omega_{\mathrm{m}} = \Omega_{\mathrm{cb}}), with hh and nsn_{\mathrm{s}} fixed at their fiducial values16. The priors are uniform in ln⁡Ωm\ln\Omega_{\mathrm{m}} and ln⁡σ8\ln\sigma_8 over Ωm∈[0.24,0.40]\Omega_{\mathrm{m}} \in[0.24, 0.40], the validity range of the syren-new linear power spectrum (Table 1), and σ8∈[0.50,1.30]\sigma_8 \in[0.50, 1.30], 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]),

F=(∂Bγ∂θ)TC−1(∂Bγ∂θ),(35)F = \left(\frac{\partial B_\gamma}{\partial\theta}\right)^{\mathsf{T}} C^{-1}\left(\frac{\partial B_\gamma}{\partial\theta}\right), \tag*{(35)}

where θ\theta is the vector of parameters and CC 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 (Ωm,S8)(\Omega_{\mathrm{m}}, S_8), with S8=σ8(Ωm/0.3)0.5S_8 = \sigma_8(\Omega_{\mathrm{m}}/0.3)^{0.5}, recovered from the mock lensing bispectrum data vector with hh and nsn_{\mathrm{s}} 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 0.1σ0.1\sigma.

The samplers work in the logarithms of the parameters, θ=(ln⁡Ωm,ln⁡σ8)\theta= (\ln\Omega_{\mathrm{m}}, \ln\sigma_8). 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]),

ESS≡NcNsτ,(36)\mathrm{ESS} \equiv\frac{N_{\mathrm{c}}N_{\mathrm{s}}}{\tau}, \tag*{(36)}

where NcN_{\mathrm{c}} is the number of chains (or walkers), NsN_{\mathrm{s}} the number of post-warm-up steps per chain, and τ\tau the integrated autocorrelation time. We report the minimum over the two parameters.

The lensing bispectrum alone leaves a strong degeneracy between σ8\sigma_8 and Ωm\Omega_{\mathrm{m}}, 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

θ=θ0+Ly,LLT=F−1(θ0),(37)\theta= \theta_0 + Ly,\qquad LL^{\mathsf{T}} = F^{-1}(\theta_0), \tag*{(37)}

where θ0\theta_0 is the fiducial cosmology, and LL the Cholesky factor.

Overall we find that bihalofit-JAX with NUTS draws 8×5008 \times500 samples (minimum ESS 3277) in 95.4 s, and bihalofit-JAX with emcee draws 32×100032 \times1000 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 ∼8×\sim8\times 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 ∼430×\sim430\times 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

CodeSamplerSamplesWall time [s]Min. ESSESS/sRelative ESS/s
bihalofit-JAXemcee32×100032 \times100014.037122651
bihalofit-JAXNUTS8×5008 \times50095.4327734.30.13
T20emcee32×100032 \times1000533532920.6170.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 (Ωm\Omega_{\mathrm{m}}, σ8\sigma_8), 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 ∼2\sim2 ms, around 4×1034 \times10^3 times faster than the next fastest implementation and 5×1055 \times10^5 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, kNLk_{\mathrm{NL}}, and the effective spectral index, neffn_{\mathrm{eff}}, 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 neffn_{\mathrm{eff}} for the effective spectral index, σ8\sigma_8, Ωm\Omega_{\mathrm{m}}, and the triangle-shape parameters r1r_1, r2r_2 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, T(q)T(q), are

log⁡10an=−2.167−2.944log⁡10σ8−1.106(log⁡10σ8)2−2.865(log⁡10σ8)3−0.310r1γn,(38)\log_{10} a_n = -2.167 - 2.944\log_{10}\sigma_8 - 1.106\left(\log_{10}\sigma_8\right)^2 - 2.865\left(\log_{10}\sigma_8\right)^3 - 0.310r_1^{\gamma_n}, \tag*{(38)}
log⁡10bn=−3.428−2.681log⁡10σ8+1.624(log⁡10σ8)2−0.095(log⁡10σ8)3,(39)\log_{10} b_n = -3.428 - 2.681\log_{10}\sigma_8 + 1.624\left(\log_{10}\sigma_8\right)^2 - 0.095\left(\log_{10}\sigma_8\right)^3, \tag*{(39)}
log⁡10cn=0.159−1.107neff,(40)\log_{10} c_n = 0.159 - 1.107n_{\mathrm{eff}}, \tag*{(40)}
log⁡10αn=min⁡[−4.348−3.006neff−0.5745neff2+10−0.9+0.2neffr22, log⁡10(1−23ns)],(41)\log_{10} \alpha_n = \min\left[-4.348 - 3.006n_{\mathrm{eff}} - 0.5745n_{\mathrm{eff}}^2 + 10^{-0.9+0.2n_{\mathrm{eff}}}r_2^2,\ \log_{10}\left(1-\frac{2}{3}n_s\right)\right], \tag*{(41)}
log⁡10βn=−1.731−2.845neff−1.4995neff2−0.2811neff3+0.007r2,(42)\log_{10} \beta_n = -1.731 - 2.845n_{\mathrm{eff}} - 1.4995n_{\mathrm{eff}}^2 - 0.2811n_{\mathrm{eff}}^3 + 0.007r_2, \tag*{(42)}
log⁡10γn=0.182+0.57neff,(43)\log_{10} \gamma_n = 0.182 + 0.57n_{\mathrm{eff}}, \tag*{(43)}

and those of the 3-halo term, B3hB_{3h}, are

log⁡10dn=−0.483+0.892log⁡10σ8−0.086Ωm,(44)\log_{10} d_n = -0.483 + 0.892\log_{10}\sigma_8 - 0.086\Omega_{\mathrm{m}}, \tag*{(44)}
log⁡10en=−0.632+0.646neff,(45)\log_{10} e_n = -0.632 + 0.646n_{\mathrm{eff}}, \tag*{(45)}
log⁡10fn=−10.533−16.838neff−9.3048neff2−1.8263neff3,(46)\log_{10} f_n = -10.533 - 16.838n_{\mathrm{eff}} - 9.3048n_{\mathrm{eff}}^2 - 1.8263n_{\mathrm{eff}}^3, \tag*{(46)}
log⁡10gn=2.787+2.405neff+0.4577neff2,(47)\log_{10} g_n = 2.787 + 2.405n_{\mathrm{eff}} + 0.4577n_{\mathrm{eff}}^2, \tag*{(47)}
log⁡10hn=−1.118−0.394neff,(48)\log_{10} h_n = -1.118 - 0.394n_{\mathrm{eff}}, \tag*{(48)}
log⁡10mn=−2.605−2.434log⁡10σ8+5.71(log⁡10σ8)2,(49)\log_{10} m_n = -2.605 - 2.434\log_{10}\sigma_8 + 5.71\left(\log_{10}\sigma_8\right)^2, \tag*{(49)}
log⁡10nn=−4.468−3.08log⁡10σ8+1.035(log⁡10σ8)2,(50)\log_{10} n_n = -4.468 - 3.08\log_{10}\sigma_8 + 1.035\left(\log_{10}\sigma_8\right)^2, \tag*{(50)}
log⁡10μn=15.312+22.977neff+10.9579neff2+1.6586neff3,(51)\begin{aligned} \log_{10}\mu_n &= 15.312 + 22.977n_{\mathrm{eff}} + 10.9579n_{\mathrm{eff}}^2 \\ &\quad+ 1.6586n_{\mathrm{eff}}^3, \tag*{(51)} \end{aligned}
log⁡10νn=1.347+1.246neff+0.4525neff2,(52)\log_{10}\nu_n = 1.347 + 1.246n_{\mathrm{eff}} + 0.4525n_{\mathrm{eff}}^2, \tag*{(52)}
log⁡10pn=0.071−0.433neff.(53)\log_{10}p_n = 0.071 - 0.433n_{\mathrm{eff}}. \tag*{(53)}

bihalofit-JAX evaluates the minimisation of Eq. (41) with a C1C^1 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 aa, apart from the constant exponents α0\alpha_{0} and α2\alpha_{2},

A0(a)={0.068(a−0.5)0.47,a>0.50,a≤0.5(54)A_{0}(a)= \begin{cases} 0.068\left(a-0.5\right)^{0.47}, & a>0.5\\ 0, & a\le0.5 \end{cases} \tag*{(54)}
μ0(a)=0.018a+0.837a2,(55)\mu_{0}(a)=0.018a+0.837a^{2}, \tag*{(55)}
σ0(a)=0.881μ0(a),(56)\sigma_{0}(a)=0.881\mu_{0}(a), \tag*{(56)}
α0=2.346,(57)\alpha_{0}=2.346, \tag*{(57)}
A1(a)={1.052(a−0.2)1.41,a>0.20,a≤0.2(58)A_{1}(a)= \begin{cases} 1.052\left(a-0.2\right)^{1.41}, & a>0.2\\ 0, & a\le0.2 \end{cases} \tag*{(58)}
μ1(a)=∣0.172+3.048a−0.675a2∣,(59)\mu_{1}(a)=\left|0.172+3.048a-0.675a^{2}\right|, \tag*{(59)}
σ1(a)=(0.494−0.039a)μ1(a),(60)\sigma_{1}(a)=\left(0.494-0.039a\right)\mu_{1}(a), \tag*{(60)}
ks(a)=29.90−38.73a+24.30a2 [h Mpc−1],(61)k_{\mathrm{s}}(a)=29.90-38.73a+24.30a^{2}\ [h\ \mathrm{Mpc}^{-1}], \tag*{(61)}
α2=2.25,(62)\alpha_{2}=2.25, \tag*{(62)}
β2(a)=0.563α2[(a0.060)0.02+1]−1.(63)\beta_{2}(a)=\frac{0.563}{\alpha_{2}}\left[\left(\frac{a}{0.060}\right)^{0.02}+1\right]^{-1}. \tag*{(63)}

As noted in § 2, the fit is calibrated only to z=5z=5.

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 NkN_{k} points, and its kNLk_{\mathrm{NL}} solve takes NRN_{R} 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 Nk=600N_{k}=600. 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 z=0,0.5,1,1.5z=0,0.5,1,1.5 on all 542 closed triangles of 25 logarithmic kk-bins in [0.01,3] h Mpc−1[0.01,3]\ h\ \mathrm{Mpc}^{-1} (Δln⁡k≃0.23\Delta\ln k\simeq0.23). Figure 8 shows the relative error of BδB_{\delta} against a reference with NR=100N_{R}=100 and Nk=150,000N_{k}=150{,}000, varying one setting at a time (every kk grid is log-spaced over 10−4≤k≤50 h Mpc−110^{-4}\le k\le50\ h\ \mathrm{Mpc}^{-1}), in float32 and float6417. The error falls rapidly with NRN_{R} and reaches machine precision at NR∼12N_{R}\sim12, and at Nk=600N_{k}=600 the grid error is 1.9×10−41.9\times10^{-4} on average and at most 1.8×10−31.8\times10^{-3}.

Figure 8. Relative error of the BiHalofit matter bispectrum against Newton iteration count NRN_{R} (left) and linear power spectrum grid density NkN_{k} (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, NχN_\chi. 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 Nχ=640N_\chi= 640 in the same precision. In all cases NχN_\chi places its GL nodes over 10≤χ≤5800 h−1Mpc10 \leq\chi\leq5800\,h^{-1}\mathrm{Mpc}. The other settings are converged (NR=100N_R = 100, Nzbg=20000N_z^{\mathrm{bg}} = 20000 uniformly spaced redshifts up to z=10z = 10 for χ(z)\chi(z), and Nk=76800N_k = 76800 log-spaced points over the range 10−4≤k≤50 h Mpc−110^{-4} \leq k \leq50\,h\,\mathrm{Mpc}^{-1}). This is shown in Figure 9. Each combination is evaluated on the 1,258 closed triangles, formed from 30 log-spaced integer multipoles between ℓ=20\ell= 20 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 z0∈[0.15,0.60]z_0 \in[0.15, 0.60], α∈[1,3]\alpha\in[1, 3] and β∈[0.8,2]\beta\in[0.8, 2], and the IA redshift index of Eq. (17) is drawn from η∈[−1,1]\eta\in[-1, 1]. Counts legs use Gaussian lens distributions with mean zˉ∈[0.2,0.7]\bar{z} \in[0.2, 0.7] and width σz∈[0.01,0.10](1+zˉ)\sigma_z \in[0.01, 0.10](1 + \bar{z}). All n(z)n(z) are tabulated on 5000 linearly spaced points over 0≤z≤50 \leq z \leq5.

Figure 9. The error in the projected bispectrum Bijk(ℓ1,ℓ2,ℓ3)B_{ijk}(\ell_1,\ell_2,\ell_3) for a given number of GL nodes, NχN_\chi, 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 Nχ=160N_\chi= 160.

The error is set by the number of counts legs, through the width of the lens sample relative to the node spacing. At Nχ=160N_\chi= 160 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 Nχ=80N_\chi= 80 these rise to 2.7% and 60%. The float32 error reaches its floor at ∼10−4%\sim10^{-4}\%.

Mass-aperture quadrature

Figure 10 shows the convergence of the diagonal-grid quadrature of § 3.3 for the mass-aperture statistics ⟨Map3⟩\langle M_{\mathrm{ap}}^3\rangle, over the 84 aperture triplets θ1≤θ2≤θ3\theta_1 \leq\theta_2 \leq\theta_3 drawn from θ∈{1,2,4,8,16,32,64}′\theta\in\{1, 2, 4, 8, 16, 32, 64\}^\prime. The grid has NℓN_\ell GL nodes in ln⁡ℓ1\ln\ell_1 over 1≤ℓ1≤10/θmin⁡1 \leq\ell_1 \leq10/\theta_{\min} (ℓ1≤34,377\ell_1 \leq34,377 for θmin⁡=1′\theta_{\min} = 1^\prime), NρN_\rho panels of two GL nodes each in ∣ln⁡ρ∣|\ln\rho|, spaced geometrically from ∣ln⁡ρ∣=3×10−3|\ln\rho| = 3 \times10^{-3} to ln⁡(10/θmin⁡)\ln(10/\theta_{\min}) and mirrored about ρ=1\rho= 1 (so 2Nρ2N_\rho nodes), and NφN_\varphi GL nodes over 0≤φ≤π0 \leq\varphi\leq\pi. Each plot of Figure 10 varies one of NℓN_\ell, NρN_\rho and NφN_\varphi in float32 and float64, with the other two at their defaults (Nℓ=96N_\ell= 96, Nρ=48N_\rho= 48, Nφ=64N_\varphi= 64), and compares the results with a float64 reference that is finer on the varied axis only (Nℓ=288N_\ell= 288, Nρ=128N_\rho= 128 or Nφ=192N_\varphi= 192). Every run, including these references, shares the remaining settings: Nχ=160N_\chi= 160 GL nodes over 10≤χ≤5800 h−1Mpc10 \leq\chi\leq5800\,h^{-1}\mathrm{Mpc}, NR=15N_R = 15, Nzbg=2000N_z^{\mathrm{bg}} = 2000 uniformly spaced redshifts up to z=10z = 10, Nk=1200N_k = 1200 log-spaced points over 10−4≤k≤104 h Mpc−110^{-4} \leq k \leq10^4\,h\,\mathrm{Mpc}^{-1}, and n(z)n(z) tabulated on 1024 linearly spaced points over 0≤z≤50 \leq z \leq5. 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 (z0∈[0.15,0.60]z_0 \in[0.15, 0.60], α∈[1,3]\alpha\in[1, 3], β∈[0.8,2]\beta\in[0.8, 2]).

Figure 10. Convergence of the ⟨Map3⟩\langle M_{\mathrm{ap}}^{3}\rangle quadrature in NℓN_{\ell} (left), NρN_{\rho} (centre; 2Nρ2N_{\rho} nodes) and NφN_{\varphi} (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 (NR=15N_R = 15, Nk=600N_k = 600), 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 kmax⁡k_{\max} 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 BijkB_{ijk}; 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 kmax⁡=max⁡(k1,k2,k3)k_{\max} = \max(k_1, k_2, k_3) for bihalofit-JAX with the Eisenstein & Hu (E&H) and baccoemu linear power spectra, over 1000 cosmologies and the triangles in each kmax⁡k_{\max} 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 BijkB_{ijk} 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 ℓmax⁡=max⁡(ℓ1,ℓ2,ℓ3)\ell_{\max} = \max(\ell_1, \ell_2, \ell_3), for the twenty tracer combinations (M lensing, N counts, I intrinsic alignment, K CMB lensing) at the default Nχ=160N_\chi= 160. 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.WorkloadNcosmoN_{\mathrm{cosmo}}syren-new [ms] GPU fp32syren-new [ms] GPU fp64syren-new [ms] CPU fp32syren-new [ms] CPU fp64E&H [ms] GPU fp32E&H [ms] GPU fp64E&H [ms] CPU fp32E&H [ms] CPU fp64baccoemu [ms] GPU fp32baccoemu [ms] CPU fp32
BδB_{\delta}10,160 (triangles)11.441.520.9321.413.68.350.8591.051.550.832
5001.7515.362.71464.4522.261.31391.957.1
BγB_{\gamma}9,799 (triangles)12.489.1125.343.74.5715.523.549.82.5126.4
50083.4*2,741*8,51417,06087.1*2,758*8,23017,01586.2*8,090
CℓγgC_{\ell}^{\gamma g}39 (multipoles)17.6616310,1259,870111688,9089,2967.819,182
5001,399*73,913*263,036507,9751,377*74,024*237,169477,9481,376*240,367
⟨Map3⟩\langle M_{\mathrm{ap}}^{3}\rangle84 (triplets)15.952521,0591,5068.682571,4171,4995.961,125
5002,113*143,529*400,378853,9782,061*150,572*359,205810,0502,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 ∼8\sim8 and ∼10\sim10 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. [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. [2]Alonso, D., Sanchez, J., & Slosar, A. 2019, Monthly Notices of the Royal Astronomical Society, 484, 4127–4151, doi: 10.1093/mnras/stz093DOI
  3. [3]Angulo, R. E., Zennaro, M., Contreras, S., et al. 2021, MNRAS. https://arxiv.org/abs/2004.06245
  4. [4]Aricò, G., Angulo, R., & Zennaro, M. 2022, Open Research Europe, 1, 152, doi: 10.12688/openreseurope.14310.2DOI
  5. [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. [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
  7. [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
  8. [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
  9. [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
  10. [11]Bradbury, J., Frostig, R., Hawkins, P., et al. 2018, JAX: composable transformations of Python+NumPy programs, http://github.com/jax-ml/jax
  11. [12]Bridle, S., & King, L. 2007, New J. Phys., 9, 444. https://arxiv.org/abs/0705.0166
  12. [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
  13. [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
  14. [16]Burger, P. A., Aricò, G., Linke, L., et al. 2026, Astronomy & Astrophysics, 705, A170, doi: 10.1051/0004-6361/202556061DOI
  15. [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
  16. [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
  17. [19]Campagne, J.-E., Lanusse, F., Zuntz, J., et al. 2023, The Open Journal of Astrophysics, 6, doi: 10.21105/astro.2302.05163
  18. [20]Chen, S.-F., Vlah, Z., & White, M. 2024, JCAP, 11, 012, doi: 10.1088/1475-7516/2024/11/012DOI
  19. [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
  20. [22]Chisari, N. E., Alonso, D., Krause, E., et al. 2019, The Astrophysical Journal Supplement Series, 242, 2, doi: 10.3847/1538-4365/ab1658
  21. [23]Chudaykin, A., Ivanov, M. M., Philcox, O. H., & Simonović, M. 2020, Physical Review D, 102, doi: 10.1103/physrevd.102.063533DOI
  22. [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
  23. [25]Crittenden, R. G., Natarajan, P., Pen, U.-L., & Theuns, T. 2002, The Astrophysical Journal, 568, 20
  24. [26]D’Amico, G., Lewandowski, M., Senatore, L., & Zhang, P. 2025, Physical Review D, 111, doi: 10.1103/physrevd.111.063514DOI
  25. [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
  26. [28]Eisenstein, D. J., & Hu, W. 1998, ApJ, 496, 605. https://arxiv.org/abs/astro-ph/9710912
  27. [31]Fisher, R. A. 1935, Journal of the Royal Statistical Society, 98, 39. http://www.jstor.org/stable/2342435
  28. [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
  29. [33]Foreman-Mackey, D., Hogg, D. W., Lang, D., & Goodman, J. 2013, PASP, 125, 306. https://arxiv.org/abs/1202.3665
  30. [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
  31. [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/
  32. [39]Harris, C. R., et al. 2020, Nature, 585, 357, doi: 10.1038/s41586-020-2649-2
  33. [40]Harscouet, L., Alonso, D., Nicola, A., & Slosar, A. 2026, The Open Journal of Astrophysics, 9, doi: 10.33232/001c.155341
  34. [41]Harscouet, L., Cowell, J. A., Ereza, J., et al. 2025, The Open Journal of Astrophysics, 8, doi: 10.33232/001c.128309
  35. [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
  36. [43]Heydenreich, S., Linke, L., Burger, P., & Schneider, P. 2023, Astronomy & Astrophysics, 672, A44, doi: 10.1051/0004-6361/202244820
  37. [44]Hirata, C. M., & Seljak, U. 2004, Phys. Rev. D, 70, 063526. https://arxiv.org/abs/astro-ph/0406275
  38. [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
  39. [46]Joachimi, B., Shi, X., & Schneider, P. 2009, Astronomy & Astrophysics, 508, 1193–1204, doi: 10.1051/0004-6361/200912906
  40. [47]Kayo, I., Takada, M., & Jain, B. 2012, Monthly Notices of the Royal Astronomical Society, 429, 344–371, doi: 10.1093/mnras/sts340
  41. [48]Lewis, A. 2013, Physical Review D, 87, doi: 10.1103/physrevd.87.103529
  42. [51]Lewis, A., & Bridle, S. 2002, Phys. Rev. D, 66, 103511. https://arxiv.org/abs/astro-ph/0205436
  43. [52]Lewis, A., Challinor, A., & Lasenby, A. 2000, ApJ, 538, 473, doi: 10.1086/309179
  44. [53]Limber, D. N. 1953, ApJ, 117, 134, doi: 10.1086/145672
  45. [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
  46. [55]Linke, L., Pyne, S., Joachimi, B., et al. 2024, Astronomy & Astrophysics, 691, A312, doi: 10.1051/0004-6361/202451032
  47. [57]LoVerde, M., & Afshordi, N. 2008, Physical Review D, 78, doi: 10.1103/physrevd.78.123506
  48. [58]McCullagh, N., Jeong, D., & Szalay, A. S. 2015, Monthly Notices of the Royal Astronomical Society, 455, 2945–2958, doi: 10.1093/mnras/stv2525
  49. [61]Nelson, D., Springel, V., Pillepich, A., et al. 2019, Computational Astrophysics and Cosmology, 6, 2, doi: 10.1186/s40668-019-0028-x
  50. [65]Phan, D., Pradhan, N., & Jankowiak, M. 2019, arXiv e-prints. https://arxiv.org/abs/1912.11554
  51. [66]Philcox, O. H. E., & Ivanov, M. M. 2022, Physical Review D, 105, doi: 10.1103/physrevd.105.043517
  52. [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
  53. [68]Piras, D., & Spurio Mancini, A. 2023, The Open Journal of Astrophysics, 6, doi: 10.21105/astro.2305.06347
  54. [69]Reymond, L., Reeves, A., Zhang, P., & Refregier, A. 2025, SwiftC: fast differentiable angular power spectra beyond Limber. https://arxiv.org/abs/2505.22718
  55. [70]Robnik, J., Luca, G. B. Di, Silvestri, E., & Seljak, U. 2026, Microcanonical Hamiltonian Monte Carlo. https://arxiv.org/abs/2212.08549
  56. [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
  57. [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
  58. [74]Schneider, P., & Watts, P. 2005, Astronomy & Astrophysics, 432, 783–795, doi: 10.1051/0004-6361:20041923
  59. [75]Scoccimarro, R. 2000, The Astrophysical Journal, 544, 597–615, doi: 10.1086/317248
  60. [76]Sefusatti, E., Crocce, M., Pueblas, S., & Scoccimarro, R. 2006, Physical Review D, 74, doi: 10.1103/physrevd.74.023522
  61. [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
  62. [80]Sui, C., Bartlett, D. J., Pandey, S., et al. 2025, Astronomy & Astrophysics, 698, A1, doi: 10.1051/0004-6361/202452854
  63. [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
  64. [82]Takahashi, R., Nishimichi, T., Namikawa, T., et al. 2020, ApJ, 895, 113, doi: 10.3847/1538-4357/ab908d
  65. [83]Tegmark, M., Taylor, A. N., & Heavens, A. F. 1997, The Astrophysical Journal, 480, 22–35, doi: 10.1086/303939
  66. [84]Verdiani, F., Harscouet, L., Zennaro, M., Alonso, D., & Hadzhyska, B. 2026, JCAP, 06, 027, doi: 10.1088/1475-7516/2026/06/027
  67. [85]Wieczorek, M. A., & Meschede, M. 2018, Geochemistry, Geophysics, Geosystems, 19, 2574, doi: https://doi.org/10.1029/2018GC007529
  68. [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

Paper details

vlnc:W_9jbmyfat
Version
v1 · latest
Published
Fresh — added to the Hub within the last 30 days
Added
License
CC BY 4.0
Usage

views · 0

downloads · 0

A view counts once per browser per day, a download each time the PDF is requested.

  • Physics and Astronomy

Claude Code, Large Language Models

View statement
Looking for related papers…
Contents