Skip to content

feat: MGE/CSE fallback for zero-returning mass profile potentials#449

Merged
Jammy2211 merged 1 commit into
mainfrom
feature/mge-cse-fallback
May 26, 2026
Merged

feat: MGE/CSE fallback for zero-returning mass profile potentials#449
Jammy2211 merged 1 commit into
mainfrom
feature/mge-cse-fallback

Conversation

@Jammy2211
Copy link
Copy Markdown
Collaborator

Summary

Replace zero-returning potential_2d_from and convergence_2d_from methods across 10 mass profiles with proper implementations. Adds a new potential_2d_via_mge_from method to MGEDecomposer using the E1 (exponential integral) formula from Shajib (2019), cross-validated against Jax-Lensing-Profiles (Herculens). Phase 3 of the mass profiles refactoring epic (#445).

Three tiers of implementation:

  • Analytic: PointMass (ψ = R_E² ln r) and MassSheet (ψ = ½κr²)
  • MGE convergence: cNFW/cNFWSph now compute convergence via MGE (same pattern as their existing MGE-based deflections)
  • MGE potential: All remaining profiles (Sersic, Gaussian, Chameleon, PowerLawBroken, dPIE families, NFWTruncated, cNFW) compute potential via the new potential_2d_via_mge_from

Self-consistency validated: laplacian(ψ_MGE) = 2κ_MGE to 0.3% median error. The ~5-9% error vs profiles with known analytic potentials is inherent to the MGE decomposition (convergence itself has similar error), not the potential formula.

API Changes

Added MGEDecomposer.potential_2d_via_mge_from() — new public method computing lensing potential from MGE-decomposed convergence using the E1 exponential integral. Added helper methods E1() (Abramowitz & Stegun approximation, JAX-compatible) and potential_func_gaussian(). All existing zero-returning methods now return physically meaningful values instead of zeros. See full details below.

Test Plan

  • pytest test_autogalaxy/profiles/mass/ — 406 passed, 0 failed
  • MGE potential self-consistency: laplacian(ψ) = 2κ to 0.3% median
  • MGE potential vs Isothermal/PowerLaw analytic: ~5% median (decomposition-limited)
  • Updated test_mass_sheet.py to match new correct potential values
  • Phase 1 self-consistency tests (autolens_workspace_test scripts/mass/) — follow-up
Full API Changes (for automation & release notes)

Added

  • MGEDecomposer.E1(x, xp) — static method, exponential integral of first order (Abramowitz & Stegun 1970)
  • MGEDecomposer.potential_func_gaussian(grid_radii, sigma, intensity, xp) — potential of a single Gaussian convergence component
  • MGEDecomposer.potential_2d_via_mge_from(grid, *, sigma_log_list, three_D, ellipticity_convention, ...) — lensing potential via MGE decomposition
  • MGEDecomposer._potential_2d_via_mge_from(grid_radii, *, sigma_log_list, ...) — internal implementation

Changed Behaviour

  • PointMass.potential_2d_from — was zeros, now returns ψ = R_E² ln(r)
  • MassSheet.potential_2d_from — was zeros, now returns ψ = ½κr²
  • cNFW.convergence_2d_from / cNFWSph.convergence_2d_from — was zeros, now MGE-computed
  • cNFW.potential_2d_from / cNFWSph.potential_2d_from — was zeros, now MGE-computed
  • NFWTruncatedSph.potential_2d_from — was zeros, now MGE-computed
  • AbstractSersic.potential_2d_from (Sersic, SersicSph) — was zeros, now MGE-computed
  • Gaussian.potential_2d_from — was zeros, now MGE-computed
  • Chameleon.potential_2d_from — was zeros, now MGE-computed
  • PowerLawBroken.potential_2d_from — was zeros, now MGE-computed
  • dPIEMass.potential_2d_from — was zeros, now MGE-computed
  • dPIEPotential.potential_2d_from / dPIEPotentialSph.potential_2d_from — was zeros, now MGE-computed

Migration

No migration needed — methods that returned zeros now return physically correct values. Any code that relied on these methods returning zeros was already broken (using a placeholder).

🤖 Generated with Claude Code

Replace zero-returning potential_2d_from and convergence_2d_from
methods across 10 mass profiles with proper implementations:

- PointMass: analytic potential psi = R_E^2 * ln(r)
- MassSheet: analytic potential psi = 0.5 * kappa * r^2
- cNFW/cNFWSph: convergence + potential via MGE decomposition
- NFWTruncatedSph: potential via MGE decomposition
- Sersic/SersicSph: potential via MGE decomposition
- Gaussian: potential via MGE decomposition
- Chameleon/ChameleonSph: potential via MGE decomposition
- PowerLawBroken/Sph: potential via MGE decomposition
- dPIEMass/Sph: potential via MGE decomposition
- dPIEPotential/Sph: potential via MGE decomposition

New potential_2d_via_mge_from method on MGEDecomposer using the E1
(exponential integral) formula from Shajib (2019), cross-validated
against Jax-Lensing-Profiles (Herculens). Self-consistency verified
to 0.3% (laplacian of MGE potential = 2 * MGE convergence).

Phase 3 of mass profiles refactoring epic (#445).

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
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.

1 participant