Repository navigation
Move toward determinism - #14090
Move toward determinism#14090
Conversation
drammock
left a comment
There was a problem hiding this comment.
I looked at the AST test, and it looks fine. didn't scrutinize the actual changes in code beyond a quick glance at a couple files. I'm definitely +1 on whittling global_rng_ignores down to zero; +1 to merge this and do a follow-up, or do it here if you prefer.
This is probably the point at which we should think ahead a bit:
- would we ever want a package-global random state/generator like
mne.RNGthat gets passed in wherever it's needed? My gut feeling is "don't do that for tests" (it just re-introduces non-determinism based on test execution order / parallelization) but IDK if it is better/neutral/worse for cases where we need RNG in package code. - are there any lingering outdated patterns we should clean up? (I saw you fixed some
randn->rng.normalorstandard_normal, are there other patterns to migrate away from?) - Should we make the test also check for the outdated patterns like
randn?
|
For We could right now think about migrating all of our code to prefer |
|
Okay I think I made it more consistent according to the plan above! I'll double check all changes in the diff then mark for merge-when-green 😅 |
|
@larsoner in how far does this PR address parts of that issue? |
|
It doesn't address random_state=int at all. That still routes through RandomState. It just prefers and enforces default_rng instead of legacy usages in our code. So we still need to figure out how to handle int. And it's complicated by the fact that sklearn doesn't support the newer generator IIRC. |
Noticing we had an un-seeded random state in our tests last week made me wonder how many other places we potentially had something like this. Turns out the answer is "a lot"! And I think it's better not to have it this way (creates unnecessary uncertainty / heisenbugs in tests, and makes unnecessary churn in our doc HTMLs). This PR
rng = default_rng(0)random_state=97andseed=0(seems to be our convention for those, but we could potentially change/unify now)Notably I didn't fix all such occurrences, but I could. The diff is already at the "kind of annoying to look at" level and I didn't want to push it. But if we agree on the approach and utility I could get through the others and shrink the
global_rng_ignorestoward zero!Claude Opus 4.8 helped me draft these changes and the initial AST implementation.