Skip to content

fix: use analytic potential for truncated NFW #563

Description

@Jammy2211

Overview

NFWTruncatedSph.potential_2d_from currently uses a 30-component MGE approximation whose potential is not self-consistent with the profile's analytic deflection field: the full mass-profile sweep reports a median grad(psi)=alpha error of about (7.1\times10^{-2}), roughly 100 times worse than the other NFW variants.

Baltz, Marshall & Oguri (2009), arXiv:0705.0682, Appendix A equation 18 gives an exact analytic lensing potential for precisely the (n=1) smoothly truncated NFW density convention implemented by this class. Replace the approximate production path with that analytic expression.

Plan

  • Port the analytic (n=1) potential from Baltz, Marshall & Oguri equation 18.
  • Derive its PyAutoGalaxy normalization from the existing analytic deflection rather than copying the paper's physical-unit prefactor.
  • Preserve NumPy/JAX compatibility and implement stable behaviour at (x=0), (x=1), and ( au=1).
  • Add derivative-based regression tests and independently cross-check the implementation.
  • Correct the profile docstring's arXiv identifier from 0705.0735 to 0705.0682.
Detailed implementation plan

Affected Repositories

  • PyAutoGalaxy (primary and only source repository)

Suggested branch

feature/nfw-truncated-analytic-potential

Implementation Steps

  1. In autogalaxy/profiles/mass/dark/nfw_truncated.py, replace the MGE call in NFWTruncatedSph.potential_2d_from with the (n=1) analytic expression from equation 18.
  2. Reuse the existing auxiliary functions consistently: inherited (F(x)) support and the current logarithmic helper corresponding to the paper's (L(x)).
  3. Map the paper's normalization onto PyAutoGalaxy units by differentiating the candidate expression and requiring agreement with deflections_yx_2d_from; the expected scale is proportional to (2\kappa_s r_s^2).
  4. Handle branch values and removable singularities without Python conditionals on possible JAX tracers. Thread xp through every nested operation.
  5. In test_autogalaxy/profiles/mass/dark/test_nfw_truncated.py, add parameterized finite-difference tests over multiple ( au=r_t/r_s) values:
    • (
      abla\psi=\alpha);
    • (
      abla^2\psi=2\kappa);
    • the large-( au) NFW limit, comparing potential differences because the additive constant is arbitrary.
  6. Cross-check representative potential differences against the independent lenstronomy TNFW implementation.
  7. Run the focused tests, the PyAutoGalaxy mass-profile suite, NumPy/JAX parity coverage, and PYAUTO_MASS_MODE=full python scripts/mass/dark.py.

Key Files

  • autogalaxy/profiles/mass/dark/nfw_truncated.py — analytic potential and corrected literature reference.
  • test_autogalaxy/profiles/mass/dark/test_nfw_truncated.py — derivative and limiting-behaviour regressions.
  • autolens_workspace_test/scripts/mass/dark.py — existing full self-consistency validation; validation-only unless a genuine test defect is found.

Scope boundary

The MGE implementation may be retained only as an independent comparison. Do not tune the Gaussian range as the production fix. Do not expand this PR to the separate (n=2) truncated profile.

Original Prompt

This starts from PyAutoMind draft/bug/autogalaxy/nfw_truncated_potential_accuracy.md, updated by the approved decision to prefer the exact analytic Baltz–Marshall–Oguri potential over MGE refinement.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions