Skip to content

Code review pass: correctness fixes, vectorization, cleanup - #121

Merged
fundthmcalculus merged 1 commit into
mainfrom
chore/code-review-fixes
Aug 24, 2026
Merged

Code review pass: correctness fixes, vectorization, cleanup#121
fundthmcalculus merged 1 commit into
mainfrom
chore/code-review-fixes

Conversation

@fundthmcalculus

Copy link
Copy Markdown
Owner

Summary

Full audit (security/error-handling, performance/resources, dead code/deps, complexity/architecture) with no Critical findings, followed by an approved refactor pass:

  • Correctness: lloyds_algorithm_points was drawing from the legacy global np.random instead of the project's seeded rng(), breaking RNG reproducibility (also dropped its now-invalid @lru_cache). Bare asserts on public entry points (TSPBase.set_network_routes, SolutionDeck.append) replaced with raise ValueError. validate_config now rejects population_size=0/solution_archive_size=0/num_generations<=0. InputContinuousVariable now raises on lower_bound >= upper_bound.
  • Performance: vectorized SolutionDeck.initialize_solution_deck and CVTArchive.add_generation (the latter verified bit-exact against the old sequential loop via a 500-trial fuzz test covering cell collisions/ties).
  • Robustness: load_checkpoint validates required keys instead of raising an opaque KeyError; added logging to previously-silent exception paths in continuous/base.py.
  • Cleanup: removed broken optimizers/fuzzy console-script entries and the stale src/fuzzy build target; removed unused deps (sympy, contextlib2, pyclustertend); added permissions: contents: read to both GitHub workflows; documented _three_opt_kernel's reconnection switch; moved 6 completed-work planning docs into docs/history/.

Deliberately deferred (flagged, not silently skipped — each is invasive/hot-path enough to warrant its own PR): adopting the shared GenerationRunner in the combinatorial solvers (DRY), wiring checkpointing into optimizer_strategy.py, and parallelizing AntColonyMTSP's cluster loop (blocked on core/random.spawn_streams being single-thread-only).

Test plan

  • flake8 ./src ./tests — clean
  • MYPYPATH=src mypy -p optimizers — clean (strict mode)
  • black --check . — clean
  • PYTHONPATH=./src pytest tests/ — 176 passed, 1 skipped (unchanged from baseline)
  • Updated test_multi_output.py::test_append_requires_outputs_when_tracking, which asserted on the old assert-raises-AssertionError behavior, to expect the new ValueError
  • archive/cvt.py vectorization independently verified bit-exact via a 500-trial randomized fuzz test (cell collisions + value ties)

🤖 Generated with Claude Code

https://claude.ai/code/session_011r9W1JZRSoayjyLin4ZBPZ

Fixes from a full audit of the repo (security/error-handling,
performance/resources, dead code/deps, complexity/architecture; no
Critical findings):

- lloyds_algorithm_points drew initial points from the legacy global
  np.random instead of the project's seeded rng(), breaking the RNG
  reproducibility guarantee; also dropped its now-invalid @lru_cache
  (a seed-dependent function can't be cached by args alone).
- Bare, message-less asserts on public entry points (TSPBase.
  set_network_routes, SolutionDeck.append) replaced with raise
  ValueError (asserts are stripped under python -O).
- validate_config now rejects population_size=0 / solution_archive_size=0
  / num_generations<=0 instead of silently falling through.
- InputContinuousVariable now raises on lower_bound >= upper_bound.
- Vectorized SolutionDeck.initialize_solution_deck (nested Python loop)
  and CVTArchive.add_generation (scalar per-row loop); the latter
  verified bit-exact against the old sequential logic via a 500-trial
  fuzz test covering cell collisions and value ties.
- load_checkpoint validates required keys and raises ValueError on a
  malformed file instead of an opaque KeyError.
- Removed broken optimizers/fuzzy console-script entries and the
  stale src/fuzzy build target (fuzzy was split out of this repo);
  removed unused deps sympy/contextlib2/pyclustertend.
- Added permissions: contents: read to both GitHub workflows.
- Added logging to previously-silent exception paths in continuous/base.py.
- Documented _three_opt_kernel's 8-way reconnection switch.
- Moved 6 completed-work planning docs into docs/history/ and updated
  in-code references.

Deliberately deferred (flagged, not silently skipped): adopting the
shared GenerationRunner in the combinatorial solvers, wiring
checkpointing into optimizer_strategy, and parallelizing
AntColonyMTSP's cluster loop (blocked on core/random.spawn_streams
being single-thread-only) -- all invasive enough to warrant their own
pass.

flake8/mypy/black clean; full suite 176 passed, 1 skipped (unchanged
from baseline). Updated one test that asserted on the old
assert-raises-AssertionError behavior to expect the new ValueError.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_011r9W1JZRSoayjyLin4ZBPZ
@fundthmcalculus
fundthmcalculus merged commit 73f0746 into main Aug 24, 2026
1 check passed
@fundthmcalculus
fundthmcalculus deleted the chore/code-review-fixes branch August 24, 2026 16:16
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