Repository navigation
TST: Compat with numpy 1.25.dev - #14718
Conversation
|
Thank you for your contribution to Astropy! 🌌 This checklist is meant to remind the package maintainers who will review this pull request of some common things to look for.
|
|
|
||
| assert np.all(inside_bbox == outside_bbox) | ||
| # FIXME: https://github.com/astropy/astropy/issues/14705 | ||
| # ValueError: operands could not be broadcast together with shapes (1100,) (1099,) |
There was a problem hiding this comment.
Might point to a subtle bug deep within modeling bounding box machinery? 🤷
There was a problem hiding this comment.
Probably an unfortunate rounding error; still, not nice!
There was a problem hiding this comment.
Yeah, if someone knows how to properly fix it in Gaussian2D, that would be better.
There was a problem hiding this comment.
I think the fix has to be here somewhere:
astropy/astropy/modeling/utils.py
Lines 179 to 183 in 252b1c4
There was a problem hiding this comment.
I guess a more hacky alternative is to modify the test case so this won't happen for that test but it is not a real fix.
There was a problem hiding this comment.
I guess it really depends on the goal of the test.... If it was just a sanity check that basically the box was the same, with a slop of 1 pixel due to rounding allowed, then it would be fine to adjust it. But I don't know...
There was a problem hiding this comment.
The part of the test which is failing has nothing to do with the precise construction of the bounding box... Nor does it have anything to do with checking "if the box was the same"... Nor can it be the result of a "rounding error"..
The point of the test where it is failing is showing that a model properly discriminates if the inputs are inside/outside the bounding box when integrated into the model evaluation process.
It specifically constricts two sets of inputs x1, y1, x2, y2 such that:
- All the points in
x1, y1are inx2, y2respectively - All points in
x2, y2not inx1, y1lie outside the bounding box
The model is then evaluated on these points without/with bounding box enforcement respectively (to x1, y1 vs x2, y2). This means that all the outputs corresponding to points outside the bounding box should be set to np.NaN. Consequently, due to the specific construction of x2, y2 relative to x1, y1 it should be the case that all the non np.NaN outputs of both evaluations should exactly correspond without any rounding errors (it is literally an exactly repeated computation).
To see that the assumptions should be satisfied, note that (1) is satisfied by
astropy/astropy/modeling/tests/test_models.py
Lines 233 to 249 in e3b2444
because the construction of
x2, y2 by concatenating points onto x1, y2 respectively.
While (2) is satisfied by the fact that the bounding box limits are used and the additional points are all created strictly -/+idx*ddx where idx != 0, where -/+ is with respect to the lower/upper bounds of the bounding box. This implies that all the additional points are strictly outside the bounding box. There should be no rounding error issues ddx = .01, which is much much larger than machine precision (so well outside any rounding error concerns).
Since bounding boxes discriminate the input points lying outside the box using
astropy/astropy/modeling/bounding_box.py
Lines 118 to 131 in e3b2444
It follows that the endpoints of the bounding box should lie within it (i.e. it defines a closed interval on each axis). So by construction all the inputs in
x1, y1 are inside the bounding box. Therefore, evaluating the model on x1, y1 regardless of bounding box enforcement should result in no np.NaN outputs (Gaussian2D is well behaved on its bounding box intervals). While evaluating the model on x2, y2 should result in np.NaN values for all the points not corresponding to those in x1, y1, while the corresponding points between x1, y1 and x2, y2 should all exactly match.
Note that, the error in question:
ValueError: operands could not be broadcast together with shapes (1100,) (1099,)
Indicates that some point in x1, y1 is being evaluated to np.NaN in the x2, y2 computation. There are a few possibilities:
- The bounding box incorrectly discriminating on the endpoints of the bounding box as those points are specifically included in the computation. Meaning there is an issue with the
>or<comparisons in theoutsidemethod. - Some sort of new numerical issue is causing a
np.NaNoccur when evaluatingGaussian2Don points contained within its bounding box (this is surprising since the default bounding box forGaussian2Dis selected specifically so that no numerical errors should occur when evaluating on points contained within it). - There is an issue with wherein
astropy/astropy/modeling/tests/test_models.py
Line 253 in e3b2444
~np.isnan(...)is incorrectly flagging a non-np.NaNvalue asNaN.
The way I could distinguish between these possibilities would be
- Compare
inside_bboxwithinside_bbox[~np.isnan(inside_bbox)](eliminates/confirms possibility (2)) - and/or Compute
inside_bboxwith thewith_bounding_box=Trueoption (eliminates/confirms possibility (1)) - Manually examine the raw values of
inside_bboxandoutside_bbox(eliminates/confirms possibility (3))
However, I can no-longer reproduce this issue, see #14771 so I cannot exactly determine the cause.
mhvk
left a comment
There was a problem hiding this comment.
Yes, looks good to me, with a possible suggestion, as I'd prefer not to have numbers in their that appear precise but are just set not to trigger failures...
|
|
||
| assert np.all(inside_bbox == outside_bbox) | ||
| # FIXME: https://github.com/astropy/astropy/issues/14705 | ||
| # ValueError: operands could not be broadcast together with shapes (1100,) (1099,) |
There was a problem hiding this comment.
Probably an unfortunate rounding error; still, not nice!
coordinates/tests/test_intermediate_transformations.py tests
larrybradley
left a comment
There was a problem hiding this comment.
LGTM. Like @mhvk, I also suspect the shape mismatch is due to a rounding error.
|
I am not going to even try LTS with this one given the other backport has like 100 failures. Since no one has idea to fix the bounding box for real, just gonna merge this then. Thanks! |
| # FIXME: https://github.com/astropy/astropy/issues/14705 | ||
| # ValueError: operands could not be broadcast together with shapes (1100,) (1099,) | ||
| if model_class != Gaussian2D: | ||
| assert np.all(inside_bbox == outside_bbox) |
There was a problem hiding this comment.
This "fix" is far far too aggressive. The only issue here is with numpy 1.25.dev and at the very least this should be restricted to that case only. As it stands, this "fix" turns off testing in all cases.
There was a problem hiding this comment.
Thanks for the follow up fix of this "fix"!
Revert Gaussian test change from #14718
…718-on-v5.3.x Backport PR #14718 on branch v5.3.x (TST: Compat with numpy 1.25.dev)
…718-on-v5.2.x Backport PR #14718 on branch v5.2.x (TST: Compat with numpy 1.25.dev)
Revert Gaussian test change from astropy#14718
Revert Gaussian test change from astropy#14718
Backport PR 14771 to v5.2.x ( Revert Gaussian test change from #14718)
Backport PR 14771 to v5.3.x ( Revert Gaussian test change from #14718)
from numpy cos/sin changes that have since been reverted in 1.25.dev
from numpy cos/sin changes that have since been reverted in 1.25.dev
from numpy cos/sin changes that have since been reverted in 1.25.dev
from numpy cos/sin changes that have since been reverted in 1.25.dev
Description
This pull request is an attempt to fix #14705 (what's remaining after Larry's fixes).