Skip to content

Feature/gaussian mass#265

Merged
NiekWielders merged 20 commits intomainfrom
feature/gaussian_mass
Jan 28, 2026
Merged

Feature/gaussian mass#265
NiekWielders merged 20 commits intomainfrom
feature/gaussian_mass

Conversation

@NiekWielders
Copy link
Copy Markdown
Collaborator

@NiekWielders NiekWielders commented Jan 27, 2026

This pull request makes significant changes to the implementation of the Gaussian mass profile in autogalaxy, primarily focusing on improving compatibility with array libraries like JAX, simplifying the code, and deprecating the integral-based deflection calculation in favor of the analytic approach. The most important changes are grouped below:

Core algorithm and compatibility improvements

  • Refactored the zeta_from method in Gaussian to a new, more efficient and JAX-compatible implementation, including a custom wofz (Faddeeva function) for use with both NumPy and JAX backends. The new implementation replaces the previous approach that used scipy.special.wofz directly, and ensures symmetry and compatibility with autodiff and JIT compilation.
  • Updated all relevant methods in Gaussian to use the xp (array module) argument instead of hardcoded np, ensuring compatibility with both NumPy and JAX throughout the profile calculations. [1] [2] [3]

Removal and deprecation of legacy/integral code

  • Commented out the integral-based deflection calculation method deflections_2d_via_integral_from and its associated test cases, indicating a shift to exclusively using the analytic solution for deflection calculations. This simplifies the codebase and reduces maintenance overhead. [1] [2]
  • Updated the deflections_yx_2d_from method to remove a now-unnecessary zero-intensity check and commented out legacy code, further simplifying the logic and relying solely on the analytic approach.

Minor code and import cleanups

  • Updated the import statements in autogalaxy/__init__.py to comment out unused imports related to interferometer curvature preloads.
  • Minor code formatting and whitespace adjustments for clarity and consistency.

These changes collectively improve the maintainability, performance, and future-proofing of the Gaussian mass profile implementation in autogalaxy.gaussian.py in mass profiles made to be used in jax.

Commented out the deflections_2d_via_integral_from and the tests in which it is contained.

Changed
defl = self.deflections_2d_via_analytic_from(grid=grid, xp=xp, **kwargs) return xp.where(self.intensity == 0.0, xp.zeros_like(defl), defl)
back to
return self.deflections_2d_via_analytic_from(grid=grid, xp=xp, **kwargs)
as the tests did not come through:
FAILED test_autogalaxy/profiles/test_light_and_mass_profiles.py::test__gaussian - AttributeError: 'numpy.ndarray' object has no attribute 'array'
FAILED test_autogalaxy/profiles/test_light_and_mass_profiles.py::test__gaussian_gradient - AttributeError: 'numpy.ndarray' object has no attribute 'array'

Copy link
Copy Markdown
Collaborator

@Jammy2211 Jammy2211 left a comment

Choose a reason for hiding this comment

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

  • Delete commented out code.
  • Make sure there are no module-level imports of JAX.
  • Do anything from copilot you think sounds important.

Then good to merge!

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 pull request makes the Gaussian mass profile JAX-compatible by replacing NumPy-specific operations with a generic xp parameter that can accept either NumPy or JAX arrays. The main changes involve refactoring mathematical operations to work with both array libraries and implementing a custom JAX-compatible Faddeeva function (wofz).

Changes:

  • Replaced np calls with xp parameter throughout gaussian.py for JAX compatibility
  • Implemented custom JAX-compatible wofz (Faddeeva function) to replace scipy.special.wofz
  • Commented out scipy-dependent deflections_2d_via_integral_from method and related tests

Reviewed changes

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

File Description
test_autogalaxy/profiles/mass/stellar/test_gaussian.py Commented out tests for scipy-dependent integral methods that are not JAX-compatible
autogalaxy/profiles/mass/stellar/gaussian.py Converted np operations to xp, implemented custom wofz function, refactored zeta_from for JAX compatibility, commented out scipy-dependent methods
autogalaxy/init.py Commented out import from autoarray.dataset.interferometer.w_tilde

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

@@ -6,9 +6,9 @@

from autoconf.dictable import from_dict, from_json, output_to_json, to_dict
from autoarray.dataset import preprocess # noqa
Copy link

Copilot AI Jan 28, 2026

Choose a reason for hiding this comment

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

The import from autoarray.dataset.interferometer.w_tilde has been commented out without explanation. If this import is no longer needed or causes issues, it should be removed entirely rather than commented out. If it's needed but temporarily causing issues, a TODO comment should explain why it's commented and what needs to be done to re-enable it.

Suggested change
from autoarray.dataset import preprocess # noqa
from autoarray.dataset import preprocess # noqa
# TODO: This import is temporarily disabled because autoarray.dataset.interferometer.w_tilde
# TODO: may not be available or compatible in all environments. Re-enable once the module
# TODO: and load_curvature_preload_if_compatible are confirmed to be stable and required.

Copilot uses AI. Check for mistakes.
@NiekWielders NiekWielders merged commit 08e7e64 into main Jan 28, 2026
8 checks passed
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.

3 participants