-
Notifications
You must be signed in to change notification settings - Fork 221
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix the global Random.seed in runtests.jl #2381
Conversation
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## master #2381 +/- ##
=======================================
Coverage 86.39% 86.39%
=======================================
Files 22 22
Lines 1573 1573
=======================================
Hits 1359 1359
Misses 214 214 ☔ View full report in Codecov by Sentry. |
Pull Request Test Coverage Report for Build 11592008026Details
💛 - Coveralls |
IIRC, we have a few test models whose posteriors have a large variance, which can cause challenges for MCMC samplers. |
Specifically, all the There are a few ways we can try to make this better, e.g. choose a different base model for testing, or just use more observations in the posterior (though this increases the computational burden of the tests). |
Also, regarding fixing the seeds: note that this won't be consistent across hardware nor Julia versions. For that we'd have to use StableRNGs.jl, but this in turn comes with additional computational overhead 😕 However, I do agree that maybe fixing the seeds can be helpful. |
That's good to know, both about StableRNGs and the large variance of the demo model. I would still like to merge this though, because it definitely removes a lot of indeterminacy, even if StableRNGs would be better still.
I would like to avoid the latter. I would rather like to aim to reduce the amount of sampling we do our tests, it would make especially local development easier. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would it be possible to add the call to seed!
slightly closer to the point of use? Specifically, I'm looking at test/mcmc/abstractmcmc.jl
and inserting them after lines 120, 161, and 185.
We would still have the issue with seed!
not being consistent across Julia versions, but at least we wouldn't get different results depending on which tests are run.
(I was pleasantly surprised to find that the PRNG is actually consistent across operating systems, at least! I didn't test architecture, though)
julia> module MWE
using Test, Random
@testset "A" begin
@show rand()
end
@testset "B" begin
@show rand()
end
end
rand() = 0.05361041735414662
Test Summary: |Time
A | None 0.0s
rand() = 0.05361041735414662
Test Summary: |Time
B | None 0.0s
Main.MWE However, without fixing the seed at the start globally, the local seed set by @penelopeysm does that mitigate the issue you worry about? |
Oh, yes! That does correspondingly suggest that we might have too many calls to seed! in other parts of the test, but that's far less pressing. |
Yup:
I would leave fixing that for later though, since it's mostly a style/clean-up question. Any other changes you want to see here @penelopeysm? |
Nope, feel free to go ahead :) And thanks for diagnosing it! |
GitHub's mobile app doesn't seem to let me approve so take this comment as an approval |
Based on local testing, this should [EDIT: not] close #2371.
EDIT: After conversation with @penelopeysm, agreed that this should not close #2371, since when the tests fail, the discrepancies are sometimes in fact quite large, which seems suspicious. Still worth fixing the seed and making this deterministic.