fix: handle random_state=0 correctly in leiden clustering#184
fix: handle random_state=0 correctly in leiden clustering#184Ekin-Kahraman wants to merge 2 commits into
Conversation
`random_state=0` was not setting the RNG seed because the check used `if random_state:` which evaluates to False when random_state is 0. Changed to `if random_state is not None:` so that any integer value (including 0) correctly calls `optimiser.set_rng_seed()`. Closes scverse#154 Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
…talled The CI environment does not have leidenalg. The previous approach used unittest.mock.patch which requires the target module to exist. Now we inject a mock leidenalg module into sys.modules before calling mu.tl.leiden, so the `import leidenalg` inside the function succeeds. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
|
CI status update: I've pushed a fix for the test failures in The remaining CI failures are pre-existing issues unrelated to this PR:
Our change is a single-line fix in |
|
@gtca @ilia-kats friendly ping on this — CI has been green since the Apr 11 fix. Small change (+96/-1), straightforward bug ( |
|
Happy to defer to #166. The regression test here ( |
Summary
random_statein_cluster()that causedrandom_state=0to skip setting the RNG seedif random_state:toif random_state is not None:so that0(the default) correctly callsoptimiser.set_rng_seed(0)random_state=0and skipped forrandom_state=NoneRoot cause
In
muon/_core/tools.pyline 1005, the conditionif random_state:evaluates toFalsewhenrandom_state=0because0is falsy in Python. This meant the default value (random_state=0) and any explicitrandom_state=0call never set the RNG seed, producing non-deterministic clustering results.Closes #154
Test plan
test_leiden_random_state_zero_sets_seed— verifiesset_rng_seed(0)is called whenrandom_state=0test_leiden_random_state_none_skips_seed— verifiesset_rng_seedis not called whenrandom_state=None