astropy / astropy-healpix

BSD-licensed HEALPix for Astropy - maintained by @astrofrog and @lpsinger
https://astropy-healpix.readthedocs.io
BSD 3-Clause "New" or "Revised" License
53 stars 22 forks source link

Test fails for test_pix2ang and test_ring2nest #39

Closed cdeil closed 7 years ago

cdeil commented 7 years ago

I see two test fails locally. I think they are deterministic (tried two times and got the exact same numbers / fails), and probably precision-related. @astrofrog - Thoughts?

_________________________________________________________________________ test_pix2ang __________________________________________________________________________

    @given(nside_pow=integers(0, 29), nest=booleans(), lonlat=booleans(),
>          frac=floats(0, 1, allow_nan=False, allow_infinity=False).filter(lambda x: x < 1))

healpix/tests/test_healpy.py:75: 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
/opt/local/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/hypothesis/executors.py:58: in default_new_style_executor
    return function(data)
/opt/local/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/hypothesis/core.py:115: in run
    return test(*args, **kwargs)
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _

nside_pow = 29, frac = 0.1666666694606345, nest = False, lonlat = False

    @given(nside_pow=integers(0, 29), nest=booleans(), lonlat=booleans(),
           frac=floats(0, 1, allow_nan=False, allow_infinity=False).filter(lambda x: x < 1))
    @settings(max_examples=2000, derandomize=True)
    def test_pix2ang(nside_pow, frac, nest, lonlat):
        nside = 2 ** nside_pow
        ipix = int(frac * 12 * nside ** 2)
        theta1, phi1 = hp_compat.pix2ang(nside, ipix, nest=nest, lonlat=lonlat)
        theta2, phi2 = hp.pix2ang(nside, ipix, nest=nest, lonlat=lonlat)
        if lonlat:
            assert_allclose(phi1, phi2, atol=1e-8)
            if abs(phi1) < 90:
                assert_allclose(theta1, theta2, atol=1e-10)
        else:
            assert_allclose(theta1, theta2, atol=1e-8)
            if theta1 > 0:
>               assert_allclose(phi1, phi2, atol=1e-10)
E               AssertionError: 
E               Not equal to tolerance rtol=1e-07, atol=1e-10
E               
E               (mismatch 100.0%)
E                x: array([  1.124984e-06])
E                y: array(1.1235210848771786e-06)

healpix/tests/test_healpy.py:89: AssertionError
-------------------------------------------------------------------------- Hypothesis ---------------------------------------------------------------------------
Falsifying example: test_pix2ang(nside_pow=29, frac=0.1666666694606345, nest=False, lonlat=False)
________________________________________________________________________ test_ring2nest _________________________________________________________________________

    @given(nside_pow=integers(0, 29),
>          frac=floats(0, 1, allow_nan=False, allow_infinity=False).filter(lambda x: x < 1))

healpix/tests/test_healpy.py:104: 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
/opt/local/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/hypothesis/executors.py:58: in default_new_style_executor
    return function(data)
/opt/local/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/hypothesis/core.py:115: in run
    return test(*args, **kwargs)
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _

nside_pow = 29, frac = 0.16666666697710755

    @given(nside_pow=integers(0, 29),
           frac=floats(0, 1, allow_nan=False, allow_infinity=False).filter(lambda x: x < 1))
    @settings(max_examples=2000, derandomize=True)
    def test_ring2nest(nside_pow, frac):
        nside = 2 ** nside_pow
        ring = int(frac * 12 * nside ** 2)
        nest1 = hp_compat.ring2nest(nside, ring)
        nest2 = hp.ring2nest(nside, ring)
>       assert nest1 == nest2
E       assert array([192153584101124779]) == 192153584101113855

healpix/tests/test_healpy.py:111: AssertionError
-------------------------------------------------------------------------- Hypothesis ---------------------------------------------------------------------------
Falsifying example: test_ring2nest(nside_pow=29, frac=0.16666666697710755)
============================================================= 2 failed, 260 passed in 6.94 seconds ==============================================================
astrofrog commented 7 years ago

Yes, these seem precision-related. The ring2nest one must be an integer precision issue, while the pix2ang one must be related to #34. This are not critical since they happen for very high values of nside, but we should still try and fix them (fixing the first one might actually involve adjusting the test). What's curious is that the derandomize option is still resulting in different cases on different computers.

Anyway, a solution for now would be to lower the maximum value of nside until we sort out these kinds of issues.

astrofrog commented 7 years ago

What's interesting about these examples is that even if I set hypothesis to run them as known examples I don't see a failure. Very strange!

astrofrog commented 7 years ago

@cdeil - could you check whether you still get failures with the latest master? I think these should now be fixed.

cdeil commented 7 years ago

All tests pass for me locally now. Closing this issue.