Repository navigation
Description
Overview
group/features/advanced/mass_stellar_dark/chaining.py fails fast (~26 s) on the
release stack with a TracerArrayConversionError, not a timeout. Diagnosed as a
real library bug, not a jax-0.10.2 regression: the CSE decomposition path used
by Sérsic stellar-mass and NFW dark-mass deflections was only partially ported
to JAX (commit 35e6812), so it cannot be jax.jit-traced when the mass params are
free. It surfaced now because this is the first release script to jit a CSE mass
profile with free params (isothermal deflects analytically and never hits CSE).
Plan
- Thread
xpinto the deflection entry so the immediate crash clears. - Make
cse_settings_fromtraceable:xpops +jnp.where/jnp.minimuminstead
ofnp.log10/np.min, and freezetotal_cses/sample_pointsto a static
conservative max (~50/80) so decomposition array shapes are constant under jit
(no Python branch on thesersic_indextracer, no value-dependent shapes). - Port
_decompose_convergence_via_cse_fromtoxp.logspace, a vectorized
coefficient-matrix build, andjnp.linalg.lstsq(replacingscipy.linalg.lstsq). - Port both
decompose_convergence_via_cseimpls (Sérsic + NFW) toxp. - Keep the NumPy path (
xp=np) behaviourally identical; validate the JAX path via
theautogalaxy_workspace_testparity scripts (jit round-trip +fitness._vmap),
nevertest_autogalaxy/; confirmmass_stellar_dark/chaining.pyruns green.
Phased: P1 — threading + traceable cse_settings_from/decompose to unblock the
release tail. P2 — parity hardening across the Sérsic-index range and NFW.
Detailed implementation plan
Affected Repositories
- PyAutoGalaxy (primary)
- PyAutoArray, PyAutoLens (reproduction only — no changes expected)
Branch Survey
| Repository | Current Branch | Dirty? |
|---|---|---|
| ./PyAutoGalaxy | main | clean |
| ./PyAutoArray | main | clean |
| ./PyAutoLens | main | clean |
Suggested branch: feature/mass-cse-jax-decompose
Root cause (reproduced on jax 0.10.2, JAX_TRACEBACK_FILTERING=off)
search[1] (lens light) cached; search[2] (lens mass = Sérsic + NFW) crashes on
its first jitted likelihood eval. The decorator AbstractMaker._xp
(PyAutoArray/.../decorators/abstract.py) resolves the backend from the xp passed
into the decorated call, so a dropped xp silently becomes numpy on a tracer.
cse.py:197radial_grid_from(grid=grid, **kwargs)dropsxp→np.sqrton a
float64[225] tracer.- After threading that,
sersic.py:58cse_settings_from→np.log10((23.0/ sersic_constant)**sersic_index)on a scalar tracer; whole decompose uses
np.logspaceon tracer bounds +scipy.linalg.lstsq(untraceable). NFW decompose
(np.max(grid_radii), complexcoord_func_g) has the same shape.
Implementation Steps (P1)
autogalaxy/profiles/mass/abstract/cse.py:197— passxp=xptoradial_grid_from.autogalaxy/profiles/mass/stellar/sersic.pycse_settings_from(lines ~1–82) —
remove Python branching onsersic_index; computeupper_dex/lower_dexwith
xp/jnp.where/jnp.minimum; return constanttotal_cses/sample_points
(conservative max, ~50/80) so shapes are static.autogalaxy/profiles/mass/abstract/cse.py_decompose_convergence_via_cse_from
(lines ~85–147) —xp.logspace; buildcoefficient_matrixvectorized (no
np.zeros+loop);jnp.linalg.lstsqwhenxp is jnp, else keep scipy for numpy
parity/speed.sersic.py:245+dark/nfw.py:177decompose_convergence_via_cse—xpthe
np.sqrt/np.max/np.realops and radii bounds.
Validation
autogalaxy_workspace_testJAX parity (jit round-trip +fitness._vmap) on a
Sérsic mass + NFW model; NumPy path unchanged (test_autogalaxy/stays green,
NumPy-only).- End-to-end:
mass_stellar_dark/chaining.pyunder the release profile
(PYAUTO_TEST_MODE=1) completes without a traceback.
Key Files
autogalaxy/profiles/mass/abstract/cse.py— decomposition + deflection driver.autogalaxy/profiles/mass/stellar/sersic.py—cse_settings_from, Sérsic decompose.autogalaxy/profiles/mass/dark/nfw.py— NFW decompose.autogalaxy/profiles/geometry_profiles.py:113—radial_grid_from(crash site).
Classification
Real library bug (incomplete JAX port), not a jax-0.10.2 regression. Surfaced
on release-validation run 29279095224 / TestPyPI 2026.7.13.1.dev65601
(PyAutoHeart#72).
Original Prompt
Click to expand starting prompt
group/mass_stellar_dark chaining fails with a JAX exception on release wheels
Type: bug
Target: autolens_workspace
Repos:
- autolens_workspace
- PyAutoGalaxy
- PyAutoArray
Difficulty: hard
Autonomy: supervised
Priority: normal
Status: diagnosed
Fix-locus: PyAutoGalaxy (autogalaxy/profiles/mass — CSE decomposition path)
Workflow: library
Strategy: full jnp trace of the CSE decomposition; freeze total_cses/sample_points
to a conservative static max (~50/80) on both paths (static shapes under jit);
phased — P1 unblock chaining, P2 Sersic-range + NFW parity harden.
Surfaced burning down the 2026-07-13 release-validation tail (PyAutoHeart#72). On the
release wheels under the release profile:
scripts/group/features/advanced/mass_stellar_dark/chaining.py ... FAIL (26.6s)
For simplicity, JAX has removed its internal frames from the traceback of the following
exception. Set JAX_TRACEBACK_FILTERING=off to include these.
The run-runner captured only the filtered banner, not the actual exception — it is a real
JAX error during a group-scale mass_stellar_dark chaining pipeline (real sampler,
PYAUTO_TEST_MODE=1 for user workspaces), and fails fast (26.6 s), so it is NOT a timeout
(distinct from the other group//chaining scripts that TIMEOUT and are handled by the
release timeout bump PyAutoHeart#c19c948).
Reproduce from the autolens_workspace checkout on current main under the release profile,
with JAX_TRACEBACK_FILTERING=off to get the real traceback:
cd autolens_workspace
JAX_TRACEBACK_FILTERING=off PYAUTO_TEST_MODE=1 PYAUTO_SKIP_WORKSPACE_VERSION_CHECK=1 \
python scripts/group/features/advanced/mass_stellar_dark/chaining.py
The dev venv is now jax 0.10.2 (matches the release stack — see
[[reference_laptop_gpu_jax_setup]]), so this should reproduce locally. Candidate causes given
the release-validation context: a jax-0.10.2 numerical/behaviour change in the chained
group-scale fit (cf. the jax-drift and LinAlg-not-PD siblings), a NaN/inf in a chained-prior
pass, or a real group/mass_stellar_dark modelling issue. Classify (jax regression vs real
bug) and fix at the right layer. Release run: PyAutoHeart workspace-validation 29279095224,
TestPyPI 2026.7.13.1.dev65601. See [[project_release_2026_07_13_blocked_3bugs]] and
PyAutoHeart#72.
Diagnosis (2026-07-14, reproduced locally on jax 0.10.2)
Classification: real library bug (incomplete JAX port of the CSE mass-profile
decomposition), NOT a jax-0.10.2 regression. jax 0.10.2 is incidental — the
release stack simply jits the likelihood; the same code fails on any jax version.
Reproduced on autolens_workspace main with JAX_TRACEBACK_FILTERING=off.
search[1] (lens light) is cached; search[2]__mass_stellar_dark crashes on the
first jitted likelihood eval. The lens mass is a Sersic (stellar) + NFW (dark)
model; the Sersic mass profile deflections go through the CSE decomposition
path, which is only partially JAX-threaded:
PyAutoArray.../decorators/abstract.py(AbstractMaker._xp) resolves the
backend from thexppassed into the decorated call. So a droppedxpat a
call site silently becomesxp=np.- First crash —
PyAutoGalaxy/autogalaxy/profiles/mass/abstract/cse.py:197:
self.radial_grid_from(grid=grid, **kwargs)dropsxp(it is a named param
of_deflections_2d_via_cse_from, not in**kwargs), soradial_grid_from
(geometry_profiles.py:113xp.sqrt(...)) runs withxp=npon a JAX tracer →
TracerArrayConversionError(float64[225]). Threadingxp=xphere clears it. - Second crash (after fixing Coordinates #2) — the decomposition itself is not traceable.
Withsersic_indexfree in search[2],decompose_convergence_via_cseruns on
tracer params via numpy/scipy:sersic.py:58cse_settings_from→np.log10((23.0/sersic_constant)**sersic_index)
on a scalar tracer →TracerArrayConversionError(float64[]).sersic.py:280np.sqrt(self.axis_ratio()); param-dependentradii_min/max.cse.py:122/126np.logspace(np.log10(radii_min), ...)on tracer bounds.cse.py:143scipy.linalg.lstsq— cannot trace at all.
The dark NFW decompose (dark/nfw.py) has the same shape (np.max(grid_radii),
scipy.lstsq) and would fail identically once reached.
Isothermal traces fine because it deflects analytically (xp.arctan/arctanh),
never touching CSE — so the CSE JAX port (commit 35e6812a, 2026-05-26 "port CSE
module to support JAX via xp parameter") was never actually exercised under jit
until this chaining script. This is the first release script to jit a CSE mass
profile with free params.
Fix locus: PyAutoGalaxy (profiles/mass/abstract/cse.py, stellar/sersic.py
incl. cse_settings_from, dark/nfw.py). Real fix ≈ thread xp through
cse_settings_from + both decompose_convergence_via_cse + _decompose_convergence_via_cse_from,
and replace scipy.linalg.lstsq/np.logspace with jnp.linalg.lstsq/xp.logspace
so the decomposition is jit-traceable. Validate via the JAX parity scripts in
autogalaxy_workspace_test (jit round-trip + fitness._vmap), never test_autogalaxy/.
Difficulty raised medium → hard (numerical path + lstsq-in-trace, affects all
CSE mass profiles under JAX).
Activity
Jammy2211 commentedon Jul 14, 2026
Ship sign-off requested (supervised
--auto— ship parks per AUTONOMY.md)P1 is implemented and validated in the worktree; changes are uncommitted pending your sign-off (
supervisedconverts the ship-PR checkpoint into this question).What was done (P1 — unblock)
JAX-traced the Sérsic stellar-mass CSE deflection path in PyAutoGalaxy. Diagnosis confirmed this is a real library bug (incomplete CSE→JAX port), not a jax-0.10.2 regression. Scope narrowed during implementation: NFW deflects analytically (HK24), not via CSE, so only the Sérsic path needed fixing for the deflection likelihood.
Files (
feature/mass-cse-jax-decompose, 4 files, +104/−59):mass/abstract/cse.py— threadxpintoradial_grid_from,decompose_convergence_via_cse,axis_ratio; port_decompose_convergence_via_cse_from(vectorised coefficient matrix,jnp.linalg.lstsqon the JAX path,scipy.linalg.lstsqretained for NumPy).mass/stellar/sersic.py—cse_settings_fromrewritten branch-free (xp.where) so a tracersersic_indextraces;total_cses/sample_pointsfrozen to a static 50/80 (conservative max) for static jit shapes; per-ndex ranges preserved exactly.mass/stellar/sersic_gradient.py,mass/dark/nfw.py—xpthreaded so sibling signatures stay compatible (NFW convergence path also traceable as a bonus).Validation (gate evidence)
test_autogalaxy/profiles/mass/→ 432 passed (NumPy path intact).group/features/advanced/mass_stellar_dark/chaining.pyunder the release profile (PYAUTO_TEST_MODE=1, jax 0.10.2) → completes, 0 tracebacks (was FAIL 26.6s).n∈[1,4].API / behaviour
xp=npkwarg to internaldecompose_convergence_via_cse/cse_settings_from/_decompose_convergence_via_cse_from.nbecause the CSE count rose (30/40 → 50/80, i.e. finer → closer to the integral truth; thetest_sersicintegral-tolerance asserts still pass at 1e-4/1e-3). No workspace script references these symbols directly, but downstream regression goldens that pin Sérsic-mass deflection values may need a ~1e-3 refresh (a/start_workspacefollow-up if so).Known P2 follow-up (agreed phasing — not in this PR)
n<1NumPy-vs-JAX parity gap of 3e-3 (ill-conditioned CSEscipyvsjnplstsq).ag.mp.Sersicdeflections toautolens_workspace_test/scripts/profiles_jit.py(parity harness currently covers Isothermal/PowerLaw/NFW only — the gap that hid this bug).Heart state (evidence, not a branch gate for a feature ship)
Not GREEN:
RELEASE VALIDATION integrate:fail(the ongoing 2026-07-13 tail burndown, organism-scope) + a stale 2026-07-09TEST RUN3f. Neither implicates this branch.Decision requested
pending-releasePR (ends at PR-open; merge stays yours), then post the workspace-impact recommendation.Jammy2211 commentedon Jul 14, 2026
Library PR created — #500 (
pending-release)Ship sign-off given in-session; commit
68a2a00dpushed onfeature/mass-cse-jax-decompose, PR #500 open withpending-release. Run ends at PR-open (merge stays a human act).Workspace impact: (iii) no API migration —
cse_settings_from/decompose_convergence_via_cseare internal; no workspace script imports them. Caveat: the ~1e-3 NumPy behaviour change (finer CSE count) reaches three regression scripts that build Sérsic mass:autolens_workspace_test/scripts/mass_via_integral/sersic.py(CSE-vs-integral parity — most likely to notice)autolens_workspace_test/scripts/mass_via_integral/sersic_gradient.pyautolens_workspace_test/scripts/mass/stellar.pyThese assert against the integral ground truth (which the finer decomposition tracks at least as well), so they should still pass, but they want a smoke re-run; if any golden shifts ~1e-3, a small
/start_workspacerefresh PR follows.P2 follow-up (separate task): (1)
n<1NumPy-vs-JAX parity gap 3e-3 (ill-conditioned CSE lstsq); (2) addag.mp.Sersicdeflections toprofiles_jit.py(the parity-harness gap that hid this bug).Jammy2211 commentedon Jul 14, 2026
Merged — PR #500 (squash
b8bc0a3e), human-directedThe release-validation integration test that surfaced this is fixed.
group/features/advanced/mass_stellar_dark/chaining.py(the FAIL in workspace-validation29279095224) now runs green end-to-end (0 tracebacks, both searches complete) against the fix. Sérsic-mass parity regression scripts also pass at rtol=1e-3 (mass_via_integral/sersic.py,sersic_gradient.py).P2 dropped (human call): the integration test is fixed, so we are not pursuing the
n<1lstsq parity-tightening or theprofiles_jit.pySérsic-harness addition as a follow-up. Then<1NumPy-vs-JAX difference (3e-3) remains documented here for future reference but is below the CSE approximation's own error and is not release-gating.Remaining to clear the release-validation RED (release-ops, human-gated): fresh post-merge wheels → rerun release-integration on
main→ new Heart verdict. Issue kept open until that confirms on wheels, matching the other 2026-07-13 tail fixes.Jammy2211 commentedon Jul 14, 2026
Corrective validation GREEN — closing
The fresh
mode=releasevalidation run on the currentmainHEADs passed end-to-end:v2026.7.14.1.dev66001— all 5 wheels built + uploaded.release_ready: true; Heart is now YELLOW (no RED reasons remain).This fix is on the validated
mainHEADs (commit_shasmatched), so its corrective validation is satisfied. Closing.