Determinism: seed MTSP clustering, route discrete-search + optimizer choice via rng - #116
Closed
fundthmcalculus wants to merge 1 commit into
Closed
Determinism: seed MTSP clustering, route discrete-search + optimizer choice via rng#116fundthmcalculus wants to merge 1 commit into
fundthmcalculus wants to merge 1 commit into
Conversation
…choice via rng Determinism quick wins (autonomous review 2026-08-23). Stacked on the combinatorial-correctness branch. - mtsp.do_clustering: KMeans and SpectralClustering were constructed with no random_state, so MTSP cluster assignments (and the resulting tours/score) varied run to run even under set_seed. Pass random_state=get_seed(), matching cvt.py / solution_deck.py. - gd.parallel_discrete_search: picked discrete vars via the legacy global np.random.randint; route through the project rng() so it honors the active worker stream like the rest of the continuous stack. - optimizer_strategy: RandomOptimizerSelection used CPython's global `random`; use the numpy rng(). Also fix the mutable default argument (optimizer_selector=RandomOptimizerSelection() built once at import) -> None + construct in __init__. Drop the now-unused `import random`. Tests: tests/test_determinism.py green (17); changed modules import cleanly. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01LxgEQmoqtAj589pvbwuGo4
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.
Determinism quick wins from the 2026-08-23 review. Stacked on #115 (base =
fix/combinatorial-correctness).KMeans/SpectralClustering(random_state=get_seed()) — were unseeded → tours varied run-to-runparallel_discrete_searchusesrng().integersinstead of legacy globalnp.random.randintRandomOptimizerSelectionuses numpyrng()(not CPython globalrandom); fix mutable default arg built once at importTests
tests/test_determinism.pygreen (17); changed modules import cleanly. Full suite + Cython via CI.Remaining opt determinism follow-up (bigger): O2 — the combinatorial family (ACO/GA) draws from thread-unsafe legacy
np.randomunderjoblib(prefer=threads); adoptingcore.random/spawn_streamsthere is cross-cutting.🤖 Generated with Claude Code
https://claude.ai/code/session_01LxgEQmoqtAj589pvbwuGo4