-
Notifications
You must be signed in to change notification settings - Fork 11
ENH: Free-threading support #330
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
Merged
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
Large diffs are not rendered by default.
Oops, something went wrong.
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,8 +3,14 @@ | |
from __future__ import annotations | ||
|
||
from enum import Enum | ||
from typing import Any | ||
|
||
__all__ = ["Backend"] | ||
import numpy as np | ||
import pytest | ||
|
||
__all__ = ["NUMPY_VERSION", "Backend"] | ||
|
||
NUMPY_VERSION = tuple(int(v) for v in np.__version__.split(".")[:3]) # pyright: ignore[reportUnknownArgumentType] | ||
|
||
|
||
class Backend(Enum): # numpydoc ignore=PR02 | ||
|
@@ -30,12 +36,6 @@ class Backend(Enum): # numpydoc ignore=PR02 | |
JAX = "jax.numpy" | ||
JAX_GPU = "jax.numpy:gpu" | ||
|
||
def __str__(self) -> str: # pyright: ignore[reportImplicitOverride] # numpydoc ignore=RT01 | ||
"""Pretty-print parameterized test names.""" | ||
return ( | ||
self.name.lower().replace("_gpu", ":gpu").replace("_readonly", ":readonly") | ||
) | ||
|
||
@property | ||
def modname(self) -> str: # numpydoc ignore=RT01 | ||
"""Module name to be imported.""" | ||
|
@@ -44,3 +44,29 @@ def modname(self) -> str: # numpydoc ignore=RT01 | |
def like(self, *others: Backend) -> bool: # numpydoc ignore=PR01,RT01 | ||
"""Check if this backend uses the same module as others.""" | ||
return any(self.modname == other.modname for other in others) | ||
|
||
def pytest_param(self) -> Any: | ||
""" | ||
Backend as a pytest parameter | ||
|
||
Returns | ||
------- | ||
pytest.mark.ParameterSet | ||
""" | ||
id_ = ( | ||
self.name.lower().replace("_gpu", ":gpu").replace("_readonly", ":readonly") | ||
) | ||
|
||
marks = [] | ||
if self.like(Backend.ARRAY_API_STRICT): | ||
marks.append( | ||
pytest.mark.skipif( | ||
NUMPY_VERSION < (1, 26), | ||
reason="array_api_strict is untested on NumPy <1.26", | ||
) | ||
) | ||
if self.like(Backend.DASK, Backend.JAX): | ||
# Monkey-patched by lazy_xp_function | ||
marks.append(pytest.mark.thread_unsafe) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I guess this is unavoidable but it's a little bit of a bummer. Makes me think as a long-term item we should figure out how to get e.g. |
||
|
||
return pytest.param(self, id=id_, marks=marks) # pyright: ignore[reportUnknownArgumentType] |
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
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
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
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
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
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
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The whole library has 1 stateful class,
at
, which has trivial state. So no point adding tests beyond those ofpytest-run-parallel
.Where we are thread-unsafe, in
lazy_xp_function
, it is clearly documented, so I believe this should qualify for the Stable badge?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@ngoldbaum perhaps you could confirm?