Skip to content

Adopt the array api #885

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 83 commits into
base: main
Choose a base branch
from
Open

Adopt the array api #885

wants to merge 83 commits into from

Conversation

mwcraig
Copy link
Member

@mwcraig mwcraig commented Mar 19, 2025

This PR makes the necessary changes to adopt the array API. There are still some things to sort out:

  • Run tests mostly against numpy, but do one run against jax (or some other non-numpy array library)
  • Check for remaining invocations of numpy in the code.
  • Check whether changing .data_arr.mask to .data_arr_mask constitutes an API change. If it does (and I think it does) then patch things up so that .data_arr.mask points to .data_arr_mask
  • Clean up any remaining handling of immutable arrays (array_api_extra makes handling those easy)

Once those are done the next step will be to find an outside reviewer for this...

@mwcraig mwcraig added this to the 2.5.0 milestone Mar 19, 2025
Copy link

codecov bot commented Mar 20, 2025

Codecov Report

❌ Patch coverage is 95.28302% with 20 lines in your changes missing coverage. Please review.
⚠️ Please upload report for BASE (main@5aa9219). Learn more about missing BASE report.
⚠️ Report is 13 commits behind head on main.

Files with missing lines Patch % Lines
ccdproc/_ccddata_wrapper_for_array_api.py 86.72% 15 Missing ⚠️
ccdproc/core.py 97.94% 3 Missing ⚠️
ccdproc/image_collection.py 92.30% 2 Missing ⚠️
Additional details and impacted files
@@           Coverage Diff           @@
##             main     #885   +/-   ##
=======================================
  Coverage        ?   97.03%           
=======================================
  Files           ?        8           
  Lines           ?     1518           
  Branches        ?        0           
=======================================
  Hits            ?     1473           
  Misses          ?       45           
  Partials        ?        0           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@mwcraig mwcraig force-pushed the explore-array-api branch from 85625f0 to 04293b7 Compare March 27, 2025 18:05
@mwcraig mwcraig marked this pull request as ready for review June 24, 2025 14:55
@mwcraig mwcraig changed the title WIP: Adopt the array api Adopt the array api Jun 24, 2025
@mwcraig mwcraig requested a review from Copilot June 24, 2025 16:42
Copilot

This comment was marked as outdated.

@eteq
Copy link
Member

eteq commented Jun 24, 2025

As a quick FYI I ran the test suite in this PR on a machine with a NVidia GPU with CCDPROC_ARRAY_LIBRARY=cupy and got a whole pile of errors (sent the log directly to @mwcraig but can also share snippets here if someone else wants to see them)

@@ -8,17 +8,19 @@ dynamic = ["version"]
description = "Astropy affiliated package"
readme = "README.rst"
license = { text = "BSD-3-Clause" }
requires-python = ">=3.8"
requires-python = ">=3.11"
Copy link
Member

Choose a reason for hiding this comment

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

Adopt Spec 0? Has that been adopted?

Copy link
Member Author

Choose a reason for hiding this comment

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

Good catch!

Copy link
Member Author

Choose a reason for hiding this comment

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

Wait, misread this -- what is Spectrum 0?

Copy link
Member

Choose a reason for hiding this comment

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

Copy link
Member Author

Choose a reason for hiding this comment

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

So the move here would be to bump it up to 3.12?

Copy link
Member

Choose a reason for hiding this comment

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

3.11 for a few more months. Then 3.12. I was also thinking about adding the badge saying "Spec 0", e.g. you can see in the README in https://github.com/GalacticDynamics/unxt

@@ -8,17 +8,19 @@ dynamic = ["version"]
description = "Astropy affiliated package"
readme = "README.rst"
license = { text = "BSD-3-Clause" }
requires-python = ">=3.8"
requires-python = ">=3.11"
Copy link
Member

Choose a reason for hiding this comment

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

@mwcraig mwcraig force-pushed the explore-array-api branch 3 times, most recently from 2fa76b7 to 3b2b9fc Compare July 3, 2025 18:28
mwcraig added 2 commits July 12, 2025 13:25
This is necessary because CCDData does not implement the array API currently.
@mwcraig mwcraig force-pushed the explore-array-api branch from 8137626 to 6af1e1e Compare July 12, 2025 20:25
Copy link
Member

@nstarman nstarman left a comment

Choose a reason for hiding this comment

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

Hi @mwcraig. LMK how I can be of help with reviews. This PR looks great, and it seems to be mostly down to small line-by-line suggestions.

@mwcraig
Copy link
Member Author

mwcraig commented Jul 17, 2025

Hi @mwcraig. LMK how I can be of help with reviews. This PR looks great, and it seems to be mostly down to small line-by-line suggestions.

Thanks, @nstarman! I'll want one last look once I've tied down a few loose ends. One thing I learned since the coordination meeting is that using np.testing.assert_allclose is a bad idea because it converts any array-like arguments into numpy arrays for the comparison, hiding any mis-match in array name space between the two things being compared. As a result, there are still a few places that I thought were working that were actually converting the data or uncertainty or mask to numpy arrays.

I've switch to using xp.all(xpx.isclose(a, b)) for numerical array comparisons, which raises an exception if a and b are in different namespaces.

