Skip to content

Fix: seed sequence permutation tests and make results independent of n_jobs #1234

Open
selmanozleyen wants to merge 5 commits into
scverse:mainfrom
selmanozleyen:fix/seed-sequence-permutation-tests
Open

Fix: seed sequence permutation tests and make results independent of n_jobs #1234
selmanozleyen wants to merge 5 commits into
scverse:mainfrom
selmanozleyen:fix/seed-sequence-permutation-tests

Conversation

@selmanozleyen

Copy link
Copy Markdown
Member

Fixes: #1233 and #1232 as a side effect.

For each permutation we have a separate seed. The seeds are generated by SeeqSequence(root_seed).spawn(x) routine. This will prevent having correlated results from sequential seeds mentioned in the numpy docs. I tried to use the best practice but since we need to use numba in the future our seeds can be only Sequence[int], instead of Sequence[np.random.SeedSequence]. Hence:

def _spawn_seeds(seed: int | None, n: int) -> list[int]:
    # uint32 integer seeds, derived from independent SeedSequence children (avoids the correlation
    # of sequential seeds). uint32 is required to stay reproducible with numba/legacy RandomState,
    # which only accept uint32 integer seeds.
    return [int(s.generate_state(1)[0]) for s in np.random.SeedSequence(seed).spawn(n)]

Once you confirm. I will write warnings in docstrings and in notebooks about this behavioral change to users.

@selmanozleyen selmanozleyen self-assigned this Jun 26, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

reproducable results indepent of n_jobs

1 participant