TST: use xpx.testing assertions#25143
Conversation
Signed-off-by: Pradyot Ranjan <[email protected]>
Signed-off-by: Pradyot Ranjan <[email protected]>
Signed-off-by: Pradyot Ranjan <[email protected]>
|
We have 8 total failures. All of them are expected namespace mismatch failures, as |
Signed-off-by: Pradyot Ranjan <[email protected]>
Co-authored-by: Lucas Colley <[email protected]>
Signed-off-by: Pradyot Ranjan <[email protected]>
| if xp is None: | ||
| try: | ||
| xp = _default_xp_ctxvar.get() |
There was a problem hiding this comment.
just a thought, I wonder whether this is something that could be ported to xpx.testing...
There was a problem hiding this comment.
For that, we will have to keep xp as a keyword argument inside the xp_assert function in array_api_extra. Could be useful, also:
try:
xp = _default_xp_ctxvar.get()Would help in accessing the namespace if the test is run inside a context manager. Something like
with default_xp(torch):
There was a problem hiding this comment.
Right, I think a good first step would be to add an xp=None parameter to the assertions in array-api-extra, then copy across
scipy/scipy/_lib/_array_api.py
Lines 264 to 279 in 7fcf4fb
Then perhaps we can see, with the example of scikit-image, whether anything relating to the context manager should also be ported over.
There was a problem hiding this comment.
Well, for this code to make sense, we need to have the context manager first. I've opened a PR, lets move this discussion: data-apis/array-api-extra#747
xpx.testing assertions
Signed-off-by: Pradyot Ranjan <[email protected]>
|
The GPU failures demonstrate something we need to address — The 'install into venv' failure I think can be addressed when we make the assertions public by ensuring that their module does not depend on
That's probably something we want to fix over in array-api-extra. |
I think we should try explicitly accepting 0-D arrays in array-api-extra for these parameters, but rejecting higher-dimensional arrays. If there are a bunch of failures for 1-D arrays with a single element then maybe it makes sense to accept that also. |
I don't know much about pytorch tensors, but can we do float(4e-16 * ref.integral)In the tests to make this work? |
|
But ofc this won't be a proper fix as we need to address these inputs in the extra module. |
|
What I am proposing is something like (in array-api-extra): actual_np = as_numpy_array(actual, xp=xp)
desired_np = as_numpy_array(desired, xp=xp)
if not isinstance(atol, float):
atol = as_numpy_array(atol, xp=xp)
if atol.ndim > 0:
# raise error
if not isinstance(rtol, float):
rtol = as_numpy_array(rtol, xp=xp)
if rtol.ndim > 0:
# raise error
np.testing.assert_allclose(actual_np, desired_np, atol, rtol, ...) |
|
Makes sense. Let me open a PR in |
Signed-off-by: Pradyot Ranjan <[email protected]>
|
I think we want to add to https://github.com/data-apis/array-api-extra/blob/main/src/array_api_extra/_lib/_testing.py#L126-L127 |
|
Having a single canonical set of assertions across the ecosystem would be very valuable indeed. Now, the scipy versions have had a lot of effort and polishing. They have basically stabilized a while ago and have been shown to work in a non-trivial project (scipy). Decisions like whether to wrap native asserions vs convert to numpy etc have already been discussed extensively, so what would be a reason to re-discover issues like pytorch conjugation bits #25143 (comment)? The array-api-extra versions are IIUC adapted from the scipy versions, and simplified to meet internal needs of So I'd expect that this is what happens: copy-paste the scipy versions into array-api-strict, and have a clear summary/discussion of where the line is drawn between "scipy-specific" and "generally useful". Is this not what's going on here? |
Yes, that's exactly what we are trying to do. I have already discussed a few things, scipy testing functions and the array_api_extras function does differently in the PR discussion. Our current tests match very closely with |
Then #25143 (comment) shouldn't be even a thing because this was figured in the scipy versions long long time ago. |
|
(I assume you mean array-api-extra when you say array-api-strict)
I'm not so sure... I have a feeling this is basically a decision I made a few years ago that seemed alright to those involved at the time.
When @crusaderky was working on adding primitive versions of these assertions for array-api-extra, I think it became clear that wrapping of native assertions was itself a scipy-specific historical quirk that we didn't have good reason to keep around. At the time, when I was getting to grips with the array API standard, I think I was too much in the mindset of 'keep everything native where possible' — now, I don't think such a heuristic applies so simply to the test-suite. I'm happy to take the blame for that, although it was one of the first things I ever worked on 😉. Unfortunately, there is no clear summary/discussion accurate to the current state, as the development has been dispersed across multiple years. @crusaderky highlighted the main initial differences (aside from the non-use of native assertions) at data-apis/array-api-extra#17 (comment), but since then @mdhaber and @prady0t have worked on adding missing features that SciPy and scikit-learn need. Is there anything in particular you are worried about being missing / erroneously dropped from the SciPy versions? Perhaps you are worried that we are silently dropping strictness? I'm pretty confident that we haven't missed anything crucial — Guido and Matt spent a significant amount of time on this initially, and the importance of @prady0t's work now is to help demonstrate that in CI. But the purpose of this PR is to figure out precisely if we are missing anything. If a full write-up of the differences between the SciPy versions and the xpx versions is what is required to get this merged, then we should do that eventually once we have the public API in |
|
Well, we are trying to always convert to numpy with this PR. Scipy uses |
That's not true — this isn't a problem that was 'figured out' in SciPy a long time ago. It is a problem that was entirely avoided by the decision to wrap native assertions (which, to be fair, I don't know if you were involved in at all). If you feel strongly that wrapping native assertions is the way to go, then we could have a new discussion on that (probably in a new array-api-extra issue?). But let's avoid assuming that because something was decided in SciPy years ago, it is the gold-standard against which alternatives must prove their legitimacy. I certainly trust my judgement now more than my judgement back then, at least 😅 |
Indeed a typo, thanks! (native assertions vs np.testing)
Okay, did not know it was your decision back then. The decision worked quite well (kudos!), and I'm just surprised there's a need to redesign. It certainly ain't broken. Taking a step back, the main feature of assertions is that they are stable and "boring", so that when porting a library or writing a new library, the author can concentrate on the functionality and rely on assertions just doing the right thing. What exactly is the right thing can be open to discussions of course, and we had way too many of those in scipy at least (I'm sure elsewhere too), which is why I thought they just work, and there's no need to rewrite then stabilize them, again. As a data point, I'm currently working on adding array api support to scikit-image. The first thing I did was to drop the scipy assertions in-tree, with an expectation that they'll make their way to So from this perspective, what's most important for porting a new library:
|
Yeah, part of the motivation for avoiding use of native assertions is for this kind of stability (or at least consistency) — we don't want to have to deal with bugs or nuances of various different I think you have a good argument if the question was "should we put in a bunch of thought to re-write these now?" But really, that work has already been done by Guido and Matt, so I think we are right to make use of it (presuming, fairly, that that work is of good quality).
Let's check what changes would be required before we finalise the public API! Would you be willing to try these out in scikit-image and report any difficulties? I already have my eyes on wilsonrljr/sysidentpy#232 and glass-dev/glass#1076 too.
I think this may be the key remaining area of work. |
Signed-off-by: Pradyot Ranjan <[email protected]>
Signed-off-by: Pradyot Ranjan <[email protected]>
I think these are useful points. Numpy also has a |
I would wait until it is explicitly requested, the finer grained parameters we have already are better IMO. |
True. |
|
All checks are passing now! |
|
nice, I think #25143 (comment) is the next step |
Signed-off-by: Pradyot Ranjan <[email protected]>
|
Only |
Let's leave it for now, but yes let's return to it when we bring this PR out of draft. |
[skip circle]
92416b6 to
4e0a864
Compare
Reference issue
What does this implement/fix?
This is a draft PR to check how much we have progressed with
xp_assertfunctions in thearray_api_extralibrary. We are checking how easy it is for other libraries to implement these testing functions in their existing test suite.Additional information
This is to remain a draft PR for reference. In case we want to merge it, I can put some effort into cleaning it and making some necessary changes in the
test_array_api.pyfile. There are 2 things different in thearray_api_extraversion of tests from scipy:array_api_extraversion. SeeI've made some efforts to take these into account and reduce the number of failing tests by checking for Python scalars and lists, and converting them with
xp.asarraybefore feeding them toarray_api_extra.Most test failures are due to our inability to disable namespace checks; they originate from
test_array_api.py.See:
AI Generation Disclosure
No AI tools used