I'll ping you when I'm confident that I have all of those cases fixed up.

@mwcraig mwcraig force-pushed the explore-array-api branch from 747d4a4 to 9afb5a6 Compare July 29, 2025 15:00
@mwcraig mwcraig modified the milestones: 2.5.0, 3.0 Jul 29, 2025
@mwcraig mwcraig requested a review from Copilot July 29, 2025 21:52
Copy link

@Copilot 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 makes the necessary changes to adopt the array API across ccdproc. The implementation allows users to leverage different array libraries (JAX, Dask, CuPy) while maintaining backward compatibility with numpy. Key infrastructure is added to support array API operations without changing existing user interfaces.

  • Comprehensive adoption of array API across core processing functions
  • Testing infrastructure for multiple array libraries (numpy, JAX, dask)
  • Updated documentation including new array API guide and examples

Reviewed Changes

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

Show a summary per file
File Description
tox.ini Adds test environments for JAX and Dask array libraries with proper configuration
pyproject.toml Updates dependencies to include array API packages and minimum version requirements
docs/index.rst Adds array API documentation section to table of contents
docs/array_api.rst New comprehensive guide explaining array API usage and library options
ccdproc/core.py Major refactoring to support array API operations throughout processing functions
ccdproc/conftest.py Test infrastructure for selecting array libraries via environment variables
ccdproc/tests/*.py Extensive test updates to work with array API and multiple backends
Comments suppressed due to low confidence (1)

ccdproc/tests/test_combiner.py:746

  • There is a spelling error: 'combiune' should be 'combine'.
    """

with `sparse`_. A `pull request <https://github.com/astropy/ccdproc/pulls>`_ to FIX
that would be a welcome contribution to the project.

What limitations shuold I be aware of?
Copy link
Preview

Copilot AI Jul 29, 2025

Choose a reason for hiding this comment

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

There is a spelling error: 'shuold' should be 'should'.

Suggested change
What limitations shuold I be aware of?
What limitations should I be aware of?

Copilot uses AI. Check for mistakes.

Comment on lines +31 to +32
with `sparse`_. A `pull request <https://github.com/astropy/ccdproc/pulls>`_ to FIX
that would be a welcome contribution to the project.
Copy link
Preview

Copilot AI Jul 29, 2025

Choose a reason for hiding this comment

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

The word 'FIX' appears to be a TODO placeholder that should be replaced with an actual link or removed.

Suggested change
with `sparse`_. A `pull request <https://github.com/astropy/ccdproc/pulls>`_ to FIX
that would be a welcome contribution to the project.
with `sparse`_. A `pull request <https://github.com/astropy/ccdproc/pulls>`_ to add
support for `sparse`_ would be a welcome contribution to the project.

Copilot uses AI. Check for mistakes.

@@ -34,6 +34,7 @@ Detailed, step-by-step guide

In addition to the documentation here, a detailed guide to the topic of CCD
data reduction using ``ccdproc`` and other `astropy`_ tools is available here:
(TODO: FIX LINK BELOW)
Copy link
Preview

Copilot AI Jul 29, 2025

Choose a reason for hiding this comment

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

There is a TODO comment indicating that the link below needs to be fixed. This should be addressed before merging.

Suggested change
(TODO: FIX LINK BELOW)

Copilot uses AI. Check for mistakes.

@@ -334,6 +340,7 @@ def test_combiner_mask_average():
# are masked?!
# assert ccd.data[0, 0] == 0
assert ccd.data[5, 5] == 1
# THE LINE BELOW IS CATCHING A REAL ERROR
Copy link
Preview

Copilot AI Jul 29, 2025

Choose a reason for hiding this comment

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

[nitpick] This comment suggests there may be an unresolved issue with the test. Consider adding more context about what error is being caught and whether it needs to be fixed.

Suggested change
# THE LINE BELOW IS CATCHING A REAL ERROR
# Ensure that the mask is correctly applied to pixels that are fully masked

Copilot uses AI. Check for mistakes.

@@ -8,17 +8,19 @@ dynamic = ["version"]
description = "Astropy affiliated package"
readme = "README.rst"
license = { text = "BSD-3-Clause" }
requires-python = ">=3.8"
requires-python = ">=3.11"
Copy link
Preview

Copilot AI Jul 29, 2025

Choose a reason for hiding this comment

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

The minimum Python version has been increased from 3.8 to 3.11. This is a breaking change that should be clearly documented in the release notes.

Copilot uses AI. Check for mistakes.

@@ -47,10 +50,11 @@ deps =

# Remember to transfer any changes here to setup.cfg also. Only listing
# packages which are constrained in the setup.cfg
Copy link
Preview

Copilot AI Jul 29, 2025

Choose a reason for hiding this comment

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

The oldest supported numpy version has been changed from 1.24 to 1.26. This is a breaking change that should be documented.

Suggested change
# packages which are constrained in the setup.cfg
# packages which are constrained in the setup.cfg
# Note: The oldest supported version of NumPy has been updated from 1.24 to 1.26.
# This is a breaking change and should be taken into account when updating dependencies.

Copilot uses AI. Check for mistakes.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants