Repository navigation
Closed
Labels
Milestone
Description
Error
____________________________ test_wrap_around[3-2] _____________________________
ndim = 3, axis = 2
@skipif(
sys.version_info[:2] == (3, 4),
reason="Doesn't work with python 3.4. See issue #3079",
)
@testing.parametrize("ndim, axis", dim_axis)
def test_wrap_around(ndim, axis):
> check_wrap_around(ndim, axis)
__warningregistry__ = {}
axis = 2
ndim = 3
tests/skimage/restoration/test_unwrap.py:138:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
ndim = 3, axis = 2
def check_wrap_around(ndim, axis):
# create a ramp, but with the last pixel along axis equalling the first
elements = 100
ramp = np.linspace(0, 12 * np.pi, elements)
ramp[-1] = ramp[0]
image = ramp.reshape(tuple([elements if n == axis else 1 for n in range(ndim)]))
image_wrapped = np.angle(np.exp(1j * image))
index_first = tuple([0] * ndim)
index_last = tuple([-1 if n == axis else 0 for n in range(ndim)])
# unwrap the image without wrap around
# We do not want warnings about length 1 dimensions
with expected_warnings([r'Image has a length 1 dimension|\A\Z']):
image_unwrap_no_wrap_around = unwrap_phase(image_wrapped, rng=0)
print(
'endpoints without wrap_around:',
image_unwrap_no_wrap_around[index_first],
image_unwrap_no_wrap_around[index_last],
)
# without wrap around, the endpoints of the image should differ
assert_(
abs(
image_unwrap_no_wrap_around[index_first]
- image_unwrap_no_wrap_around[index_last]
)
> np.pi
)
# unwrap the image with wrap around
wrap_around = [n == axis for n in range(ndim)]
# We do not want warnings about length 1 dimensions
with expected_warnings([r'Image has a length 1 dimension.|\A\Z']):
image_unwrap_wrap_around = unwrap_phase(image_wrapped, wrap_around, rng=0)
print(
'endpoints with wrap_around:',
image_unwrap_wrap_around[index_first],
image_unwrap_wrap_around[index_last],
)
# with wrap around, the endpoints of the image should be equal
> assert_almost_equal(
image_unwrap_wrap_around[index_first], image_unwrap_wrap_around[index_last]
)
E AssertionError:
E Arrays are not almost equal to 7 decimals
E ACTUAL: np.float64(-31.41592653589793)
E DESIRED: np.float64(6.283185307179586)
__warningregistry__ = {}
axis = 2
elements = 100
image = array([[[ 0. , 0.38079911, 0.76159822, 1.14239733,
1.52319644, 1.90399555, 2.28479466, 2.665593... 35.03351808, 35.41431719, 35.7951163 , 36.1759154 ,
36.55671451, 36.93751362, 37.31831273, 0. ]]])
image_unwrap_no_wrap_around = array([[[-18.84955592, -18.46875681, -18.0879577 , -17.70715859,
-17.32635948, -16.94556037, -16.56476126, -1...18396215, 16.56476126, 16.94556037, 17.32635948,
17.70715859, 18.0879577 , 18.46875681, 18.84955592]]])
image_unwrap_wrap_around = array([[[-31.41592654, -31.03512743, -30.65432832, -30.27352921,
-29.8927301 , -29.51193099, -29.13113188, -2...61759154, 3.99839065, 4.37918976, 4.75998887,
5.14078798, 5.52158709, 5.9023862 , 6.28318531]]])
image_wrapped = array([[[ 0.00000000e+00, 3.80799110e-01, 7.61598219e-01,
1.14239733e+00, 1.52319644e+00, 1.90399555e+00...90399555e+00, -1.52319644e+00,
-1.14239733e+00, -7.61598219e-01, -3.80799110e-01,
0.00000000e+00]]])
index_first = (0, 0, 0)
index_last = (0, 0, -1)
ndim = 3
ramp = array([ 0. , 0.38079911, 0.76159822, 1.14239733, 1.52319644,
1.90399555, 2.28479466, 2.66559377, ...271897, 35.03351808, 35.41431719, 35.7951163 ,
36.1759154 , 36.55671451, 36.93751362, 37.31831273, 0. ])
wrap_around = [False, False, True]
I think I've seen this test being flaky before. For example see #3079 and #3237.
Activity
main#7961lagru commentedon Nov 28, 2025
I'm unsure how to properly debug this without convenient access to that arch. :/
matthew-brett commentedon Dec 10, 2025
I've tried reproducing the build from https://github.com/scikit-image/scikit-image/actions/runs/19970158590/job/57272587215. I have the same version of Python (3.13.9) and the same Pip packages, and am using the same commit of Scikit-image, running on MacOS Tahoe (26.1), on an M2 chip. The CI run was on the
macos-15-arm64image, giving MacOS 15.7.2.I've run
pytest tests/skimage/restoration/test_unwrap.pyover 2500 times without error.However, I have run the full test suite, and generated the error twice, once after a few iterations, and once after 510 iterations. So it looks like a rare (say 1 time in 300 or so) error, from the full test suite only - the worst kind!
I suspect the exact environment is not important, but the platform is. I'll revert to my usual environment, and try repeated test runs on that. I'll do the same for Intel, expecting that won't generate the error.
lagru commentedon Dec 10, 2025
Thank you so much for investigating and reproducing this! 🙏
[-]Flaky `test_wrap_around` for `restoration.unwrap_phase` on MacOS-15[/-][+]Flaky `test_wrap_around` for `restoration.unwrap_phase` on MacOS-15-ARM[/+][-]Flaky `test_wrap_around` for `restoration.unwrap_phase` on MacOS-15-ARM[/-][+]Flaky `test_wrap_around` on MacOS-15-ARM[/+]matthew-brett commentedon Dec 12, 2025
Perhaps there are differences between Python versions. I did replicate the error with Python 3.12, but after 1164 iterations, again, with the full test suite.
Trying on Intel.
matthew-brett commentedon Dec 12, 2025
Yup, replicates quickly (3 iterations) on Mac Intel, with Python 3.13.
I'll investigate further.
In the meantime - I think it's reasonable to release - it's a very rare failure that may not occur in the wild. We have this issue to track it - I will try hard to get to the bottom of it.
matthew-brett commentedon Dec 14, 2025
Replicated after 11 runs again on Intel.
No replication after 64K runs of just the individual test file on Intel, and after 120K runs on M1.
So, definitively only replicates as part of full test run.
lagru commentedon Dec 16, 2025
See #3079 for earlier similar issues with this test on Python 3.4. 🤷
matthew-brett commentedon Dec 16, 2025
conda-forge/scikit-image-feedstock#91 (comment) looks like the same failure.
5 remaining items
ngoldbaum commentedon Feb 18, 2026
It may be a good idea to run the scikit-image tests under ASan builds. I've found it's good at finding issues that lead to random crashes like this.
ngoldbaum commentedon Feb 25, 2026
I just triggered this on my Mac locally. I'm planning to build scikit-image with sanitizers so I'll just go ahead and do that ASan pass to look at this issue.
ngoldbaum commentedon Feb 26, 2026
I built scikit-image and all Python dependencies (including CPython) using address sanitizer and unfortunately didn't see any issues.
That doesn't completely rule out heap corruption as the cause of the issue if the corruption is happening inside system libraries. I double-checked and the 2D and 3D C unwrapping code is being correctly wrapped by address sanitizer.
I should say, if I run just this test, I eventually see failures after 47 iterations if I do
spin test "tests/skimage/restoration/test_unwrap.py::test_wrap_around"in a bash for loop in my Mac.ngoldbaum commentedon Mar 10, 2026
Here's it happening again in CI: https://github.com/scikit-image/scikit-image/actions/runs/22911859048/job/66486398382?pr=8084
lagru commentedon Mar 19, 2026
Thanks for the investigation and additional info! 😊
A bit off-topic: I'm curious how you checked the code in question since I may want to debug similar issues at some point. Which sanitizer did you use? Anything needed besides getting the correct flags passed down somewhere in our build process?
ngoldbaum commentedon Mar 19, 2026
I used address sanitizer. See Quansight-Labs/free-threaded-compatibility#309 for detailed build instructions. Those instructions are for thread sanitizer, but you can do the exact same thing for address sanitizer. It's a little annoying because building SciPy needs OpenMP support, so you need to use homebrew's LLVM compilers and override the default MacOS compilers.
The one big pain point for the LLVM sanitizers is that the entire codebase needs to be compiled with the same sanitizer runtime (e.g. the same LLVM major version). For Python projects, that means the interpreter and all native code that is getting called. Unfortunately there's no way to instrument system libraries like that, which is why I called it out above.
michaelbratsch commentedon Mar 20, 2026
If I am not mistaken,
use_seedis not set properly, see https://github.com/scikit-image/scikit-image/pull/8099/changes.There has been quite some investigation on the stability in this issue so I was wondering why we see the observed behaviour and consulted AI:
matthew-brett commentedon May 4, 2026
@michaelbratsch - thanks - that's a useful analysis. And thanks for the PR. I wonder whether we should be using something that is more thread-safe for the random numbers.
ngoldbaum commentedon May 4, 2026
@matthew-brett see #8084
matthew-brett commentedon May 4, 2026
@ngoldbaum - could you say more? Am I right in thinking you didn't address the
test_unwraptests there?ngoldbaum commentedon May 4, 2026
No, I don't think so. More pointing to there being a better pattern for this going forward in the tests.
stefanv commentedon May 16, 2026
We've seeded phase unwrapping, so this should be addressed. @matthew-brett please confirm.