Overview
Create a comprehensive self-consistency test suite for every mass profile in PyAutoGalaxy. The suite verifies that convergence, potential, deflections, and shear are internally consistent using generic lensing relations (divergence, gradient, Laplacian) computed via numerical differentiation — independent of the source code implementation. This is the safety net for the broader mass profiles refactoring effort (PyAutoLabs/PyAutoGalaxy#445).
Plan
- Create
scripts/mass/ in autolens_workspace_test with one script per profile category (total, dark, stellar, sheets, point)
- Each script instantiates every profile with representative parameters and checks lensing relations: div(α)=2κ, ∇ψ=α, ∇²ψ=2κ
- Profiles returning zeros for convergence or potential are documented as SKIP with clear notes
- Cross-check against existing
mass_via_integral/ reference implementations (NFW, Sersic, etc.)
- Support
PYAUTO_MASS_FAST env var for quick CI validation (smaller grids, looser tolerances)
- Print summary table at end of each script: PASS/FAIL/SKIP per profile per relation
Detailed implementation plan
Affected Repositories
- autolens_workspace_test (primary)
- PyAutoGalaxy (read-only reference)
Work Classification
Workspace
Branch Survey
| Repository |
Current Branch |
Dirty? |
| autolens_workspace_test |
main |
yes (modified datasets, untracked scripts) |
| PyAutoGalaxy |
main |
yes (modified CLAUDE.md) |
Suggested branch: feature/mass-self-consistency-tests
Worktree root: ~/Code/PyAutoLabs-wt/mass-self-consistency-tests/
Implementation Steps
-
Create scripts/mass/__init__.py and shared utility module scripts/mass/util.py with:
check_div_alpha_eq_2kappa(profile, grid) — divergence of deflections vs 2× convergence
check_grad_psi_eq_alpha(profile, grid) — gradient of potential vs deflections
check_laplacian_psi_eq_2kappa(profile, grid) — Laplacian of potential vs 2× convergence
check_shear_consistency(profile, grid) — shear from Hessian vs deflection derivatives
make_grid(fast=False) — returns appropriate grid based on PYAUTO_MASS_FAST
print_summary_table(results) — formatted PASS/FAIL/SKIP table
- All checks use
np.gradient on 2D native arrays, excluding 2-pixel boundary
-
Write scripts/mass/total.py:
- Isothermal, IsothermalSph, IsothermalCore, IsothermalCoreSph
- PowerLaw, PowerLawSph, PowerLawCore, PowerLawCoreSph
- PowerLawBroken, PowerLawBrokenSph (potential SKIP — returns zeros)
- PowerLawMultipole (convergence SKIP — returns zeros, physically correct)
- PIEMass, dPIEMass, dPIEMassSph (potential SKIP for dPIEMass)
- dPIEPotential, dPIEPotentialSph (potential SKIP — returns zeros)
-
Write scripts/mass/dark.py:
- NFW, NFWSph (full check + cross-ref with mass_via_integral/nfw.py)
- gNFW, gNFWSph (cross-ref with mass_via_integral/gnfw.py)
- cNFW, cNFWSph (convergence + potential SKIP — both return zeros)
- NFWTruncatedSph (potential SKIP — returns zeros)
- MCR/Scatter/Virial variants — deflections and convergence only (same underlying math)
-
Write scripts/mass/stellar.py:
- Sersic, SersicSph (potential SKIP — returns zeros; cross-ref mass_via_integral/sersic.py)
- SersicCore, SersicCoreSph
- SersicGradient, SersicGradientSph (cross-ref mass_via_integral/sersic_gradient.py)
- Gaussian (potential SKIP; cross-ref mass_via_integral/gaussian.py)
- GaussianGradient
- Exponential, ExponentialSph
- DevVaucouleurs, DevVaucouleursSph
- Chameleon, ChameleonSph (potential SKIP)
-
Write scripts/mass/sheets.py:
- ExternalShear (convergence SKIP — physically zero)
- MassSheet (potential SKIP — returns zeros)
- ExternalPotential
-
Write scripts/mass/point.py:
- PointMass (potential SKIP — returns zeros)
- SMBH
- SMBHBinary
Key Files
scripts/mass/util.py — shared numerical differentiation utilities
scripts/mass/total.py — total mass profile tests
scripts/mass/dark.py — dark matter profile tests
scripts/mass/stellar.py — stellar mass profile tests
scripts/mass/sheets.py — sheet/perturbation profile tests
scripts/mass/point.py — point mass profile tests
scripts/mass_via_integral/ — existing reference implementations (read-only)
Original Prompt
Click to expand starting prompt
Build a comprehensive self-consistency test suite for every mass profile in PyAutoGalaxy.
Create scripts/mass/ in autolens_workspace_test with scripts that verify the internal mathematical consistency of every mass profile independently of the source code implementation. This is the safety net for the broader mass profiles refactoring effort (z_features/mass_profiles_refactor.md).
One script per mass profile category under scripts/mass/: total.py, dark.py, stellar.py, sheets.py, point.py. Each verifies lensing relations (div(alpha)=2kappa, grad(psi)=alpha, laplacian(psi)=2kappa) via numerical differentiation, cross-checks against mass_via_integral/ reference implementations, and supports PYAUTO_MASS_FAST for quick validation.
Overview
Create a comprehensive self-consistency test suite for every mass profile in PyAutoGalaxy. The suite verifies that convergence, potential, deflections, and shear are internally consistent using generic lensing relations (divergence, gradient, Laplacian) computed via numerical differentiation — independent of the source code implementation. This is the safety net for the broader mass profiles refactoring effort (PyAutoLabs/PyAutoGalaxy#445).
Plan
scripts/mass/in autolens_workspace_test with one script per profile category (total, dark, stellar, sheets, point)mass_via_integral/reference implementations (NFW, Sersic, etc.)PYAUTO_MASS_FASTenv var for quick CI validation (smaller grids, looser tolerances)Detailed implementation plan
Affected Repositories
Work Classification
Workspace
Branch Survey
Suggested branch:
feature/mass-self-consistency-testsWorktree root:
~/Code/PyAutoLabs-wt/mass-self-consistency-tests/Implementation Steps
Create
scripts/mass/__init__.pyand shared utility modulescripts/mass/util.pywith:check_div_alpha_eq_2kappa(profile, grid)— divergence of deflections vs 2× convergencecheck_grad_psi_eq_alpha(profile, grid)— gradient of potential vs deflectionscheck_laplacian_psi_eq_2kappa(profile, grid)— Laplacian of potential vs 2× convergencecheck_shear_consistency(profile, grid)— shear from Hessian vs deflection derivativesmake_grid(fast=False)— returns appropriate grid based onPYAUTO_MASS_FASTprint_summary_table(results)— formatted PASS/FAIL/SKIP tablenp.gradienton 2D native arrays, excluding 2-pixel boundaryWrite
scripts/mass/total.py:Write
scripts/mass/dark.py:Write
scripts/mass/stellar.py:Write
scripts/mass/sheets.py:Write
scripts/mass/point.py:Key Files
scripts/mass/util.py— shared numerical differentiation utilitiesscripts/mass/total.py— total mass profile testsscripts/mass/dark.py— dark matter profile testsscripts/mass/stellar.py— stellar mass profile testsscripts/mass/sheets.py— sheet/perturbation profile testsscripts/mass/point.py— point mass profile testsscripts/mass_via_integral/— existing reference implementations (read-only)Original Prompt
Click to expand starting prompt
Build a comprehensive self-consistency test suite for every mass profile in PyAutoGalaxy.
Create
scripts/mass/in autolens_workspace_test with scripts that verify the internal mathematical consistency of every mass profile independently of the source code implementation. This is the safety net for the broader mass profiles refactoring effort (z_features/mass_profiles_refactor.md).One script per mass profile category under
scripts/mass/: total.py, dark.py, stellar.py, sheets.py, point.py. Each verifies lensing relations (div(alpha)=2kappa, grad(psi)=alpha, laplacian(psi)=2kappa) via numerical differentiation, cross-checks against mass_via_integral/ reference implementations, and supports PYAUTO_MASS_FAST for quick validation.