Skip to content

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

Merged
Jammy2211 merged 1 commit intomainfrom
feature/remove-deflection-integral
Apr 6, 2026
Merged

refactor: remove integral-based deflection/potential methods from mass profiles#324
Jammy2211 merged 1 commit intomainfrom
feature/remove-deflection-integral

Conversation

@Jammy2211
Copy link
Copy Markdown
Collaborator

Summary

Remove all integral-based deflection and potential methods from mass profiles. These methods used scipy.integrate.quad and were slow and large — they were only used for testing, since the actual deflection calculations use MGE or CSE decompositions. The integral code is preserved as standalone reference scripts in autolens_workspace_test/scripts/mass_via_integral/.

API Changes

The following methods are removed from mass profile classes:

  • deflections_2d_via_integral_from — removed from Gaussian, Sersic, SersicGradient, NFW, gNFW, gNFWSph
  • deflection_func — removed from Gaussian, Sersic, SersicGradient, NFW, gNFW
  • potential_2d_from — removed from elliptical NFW and gNFW (spherical NFWSph analytic version kept)
  • potential_func — removed from NFW and gNFW
  • tabulate_integral — removed from AbstractgNFW
  • deflection_integrand, deflection_func_sph — removed from gNFWSph

gNFW.convergence_func is kept (essential for convergence and MGE deflections).
See full details below.

Test Plan

  • Full test suite: 811 passed, 0 failures
  • All comparison tests updated to use hardcoded expected values
  • Workspace scripts in autolens_workspace_test/scripts/mass_via_integral/ verify preserved values
Full API Changes (for automation & release notes)

Removed

  • mp.Gaussian.deflections_2d_via_integral_from(grid) — test-only integral deflection
  • mp.Gaussian.deflection_func(u, y, x, npow, axis_ratio, sigma) — integrand helper
  • mp.Sersic.deflections_2d_via_integral_from(grid) — test-only integral deflection
  • mp.Sersic.deflection_func(u, y, x, npow, axis_ratio, sersic_index, effective_radius, sersic_constant) — integrand helper
  • mp.SersicGradient.deflections_2d_via_integral_from(grid) — test-only integral deflection
  • mp.SersicGradient.deflection_func(u, y, x, ...) — integrand helper
  • mp.NFW.deflections_2d_via_integral_from(grid) — test-only integral deflection
  • mp.NFW.deflection_func(u, y, x, npow, axis_ratio, scale_radius) — integrand helper
  • mp.NFW.potential_2d_from(grid) — integral-based elliptical potential
  • mp.NFW.potential_func(u, y, x, axis_ratio, kappa_s, scale_radius) — potential integrand
  • mp.gNFW.deflections_2d_via_integral_from(grid, tabulate_bins) — test-only integral deflection
  • mp.gNFW.deflection_func(u, y, x, ...) — integrand helper
  • mp.gNFW.potential_2d_from(grid, tabulate_bins) — integral-based potential
  • mp.gNFW.potential_func(u, y, x, ...) — potential integrand
  • mp.gNFWSph.deflections_2d_via_integral_from(grid) — test-only integral deflection
  • mp.gNFWSph.deflection_integrand(y, eta, inner_slope) — integrand helper
  • mp.gNFWSph.deflection_func_sph(eta) — spherical deflection helper
  • AbstractgNFW.tabulate_integral(grid, tabulate_bins) — dead code after integral removal

Migration

  • Before: profile.deflections_2d_via_integral_from(grid=grid) — for test comparisons

  • After: Use hardcoded expected values or deflections_yx_2d_from / deflections_2d_via_cse_from / deflections_2d_via_mge_from

  • Before: nfw.potential_2d_from(grid=grid) on elliptical NFW

  • After: Only available on NFWSph (analytic). Elliptical NFW/gNFW potential raises NotImplementedError.

🤖 Generated with Claude Code

…iles

Move slow scipy.integrate.quad-based methods to standalone reference scripts
in autolens_workspace_test. The actual deflection calculations already use
MGE or CSE decompositions; the integrals were only used for testing.

Removed: deflections_2d_via_integral_from, deflection_func from Gaussian,
Sersic, SersicGradient, NFW, gNFW, gNFWSph. Removed integral-based
potential_2d_from and potential_func from elliptical NFW and gNFW. Removed
dead tabulate_integral from AbstractgNFW.

Kept gNFW.convergence_func (essential for convergence_2d_from and MGE).

Updated comparison tests to use hardcoded expected values instead of
calling integral methods.

Closes #323

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@Jammy2211
Copy link
Copy Markdown
Collaborator Author

Workspace PR: PyAutoLabs/autolens_workspace_test#13

@Jammy2211 Jammy2211 merged commit 3a8ddd9 into main Apr 6, 2026
2 checks passed
@Jammy2211 Jammy2211 deleted the feature/remove-deflection-integral branch April 6, 2026 19:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant