Overview
The deflections_2d_via_integral_from methods across mass profiles are slow, large, and only used for testing — the actual deflection calculations use MGE or CSE decompositions. This task removes all integral-based deflection, potential, and related helper methods from the source code, preserving them as standalone reference scripts in autolens_workspace_test/scripts/mass_via_integral/.
Additionally, the integral-based potential_2d_from methods on elliptical NFW and gNFW (which use scipy.integrate.quad) are removed. The gNFW convergence_func is kept in place as it is the only convergence calculation for gNFW and is also used internally by the MGE decomposition.
Plan
- Move all integral-based deflection/potential/convergence code to standalone scripts in
autolens_workspace_test/scripts/mass_via_integral/ with numerical assertions
- Remove
deflections_2d_via_integral_from and deflection_func from: Gaussian, Sersic, SersicGradient, NFW, gNFW, gNFWSph
- Remove integral-based
potential_2d_from and potential_func from NFW (elliptical) and gNFW
- Remove
tabulate_integral from AbstractgNFW (dead code after removal)
- Update comparison tests (integral vs CSE/MGE) to use hardcoded expected values
- Delete tests that directly test integral methods
- Keep
gNFW.convergence_func (essential for convergence and MGE deflections)
Detailed implementation plan
Affected Repositories
- PyAutoGalaxy (primary)
- autolens_workspace_test
Work Classification
Library + Workspace
Branch Survey
| Repository |
Current Branch |
Dirty? |
| ./PyAutoGalaxy |
main |
clean |
| ./autolens_workspace_test |
main |
clean |
Suggested branch: feature/remove-deflection-integral
Implementation Steps
- Capture hardcoded values from integral methods before removing source code
- Create 6 workspace scripts in
autolens_workspace_test/scripts/mass_via_integral/
- Update comparison tests to use hardcoded numpy arrays
- Delete direct integral tests (20 tests across 8 files)
- Delete gNFW potential tests (5 tests)
- Remove source methods from 6 files
- Run full test suite to verify
Key Files
autogalaxy/profiles/mass/stellar/gaussian.py
autogalaxy/profiles/mass/stellar/sersic.py
autogalaxy/profiles/mass/stellar/sersic_gradient.py
autogalaxy/profiles/mass/dark/nfw.py
autogalaxy/profiles/mass/dark/gnfw.py
autogalaxy/profiles/mass/dark/abstract.py
Original Prompt
Click to expand starting prompt
Throughout the package PyAutoGalaxy/autogalaxy/profiles/mass there are methods which compute deflection angles via a method deflections_2d_via_integral_from. These are slow, and often very large. Move all methods to a dedicated package in autolens_workspace_test/scripts/ called mass_via_integral, asserting their values based on the autogalaxy unit tests. For the majority of these functions, the integral was only used for testing anyway, with an MGE or CSE decomposition forming the basis of the deflection angle. Do not remove or change any unit tests unless they are directly against the integral. Also remove all long integral functions used for potentials or convergences, moving them to the same mass_via_integral.
Overview
The
deflections_2d_via_integral_frommethods across mass profiles are slow, large, and only used for testing — the actual deflection calculations use MGE or CSE decompositions. This task removes all integral-based deflection, potential, and related helper methods from the source code, preserving them as standalone reference scripts inautolens_workspace_test/scripts/mass_via_integral/.Additionally, the integral-based
potential_2d_frommethods on elliptical NFW and gNFW (which usescipy.integrate.quad) are removed. The gNFWconvergence_funcis kept in place as it is the only convergence calculation for gNFW and is also used internally by the MGE decomposition.Plan
autolens_workspace_test/scripts/mass_via_integral/with numerical assertionsdeflections_2d_via_integral_fromanddeflection_funcfrom: Gaussian, Sersic, SersicGradient, NFW, gNFW, gNFWSphpotential_2d_fromandpotential_funcfrom NFW (elliptical) and gNFWtabulate_integralfrom AbstractgNFW (dead code after removal)gNFW.convergence_func(essential for convergence and MGE deflections)Detailed implementation plan
Affected Repositories
Work Classification
Library + Workspace
Branch Survey
Suggested branch:
feature/remove-deflection-integralImplementation Steps
autolens_workspace_test/scripts/mass_via_integral/Key Files
autogalaxy/profiles/mass/stellar/gaussian.pyautogalaxy/profiles/mass/stellar/sersic.pyautogalaxy/profiles/mass/stellar/sersic_gradient.pyautogalaxy/profiles/mass/dark/nfw.pyautogalaxy/profiles/mass/dark/gnfw.pyautogalaxy/profiles/mass/dark/abstract.pyOriginal Prompt
Click to expand starting prompt
Throughout the package PyAutoGalaxy/autogalaxy/profiles/mass there are methods which compute deflection angles via a method deflections_2d_via_integral_from. These are slow, and often very large. Move all methods to a dedicated package in autolens_workspace_test/scripts/ called mass_via_integral, asserting their values based on the autogalaxy unit tests. For the majority of these functions, the integral was only used for testing anyway, with an MGE or CSE decomposition forming the basis of the deflection angle. Do not remove or change any unit tests unless they are directly against the integral. Also remove all long integral functions used for potentials or convergences, moving them to the same mass_via_integral.