Skip to content

refactor: remove integral-based deflection/potential methods from mass profiles #323

@Jammy2211

Description

@Jammy2211

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

  1. Capture hardcoded values from integral methods before removing source code
  2. Create 6 workspace scripts in autolens_workspace_test/scripts/mass_via_integral/
  3. Update comparison tests to use hardcoded numpy arrays
  4. Delete direct integral tests (20 tests across 8 files)
  5. Delete gNFW potential tests (5 tests)
  6. Remove source methods from 6 files
  7. 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.

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