Skip to content

Determinism: seed MTSP clustering, route discrete-search + optimizer choice via rng - #116

Closed
fundthmcalculus wants to merge 1 commit into
fix/combinatorial-correctnessfrom
fix/opt-determinism
Closed

Determinism: seed MTSP clustering, route discrete-search + optimizer choice via rng#116
fundthmcalculus wants to merge 1 commit into
fix/combinatorial-correctnessfrom
fix/opt-determinism

Conversation

@fundthmcalculus

Copy link
Copy Markdown
Owner

Determinism quick wins from the 2026-08-23 review. Stacked on #115 (base = fix/combinatorial-correctness).

# fix file
O4 seed MTSP KMeans/SpectralClustering (random_state=get_seed()) — were unseeded → tours varied run-to-run combinatorial/mtsp.py
O6 parallel_discrete_search uses rng().integers instead of legacy global np.random.randint continuous/gd.py
O9 RandomOptimizerSelection uses numpy rng() (not CPython global random); fix mutable default arg built once at import continuous/optimizer_strategy.py

Tests

tests/test_determinism.py green (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.random under joblib(prefer=threads); adopting core.random/spawn_streams there is cross-cutting.

🤖 Generated with Claude Code

https://claude.ai/code/session_01LxgEQmoqtAj589pvbwuGo4

…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
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