Skip to content

make random state argument handling more consistent - #166

Merged
ilia-kats merged 2 commits into
scverse:mainfrom
ilia-kats:random_state_fixes
Aug 24, 2026
Merged

make random state argument handling more consistent#166
ilia-kats merged 2 commits into
scverse:mainfrom
ilia-kats:random_state_fixes

Conversation

@ilia-kats

@ilia-kats ilia-kats commented Aug 14, 2025

Copy link
Copy Markdown
Collaborator

@ilia-kats
ilia-kats requested a review from gtca August 15, 2025 14:36
@ilia-kats
ilia-kats requested a review from ilan-gold October 9, 2025 16:10

@ilan-gold ilan-gold left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How is this not a breaking change for reproducibility given that you're changing the default? If you didn't set the random seed by default now in each of these, you're setting it every time now to 0. I think handling random state this way is a separate issue

Comment thread muon/_core/tools.py Outdated
@ilia-kats

Copy link
Copy Markdown
Collaborator Author

We already weren't reproducible before, unless someone set their global random seed at the very beginning of the analysis, which very few people do. I would think this improves reproducibility. But I guess we can defer that change to muon 0.2 or something, with an explicit warning in the release notes.

@ilan-gold

Copy link
Copy Markdown
Contributor

Up to you! If the goal is to just "fix the issue" I think checking is not None is sufficient but otherwise this change seems reasonable

- always default to non-None random_state (consistent within muon and
  with scanpy)
- fix condition before setting random state in .tl.leiden (closes #154,
  closes #184, closes #218)
@grst

grst commented Aug 24, 2026

Copy link
Copy Markdown
Contributor

Maybe worth fully adhering to https://scientific-python.org/specs/spec-0007/ while you are at it?

@codecov

codecov Bot commented Aug 24, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 0% with 1 line in your changes missing coverage. Please review.
✅ Project coverage is 26.27%. Comparing base (76ee541) to head (87903c5).

Files with missing lines Patch % Lines
src/muon/tl.py 0.00% 1 Missing ⚠️
Additional details and impacted files
@@           Coverage Diff           @@
##             main     #166   +/-   ##
=======================================
  Coverage   26.27%   26.27%           
=======================================
  Files          16       16           
  Lines        2299     2299           
=======================================
  Hits          604      604           
  Misses       1695     1695           
Files with missing lines Coverage Δ
src/muon/atac/tl.py 12.73% <ø> (ø)
src/muon/prot/pp.py 10.29% <ø> (ø)
src/muon/tl.py 40.90% <0.00%> (ø)
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@ilia-kats

Copy link
Copy Markdown
Collaborator Author

Maybe worth fully adhering to https://scientific-python.org/specs/spec-0007/ while you are at it?

yeah, that was my thought as well.

@ilia-kats

Copy link
Copy Markdown
Collaborator Author

@grst turns out we can't adhere to SPEC007 yet: muon itself does not do any random sampling, the random_state argument is always passed to an upstream package, none of which (scanpy, scikit-learn, pandas, umap-learn) currently support SPEC007 (meaning they all accept a random_state argument typed as int | RandomState | None.

@grst

grst commented Aug 24, 2026

Copy link
Copy Markdown
Contributor

I see, thanks for investigating!

@ilia-kats
ilia-kats merged commit dacf899 into scverse:main Aug 24, 2026
9 checks passed
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.

random_state=0 does not set seed in muon.tl.leiden, either a bug or unclear documentation

3 participants