fix: handle random_state=0 correctly in leiden clustering#184
Open
Ekin-Kahraman wants to merge 2 commits intoscverse:mainfrom
Open
fix: handle random_state=0 correctly in leiden clustering#184Ekin-Kahraman wants to merge 2 commits intoscverse:mainfrom
Ekin-Kahraman wants to merge 2 commits intoscverse:mainfrom
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>
Author
|
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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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