Skip to content
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

gh-439: infrastructure for testing array API compatibility #459

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

Conversation

Saransh-cpp
Copy link
Member

@Saransh-cpp Saransh-cpp commented Nov 26, 2024

Inspired heavily from SciPy's infrastructure, this PR adds a way to test array API compatibility (more specifically, array_api_strict and jax, which can be easily scaled to other libraries in the future).

SciPy does in fact test its functions on every supported array library, instead of just relying on array_api_strict. array_api_strict will test the shared functionality, but will fail to identify functionalities which are not standardized and where libraries deviate from each other (such as immutability in jax); hence, testing with every library sounds like a good idea.

Closes: #439

@Saransh-cpp Saransh-cpp added array-api Work is related to the Array API testing Work is related to testing labels Nov 26, 2024
@Saransh-cpp Saransh-cpp self-assigned this Nov 26, 2024
@Saransh-cpp Saransh-cpp changed the title gh-439: a framework for testing array API compatibility gh-439: infrastructure for testing array API compatibility Nov 26, 2024
@Saransh-cpp
Copy link
Member Author

pre-commit.ci autofix

@Saransh-cpp
Copy link
Member Author

@paddyroddy @ntessore this should be ready for review. See the infrastructure in action in #423 -

image image

Copy link
Member

@paddyroddy paddyroddy left a comment

Choose a reason for hiding this comment

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

Looks great! Have you got a link to what SciPy do?

noxfile.py Outdated Show resolved Hide resolved
CONTRIBUTING.md Outdated Show resolved Hide resolved
CONTRIBUTING.md Outdated Show resolved Hide resolved
tests/conftest.py Outdated Show resolved Hide resolved
Comment on lines +95 to +99
# use this as a decorator for tests involving array API compatible functions
array_api_compatible = pytest.mark.parametrize("xp", xp_available_backends.values())
Copy link
Member

Choose a reason for hiding this comment

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

I wonder if all of this stuff should go in its own file, so that only this line features here?

Copy link
Member Author

Choose a reason for hiding this comment

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

In my opinion all the common testing utilities should go directly into conftest.py because that is the sole use of this file (even if it gets crowded).

Copy link
Member

Choose a reason for hiding this comment

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

Fair enough. I'm just concerned that it can make it harder for others to contribute. Would be good for it to be as neat and granular as possible.

@Saransh-cpp
Copy link
Member Author

Saransh-cpp commented Nov 27, 2024

Have you got a link to what SciPy do?

Here it is - https://github.com/scipy/scipy/blob/36e349b6afbea057cb713fc314296f10d55194cc/scipy/conftest.py#L139

They have loads of utility functions defined in that section that we might need someday in the future. Maybe I should link this in the file for future reference.

@ntessore
Copy link
Collaborator

Fantastic effort @Saransh-cpp! Only one question: why aren't we testing with numpy?

@paddyroddy
Copy link
Member

They have loads of utility functions defined in that section that we might need someday in the future. Maybe I should link this in the file for future reference.

Yeah I think that would be a good idea

CONTRIBUTING.md Outdated Show resolved Hide resolved
@Saransh-cpp
Copy link
Member Author

Only one question: why aren't we testing with numpy?

We are! The screenshot above does not show the [numpy] case as that did not fail. Moreover, if a dev does not specify any backend, the code is by default tested only on numpy.

@ntessore
Copy link
Collaborator

Only one question: why aren't we testing with numpy?

We are! The screenshot above does not show the [numpy] case as that did not fail. Moreover, if a dev does not specify any backend, the code is by default tested only on numpy.

Oh, I see: it's not in the default ARRAY_BACKENDS list but added in the processing of "all", got it! Fantastic!

@Saransh-cpp
Copy link
Member Author

Ah, yes, for noxfile - given that we are already installing numpy as part of requirements.txt, it is not installed as a separate step/elif condition.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
array-api Work is related to the Array API testing Work is related to testing
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Array API: Testing
3 participants