You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
test_lme.TestMixedLM.test_compare_numdiff is occasionally failing when run locally. A bit surprising that it isn't consistent because it calls np.random.seed(3558). It's marked with @dec.slow. Does it not get run by the CI?
ci testing does not skip slow test, so the test should be run.
The main reason it could sometimes fail is floating point, numerical noise and tolerance to tight in some cases, e.g. when gradients or hessians are very small. This is a problem when the derivatives are evaluated at the MLE, but not so much in this case with random parameters.
I don't remember having seen that this test fails.
Shouldn't calling np.random.seed at the top make it non random?
It makes the random number generator non-random.
But there is also floating point noise in any numerical computation that may not be deterministic, and might fluctuate for technical reasons, memory usage, ....
If an assert checks at the precision of this floating point noise, then it might fail sometimes or on some machines.
But there is also floating point noise in any numerical computation that may not be deterministic, and might fluctuate for technical reasons, memory usage, ...
I have a vague recollection that we may have had this conversation before, and that I found this as strange then as I do now. The stack* results I see all seem to relate to threading issues, which shouldn't be at play here.
The assertion in question is assert_allclose(hess, nhess, rtol=1e-3) and the smallest exponent I'm seeing in the traceback is "e-01", which I think suggests that the difference is of order e-4, which I hope isn't explained by the floating point randomness theory.
Also looks like a) this reproduces on OSX but not on Linux, b) its always exactly one element that mismatches.
We don't have CI testing for OSX, just Windows and Linux which both use MKL as linear algebra library.
MKL by default uses multiple processors. Even in the old times when I was using ATLAS on Windows on a single core, some linear algebra computation had systematic fluctuations at floating point precision when I ran it repeatedly.
Maybe there is a problem with the linear algebra library that you are using on OSX.
Can you figure out a change to the unit test so it always passes on OSX?
I have no experience with OSX.
It looks like I can replicate the error on Linux when copy/pasting the code interactively, but not when running via pytest. When convenient, can you give it a shot and see if the behavior replicates? Dropping n_grp from 200 to 20 makes the error happen much more reliably (and faster)
we can increase rtol to rtol=2e-3, i.e doubling it.
a bit of background using pdb, test cases are in a loop, my numbers look the same as in the failing test, so I guess I have the same case (I put rtol=1e-4 to get a failing case that drops into pdb)
It doesn't look like a close to zero case where rtol would have problems. numerical hessian are difficult to check and depend a lot on the parameters and curvature, rtol=2e-3 is still a good verification.
I have no clue about reliability and numerical noise on OSX, and no way to check.
Out of curiosity I'm going to check if using bottleneck affects this. I seem to recall its results matching those from python (slow) sum in a case where np.sum bounced around.
e.g. when I drop n_grp to 20 (faster test, plus failures are much more consistent), it looks like half of the cases fail, precisely those with profile_fe = True woops, use_sqrt=True
Activity
josef-pkt commentedon Mar 24, 2018
ci testing does not skip slow test, so the test should be run.
The main reason it could sometimes fail is floating point, numerical noise and tolerance to tight in some cases, e.g. when gradients or hessians are very small. This is a problem when the derivatives are evaluated at the MLE, but not so much in this case with random parameters.
I don't remember having seen that this test fails.
jbrockmendel commentedon Mar 24, 2018
OK, I'll keep trying to track this down. I'm finding it fails about 1/5 runs. If you get a chance to run locally a few times, pls let me know.
Shouldnt calling np.random.seed at the top make it non random?
josef-pkt commentedon Mar 25, 2018
It makes the random number generator non-random.
But there is also floating point noise in any numerical computation that may not be deterministic, and might fluctuate for technical reasons, memory usage, ....
If an assert checks at the precision of this floating point noise, then it might fail sometimes or on some machines.
jbrockmendel commentedon Mar 25, 2018
I have a vague recollection that we may have had this conversation before, and that I found this as strange then as I do now. The stack* results I see all seem to relate to threading issues, which shouldn't be at play here.
The assertion in question is
assert_allclose(hess, nhess, rtol=1e-3)and the smallest exponent I'm seeing in the traceback is "e-01", which I think suggests that the difference is of order e-4, which I hope isn't explained by the floating point randomness theory.Also looks like a) this reproduces on OSX but not on Linux, b) its always exactly one element that mismatches.
josef-pkt commentedon Mar 25, 2018
We don't have CI testing for OSX, just Windows and Linux which both use MKL as linear algebra library.
MKL by default uses multiple processors. Even in the old times when I was using ATLAS on Windows on a single core, some linear algebra computation had systematic fluctuations at floating point precision when I ran it repeatedly.
Maybe there is a problem with the linear algebra library that you are using on OSX.
Can you figure out a change to the unit test so it always passes on OSX?
I have no experience with OSX.
jbrockmendel commentedon Mar 25, 2018
Yah I'll keep poking at it
jbrockmendel commentedon Mar 27, 2018
It looks like I can replicate the error on Linux when copy/pasting the code interactively, but not when running via pytest. When convenient, can you give it a shot and see if the behavior replicates? Dropping n_grp from 200 to 20 makes the error happen much more reliably (and faster)
matthew-brett commentedon Sep 10, 2018
I think I've just hit this in the wheel tests, on macOS:
https://travis-ci.org/MacPython/statsmodels-wheels/jobs/426763185
It does seem there's some randomness, this is only for Python 2.7, and we didn't get the failure at all for the previous runs, yesterday.
josef-pkt commentedon Sep 10, 2018
we can increase rtol to
rtol=2e-3, i.e doubling it.a bit of background using pdb, test cases are in a loop, my numbers look the same as in the failing test, so I guess I have the same case (I put rtol=1e-4 to get a failing case that drops into pdb)
It doesn't look like a close to zero case where rtol would have problems. numerical hessian are difficult to check and depend a lot on the parameters and curvature,
rtol=2e-3is still a good verification.(as in another test failure: I have no clue about reliability and numerical noise on OSX, and no way to check.)
jbrockmendel commentedon Sep 10, 2018
Out of curiosity I'm going to check if using
bottleneckaffects this. I seem to recall its results matching those from python (slow) sum in a case where np.sum bounced around.jbrockmendel commentedon Sep 10, 2018
BTW troubleshooting this would be made easier if this particular test were parametrized, so the test log would tell us which of the 2**3 cases failed
jbrockmendel commentedon Sep 10, 2018
e.g. when I drop
n_grpto 20 (faster test, plus failures are much more consistent), it looks like half of the cases fail, precisely those withwoops,profile_fe = Trueuse_sqrt=Truejbrockmendel commentedon Sep 10, 2018
There's also reason to believe there may be a non-numerical problem in the affected code: #4414 (comment)
TST: parametrize flaky numdiff test; closes statsmodels#4396
jbrockmendel commentedon May 10, 2019
This is now conditionally xfailed on Mac, and Mac is in the CI. Closing.