Skip to content

fix: make PointMass and SMBH JAX-compatible - #554

Merged
Jammy2211 merged 1 commit into
mainfrom
feature/pointmass-smbh-jax
Aug 6, 2026
Merged

fix: make PointMass and SMBH JAX-compatible#554
Jammy2211 merged 1 commit into
mainfrom
feature/pointmass-smbh-jax

Conversation

@Jammy2211

Copy link
Copy Markdown
Collaborator

Summary

al.mp.PointMass and al.mp.SMBH failed every JAX-mode fit (user report on 2026.8.4.1; reproduced on main):

  • PointMass.deflections_yx_2d_from routed through the legacy radial_grid_from_cartesian_grid_via_radial_from helpers, which return an ArrayIrregular wrapper under xp=jnp on the irregular PSF-evaluation grids every imaging fit uses — jnp.multiply rejects it (TypeError: multiply requires ndarray or scalar arguments, got ArrayIrregular).
  • SMBH.__init__ computed np.sqrt(mass_angular / np.pi) — with mass a free parameter the instance is built inside the jit trace, so np.sqrt receives a tracer (jax.errors.TracerArrayConversionError).

Deflections are rewritten with raw xp ops (mirroring how IsothermalSph already works under JAX), potential_2d_from / convergence_2d_from are hardened the same way (the convergence central-pixel argmin code was dead — its assignment has been commented out for a long time), and the SMBH Einstein radius uses tracer-safe ** 0.5.

Fixes #553.

API Changes

None — internal bug fixes only. NumPy-path behaviour is numerically identical (deflections match the previous implementation and the analytic point-mass formula to ~1e-18). The behavioural change is that JAX-mode fits containing PointMass/SMBH now run instead of raising.
See full details below.

Test Plan

  • test_autogalaxy/ full suite: 1017 passed
  • PyAutoLens test_autolens/point/: 115 passed against this branch
  • Jitted AnalysisImaging.log_likelihood_function with stock PointMass (Einstein radius free) and stock SMBH (mass free): finite likelihoods — both configurations reproduced the user-reported errors on unfixed main as controls
  • jax.grad finite for all PointMass/SMBH parameters (a non-finite Isothermal.ell_comps gradient at exactly (0.0, 0.0) exists with and without the point mass — pre-existing, unrelated)
  • Deflections parity vs analytic θ_E²/r² · (y, x): max abs diff 8.7e-19
Full API Changes (for automation & release notes)

Changed Behaviour

  • PointMass.deflections_yx_2d_from / potential_2d_from / convergence_2d_from — now tracer-safe under xp=jnp (previously raised TypeError / TracerArrayConversionError in JAX-mode fits); NumPy results numerically unchanged.
  • SMBH.__init__ — Einstein radius computed with tracer-safe ** 0.5 instead of np.sqrt; accepts a traced mass.

Generated by the PyAutoLabs agent workflow.

PointMass.deflections_yx_2d_from routed through the legacy
radial_grid_from / _cartesian_grid_via_radial_from helpers, which return
an ArrayIrregular wrapper under xp=jnp on the irregular PSF-evaluation
grids every imaging fit uses - jnp.multiply rejects it. Rewritten with
raw xp ops (same maths, parity ~1e-18); potential_2d_from and
convergence_2d_from hardened the same way (the convergence central-pixel
argmin code was dead - its assignment was commented out). SMBH.__init__
used np.sqrt on the traced mass, raising TracerArrayConversionError; now
tracer-safe pow.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
@Jammy2211 Jammy2211 added the pending-release PR queued for the next release build label Aug 6, 2026
@Jammy2211
Jammy2211 merged commit daf3b8d into main Aug 6, 2026
1 of 3 checks passed
@Jammy2211
Jammy2211 deleted the feature/pointmass-smbh-jax branch August 6, 2026 18:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

pending-release PR queued for the next release build

Projects

None yet

Development

Successfully merging this pull request may close these issues.

fix: make PointMass and SMBH JAX-compatible

1 participant