Skip to content

feat: drop rand for in-tree splitmix64 (src/rng.rs). Empirically - #139

Merged
Psy-Fer merged 1 commit into
mainfrom
rng-empirical-test
Jul 27, 2026
Merged

feat: drop rand for in-tree splitmix64 (src/rng.rs). Empirically#139
Psy-Fer merged 1 commit into
mainfrom
rng-empirical-test

Conversation

@Psy-Fer

@Psy-Fer Psy-Fer commented Jul 27, 2026

Copy link
Copy Markdown
Collaborator

Drop the rand dependency for an in-tree splitmix64 RNG (completes #118)

Replaces the external rand crate with a small in-tree deterministic RNG (src/rng.rs, splitmix64). This is #118's original goal — done correctly this time, and only after empirically proving the RNG choice is output-neutral

Why

rustar-aligner's only randomness is tie-breaking and EmptyDrops Monte-Carlo — paths where the exact RNG stream is not STAR-faithful anyway (STAR uses mt19937; we already diverge and report a tie-adjusted metric). What actually matters is determinism (reproducible regardless of thread scheduling), which a fixed-seed splitmix64 gives without pulling in randrand_corerand_chachappv-lite86zerocopy. Fewer deps = simpler build and a step toward the pure-Rust / C-toolchain-free goal.

#118 (BenjaminDEMAILLE) proposed exactly this but just deleted rand from Cargo.toml without migrating the WeightedIndex users, so it broke the build. This PR does the migration.

Empirical validation (the key point)

Before touching anything, I measured whether the RNG choice changes results, on the mouse 10x set (test/data/singlecell/, --soloCellFilter EmptyDrops_CR) — the one path claimed to "need rand":

  • StdRng vs splitmix64: identical 229 cells (0 differ). The RNG choice makes no difference to the EmptyDrops calls.
  • Both hit 228/229 vs STAR — same single borderline FDR cell (Monte-Carlo noise), so splitmix64 is exactly as STAR-faithful as StdRng.
  • Deterministic across thread counts (4-thread ≡ 1-thread).

So WeightedIndex is just a cumulative-weight sampler (~15 lines), and removing rand costs nothing in faithfulness.

Changes

  • src/rng.rs (new): SplitMix64 (next_u64/uniform/below), shuffle_deterministic (Fisher–Yates), cumulative_weights + sample_cumulative (WeightedIndex-equivalent). Unit-tested (determinism, range, permutation, weighted distribution).
  • Migrated all four production rand sites to it:
    • solo/count.rs — EmptyDrops ambient Monte-Carlo sampler.
    • src/bin/emptydrops.rs — standalone binary, same sampler.
    • align/read_align.rs--outMultimapperOrder Random tie-break shuffle.
    • lib.rs::pick_primary_and_mapq--runRNGseed primary tie-break.
    • (+ one #[cfg(test)] in index/packed_stream.rs.)
  • Dropped rand from Cargo.toml; rand/rand_core/rand_chacha/ppv-lite86/zerocopy are gone from the dependency tree.

Validation

  • EmptyDrops: 229 cells, byte-identical to the pre-change StdRng output; 228/229 vs STAR; deterministic across thread counts.
  • Yeast benchmark unchanged: SE 8788/8926, PE 8390 both-mapped (the tie-break stream change is output-neutral — tie-adjusted faithfulness holds).
  • 579 tests pass (+5 new rng unit tests) · clippy --all-targets 0 warnings · fmt clean.

@Psy-Fer Psy-Fer self-assigned this Jul 27, 2026
@Psy-Fer
Psy-Fer enabled auto-merge (squash) July 27, 2026 12:24
@Psy-Fer Psy-Fer changed the title feat: drop rand for in-tree splitmix64 (src/rng.rs). Wmpirically feat: drop rand for in-tree splitmix64 (src/rng.rs). Empirically Jul 27, 2026
@Psy-Fer
Psy-Fer disabled auto-merge July 27, 2026 12:24
@Psy-Fer
Psy-Fer enabled auto-merge (squash) July 27, 2026 12:24
@Psy-Fer
Psy-Fer merged commit 08ba386 into main Jul 27, 2026
10 checks passed
@Psy-Fer
Psy-Fer deleted the rng-empirical-test branch July 27, 2026 12:29
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.

1 participant