feat: vmapped_deflections_from for batched subhalo deflections#455
Merged
Conversation
…x.vmap Adds a generic vmapped deflection path on MassProfile that computes summed deflections from N subhalos in a single GPU launch. Each spherical profile provides a small radial_deflection_from static method (the profile-specific physics); the generic wrapper handles centre subtraction, radial distance, cartesian reconstruction, masking, and summing — written once on the base class. Implemented for NFWTruncatedSph and cNFWSph. Unsupported profiles raise NotImplementedError with a clear message. Ref: PyAutoLens#542 prompt 1. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
MassProfile.vmapped_deflections_from(grid, params_batch, mask)— a generic classmethod that usesjax.vmapto compute summed deflections from N subhalos in a single GPU launchradial_deflection_fromstatic method (just the physics formula); the generic wrapper on the base class handles centre subtraction, radial distance, cartesian reconstruction, masking, and summingNFWTruncatedSphandcNFWSph; unsupported profiles raiseNotImplementedErrorwith contact infocoord_func_f_from,coord_func_k_from,coord_func_m_from,F_func_from,dev_F_func_from) to module level soradial_deflection_fromcan call them without an instance; existing instance methods delegate to themAPI Changes
New methods on
MassProfile:MassProfile.vmapped_deflections_from(grid, params_batch, mask, xp=None)— classmethodMassProfile.radial_deflection_from(r, params, xp)— static method (default raisesNotImplementedError)New static methods:
NFWTruncatedSph.radial_deflection_from(r, params, xp)— params =[kappa_s, scale_radius, truncation_radius]cNFWSph.radial_deflection_from(r, params, xp)— params =[kappa_s, scale_radius, core_radius]New module-level functions:
abstract.coord_func_f_from(grid_radius, xp)nfw_truncated.coord_func_k_from(grid_radius, tau, xp)nfw_truncated.coord_func_m_from(grid_radius, tau, xp)cnfw.F_func_from(theta, radius, xp)cnfw.dev_F_func_from(theta, radius, xp)Test plan
test_nfw_truncated.py,test_cnfw.py)scripts/jax_substructure/test_vmap_deflections.py— NFWTruncated parity, cNFW parity, masking, JIT, error messageRef: PyAutoLens#542 (prompt 1 of 4)
🤖 Generated with Claude Code