Repository navigation
Description
Overview
Phase 2 follow-up to #397. The Phase 1 feasibility report (docs/research/nfw_ludlow16_jax_assessment.md, shipped in #402) confirmed that the jax.pure_callback wrapping colossus.halo.concentration in autogalaxy/profiles/mass/dark/mcr_util.py can be replaced by a JAX-native port of modelLudlow16 (Approach A — full Eisenstein-Hu '98 transfer + Heath '77 growth factor + Einasto gammainc mass ratio + 200-point Ludlow c-solver, ~330 lines of straight-line JAX).
Validated numbers from the Phase 1 prototype at docs/research/nfw_ludlow16_jax/ludlow16_jax.py:
- Max c200c relative error vs colossus over the lensing grid: 7.5 × 10⁻⁴
- Max
kappa_srelative error end-to-end: 1.07 × 10⁻³ - Max NFW convergence / deflection per-pixel relative error: 8.21 × 10⁻⁴
- ~350× below the intrinsic Ludlow16 scatter (
σ_log10(c) = 0.13 dex) — scientifically invisible. - Single-call post-JIT: 0.69 ms vs colossus' 0.83 ms.
jax.gradworks end-to-end (agreement to 7 × 10⁻⁴ vs finite-diff).
This issue implements the swap-in: move the prototype into production, collapse the JAX/NumPy branches in the two callers, drop colossus as a runtime dependency, add tests.
Plan
- Promote
docs/research/nfw_ludlow16_jax/ludlow16_jax.pyintoautogalaxy/profiles/mass/dark/ludlow16.py(or fold it intomcr_util.pyif size stays reasonable). Convert thejnp.*calls to bexp-aware so the same function runs under both numpy and JAX paths (the numpy path is needed forxp=npcallers; both branches already exist in the helpers). - Replace
_ludlow16_cosmology_callbackandludlow16_cosmology_jaxinmcr_util.pywith a singlexp-awareludlow16_cosmology(mass_at_200, redshift_object, redshift_source, xp=np)that calls the newludlow16_concentration_xp(...)for the c200c part and continues to use the existing JAX-nativePlanck15for the other three returned values. - Drop the
if xp is np: ... else: ...branching inkappa_s_and_scale_radius_for_ludlowandkappa_s_scale_radius_and_core_radius_for_ludlow— both become straightxpcalls. - Make
colossusan optional dependency: only the unit-test cross-check against the original implementation needs it at runtime. Updatepyproject.toml(and any conda/eden recipe) accordingly. - Add unit tests covering:
- Numpy path regression vs colossus on a small (log M, z) grid (the existing prototype's
validate.pynumbers — keep them as the regression baseline). - JAX path
jitcorrectness (numpy/JAX paths agree to ~1e-12). jax.gradsmoke test (finite, non-NaN gradient throughludlow16_concentration_xp).
- Numpy path regression vs colossus on a small (log M, z) grid (the existing prototype's
- Validate the five MCR-Ludlow callers end-to-end under
jax.jitinautogalaxy_workspace_test/:nfw_mcr,nfw_mcr_scatter,nfw_truncated_mcr_scatter,gnfw_mcr,cnfw_mcr_scatter.
Out of scope (separate work)
Two pre-existing issues surfaced during the Phase 1 science check but are unrelated to this swap-in:
cNFWSph.convergence_2d_fromreturns zeros — marked "not yet implemented" incnfw.py:239-244.- The Penarrubia mcr formula in
kappa_s_scale_radius_and_core_radius_for_ludlowproduces a negativekappa_sforf_c ≳ 0.18due to a sign flip in the denominator. Either restrictf_cpriors or guard the formula.
References
- Phase 1 issue: feat: assess JAX-native replacement for Ludlow16 concentration pure_callback #397
- Phase 1 PR: docs(research): Ludlow16 JAX concentration feasibility study (#397) #402
- Feasibility report:
docs/research/nfw_ludlow16_jax_assessment.md - Prototype:
docs/research/nfw_ludlow16_jax/ludlow16_jax.py
🤖 Generated with Claude Code
Activity
Merge pull request #406 from PyAutoLabs/feature/ludlow16-jax-native
Jammy2211 commentedon May 14, 2026
Shipped — 2026-05-14
PR
Summary
The colossus
jax.pure_callbackchain inmcr_util.pyis gone.import colossusandjax.pure_callbackno longer appear anywhere in production code.colossusmoved from required to test/dev extras — production no longer needs it installed.Cross-implementation verification
Re-running
autolens_workspace_test/scripts/jax_likelihood_functions/imaging/subhalo.pyagainst this PR's code produced bit-identicalvmap = -1.349200e+09for Scenarios C and D — exactly matching the colossus-locked regression literals from workspace_test PR #92. The downstream log-likelihood is unchanged atrtol=1e-4.Session Notes
1.0e-4to1.0e-3(still 0.1%, well below the Ludlow16 intrinsic scatter thescatter_sigmaparameter marginalises over). The old 1e-4 was implicitly claiming colossus-level precision; JAX impl differs from colossus by ~2e-4 in these literals. Affected files:test_nfw_mcr.py,test_nfw_scatter.py,test_nfw_truncated_mcr.py,test_nfw_truncated_mcr_scatter.py.xp.trapezoid(added in numpy 1.26) with a manual_trapezoid_last_axishelper. Local 3.12 venv has new numpy; CI's 3.12 had numpy<1.26. JAX 3.13 was fine. Manual trapezoidal rule works across all numpy versions and produces bit-identical output.kappa_sforf_c ≳ 0.18— pre-existing. (ii)cNFWSph.convergence_2d_fromreturning zeros — pre-existing "not yet implemented". (iii)Planck15Om0 mismatch between autogalaxy (0.3075) and colossus preset (0.3089) — preserved as-is for apples-to-apples swap.