Skip to content

Parallelize AntColonyMTSP's cluster solving - #123

Merged
fundthmcalculus merged 1 commit into
mainfrom
feat/mtsp-parallel-clusters
Aug 24, 2026
Merged

Parallelize AntColonyMTSP's cluster solving#123
fundthmcalculus merged 1 commit into
mainfrom
feat/mtsp-parallel-clusters

Conversation

@fundthmcalculus

Copy link
Copy Markdown
Owner

Summary

  • AntColonyMTSP.solve() previously solved each cluster's independent ACO tour sequentially, with a TODO noting it could be parallelized but wasn't (each solver draws from the seeded global RNG, and core.random.spawn_streams()'s spawn counter is documented as single-thread-only, so naive concurrency would have raced on it and broken run reproducibility).
  • Adds spawn_stream_roots() / use_stream_root() to core/random.py: a nested-parallelism companion to the existing spawn_streams()/use_stream(). A task that itself dispatches further parallel work (here: one full multi-generation ACO run per cluster) gets its own independent SeedSequence sub-tree to spawn from, instead of racing on the shared global root. Purely additive — spawn_streams() is unchanged when no such scope is active.
  • AntColonyMTSP.solve() now spawns one stream root per cluster up front (single-threaded, before dispatch), then runs the clusters through joblib.Parallel, each wrapped in use_stream_root.
  • Also splits the configured processor budget between cluster-level and per-cluster ant-level parallelism instead of giving every cluster the full budget — resolving the old TODO ("handle the number of processors based upon parallel clusters").

Test plan

  • New RNG-isolation unit tests for spawn_stream_roots/use_stream_root (mirroring the existing spawn_streams/use_stream tests) in tests/test_determinism.py
  • New AntColonyMTSP-specific determinism test: a seeded run with concurrently-solving clusters is reproducible across repeated runs, and still seed-sensitive
  • flake8 ./src ./tests — clean
  • MYPYPATH=src mypy -p optimizers — clean
  • black --check . — clean
  • Full suite passing

🤖 Generated with Claude Code

https://claude.ai/code/session_011r9W1JZRSoayjyLin4ZBPZ

Each cluster's ACO run is independent, but every solver draws from the
seeded global RNG via core.random.spawn_streams()/rng(), whose spawn
counter is documented as single-thread-only. Running clusters
concurrently would have raced on that counter and broken the
reproducibility guarantee the RNG-determinism work established.

Adds spawn_stream_roots()/use_stream_root() to core/random.py: a
nested-parallelism companion to spawn_streams()/use_stream() that lets
a task which itself dispatches further parallel work (one
multi-generation ACO run per cluster) draw from its own independent
SeedSequence sub-tree instead of racing on the shared global one.
Purely additive -- spawn_streams() behaves exactly as before when no
such scope is active.

AntColonyMTSP.solve() now spawns one stream root per cluster up front
(single-threaded, before dispatch) and runs the clusters through
joblib.Parallel, each wrapped in use_stream_root. Also splits the
configured processor budget between cluster-level and per-cluster
ant-level parallelism instead of giving every cluster the full budget
(the old TODO here -- "handle the number of processors based upon
parallel clusters" -- was asking for exactly this).

Tests: RNG-isolation unit tests for spawn_stream_roots/use_stream_root
(mirroring the existing spawn_streams/use_stream tests), plus an
AntColonyMTSP-specific determinism test confirming a seeded run with
concurrent clusters is reproducible and still seed-sensitive.

flake8/mypy/black clean; full suite passing.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_011r9W1JZRSoayjyLin4ZBPZ
@fundthmcalculus
fundthmcalculus merged commit 175717b into main Aug 24, 2026
1 check passed
@fundthmcalculus
fundthmcalculus deleted the feat/mtsp-parallel-clusters branch August 24, 2026 17:03
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