Skip to content

feature/geometry_hot_fix#274

Merged
Jammy2211 merged 1 commit intomainfrom
feature/geometry_hot_fix
Feb 7, 2026
Merged

feature/geometry_hot_fix#274
Jammy2211 merged 1 commit intomainfrom
feature/geometry_hot_fix

Conversation

@Jammy2211
Copy link
Copy Markdown
Collaborator

@Jammy2211 Jammy2211 commented Feb 7, 2026

This pull request makes a minor change to the calculation of Cartesian grid coordinates from radial coordinates in geometry_profiles.py.

This is motivated by a JAX tracing issue which leads to NaN in the defleciton angles of certain mass profile like the IsothermalSph. This occurs only on GPU and when tracing via a full tracer. This PR does not fix the underlying issue, which is likely a JAX tracing bug, but is a hot fix which means lens modeling runs OK for now.

The main update is to use direct trigonometric functions for angle conversion, simplifying the code and potentially improving performance.

Improvements to coordinate calculation:

  • autogalaxy/profiles/geometry_profiles.py: Replaced the call to angle_to_profile_grid_from with direct calculation of cos_theta and sin_theta using xp.cos and xp.sin, removing unnecessary indirection.

Minor code cleanup:

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR updates a shared geometry helper used to convert radial coordinates back into Cartesian coordinates, aiming to simplify angle handling by using direct trigonometric calls, plus a small call-site cleanup for readability.

Changes:

  • Updated SphProfile._cartesian_grid_via_radial_from to compute cos_theta / sin_theta directly via xp.cos / xp.sin.
  • Reordered keyword arguments in an IsothermalSph.deflections_yx_2d_from call for clarity (no functional change).

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.

File Description
autogalaxy/profiles/geometry_profiles.py Simplifies angle-to-(sin,cos) computation inside _cartesian_grid_via_radial_from.
autogalaxy/profiles/mass/total/isothermal.py Reorders keyword arguments in a helper call for readability.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +109 to +110
cos_theta = xp.cos(grid_angles)
sin_theta = xp.sin(grid_angles)
Copy link

Copilot AI Feb 7, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

_cartesian_grid_via_radial_from previously delegated to self.angle_to_profile_grid_from(...), which is overridden by EllProfile to account for the profile’s position angle. Replacing it with xp.cos/sin(grid_angles) bypasses that override and changes behavior for any subclass with a non-zero angle that calls this helper. Consider restoring the call to self.angle_to_profile_grid_from(...), or (if the intent is to always ignore the profile angle because the grid is already in the profile reference frame) add an explicit comment and/or use a clearly-named helper to avoid silently breaking polymorphism.

Suggested change
cos_theta = xp.cos(grid_angles)
sin_theta = xp.sin(grid_angles)
# Use angle_to_profile_grid_from so subclasses (e.g. with non-zero position angle)
# can override how angles are converted to Cartesian directions.
cos_theta, sin_theta = self.angle_to_profile_grid_from(
grid_angles=grid_angles, xp=xp, **kwargs
)

Copilot uses AI. Check for mistakes.
Comment on lines 107 to 112
grid_angles = xp.arctan2(grid.array[:, 0], grid.array[:, 1])
cos_theta, sin_theta = self.angle_to_profile_grid_from(
grid_angles=grid_angles, xp=xp
)

cos_theta = xp.cos(grid_angles)
sin_theta = xp.sin(grid_angles)

return xp.multiply(radius[:, None], xp.vstack((sin_theta, cos_theta)).T)
Copy link

Copilot AI Feb 7, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This change alters the angle-to-(sin,cos) conversion path used by _cartesian_grid_via_radial_from, but there’s no unit test covering this helper (e.g. verifying the returned Cartesian vectors for known input grids/radii, including a rotated EllProfile case if overrides are expected to apply). Adding a focused test would help prevent regressions in coordinate conversion.

Copilot uses AI. Check for mistakes.
@Jammy2211 Jammy2211 merged commit d8f68e2 into main Feb 7, 2026
14 checks passed
@Jammy2211 Jammy2211 deleted the feature/geometry_hot_fix branch February 13, 2026 13:43
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.

2 participants