Code review pass: correctness fixes, vectorization, cleanup - #121
Merged
Conversation
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
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.
Summary
Full audit (security/error-handling, performance/resources, dead code/deps, complexity/architecture) with no Critical findings, followed by an approved refactor pass:
lloyds_algorithm_pointswas drawing from the legacy globalnp.randominstead of the project's seededrng(), breaking RNG reproducibility (also dropped its now-invalid@lru_cache). Bareasserts on public entry points (TSPBase.set_network_routes,SolutionDeck.append) replaced withraise ValueError.validate_confignow rejectspopulation_size=0/solution_archive_size=0/num_generations<=0.InputContinuousVariablenow raises onlower_bound >= upper_bound.SolutionDeck.initialize_solution_deckandCVTArchive.add_generation(the latter verified bit-exact against the old sequential loop via a 500-trial fuzz test covering cell collisions/ties).load_checkpointvalidates required keys instead of raising an opaqueKeyError; added logging to previously-silent exception paths incontinuous/base.py.optimizers/fuzzyconsole-script entries and the stalesrc/fuzzybuild target; removed unused deps (sympy,contextlib2,pyclustertend); addedpermissions: contents: readto both GitHub workflows; documented_three_opt_kernel's reconnection switch; moved 6 completed-work planning docs intodocs/history/.Deliberately deferred (flagged, not silently skipped — each is invasive/hot-path enough to warrant its own PR): adopting the shared
GenerationRunnerin the combinatorial solvers (DRY), wiring checkpointing intooptimizer_strategy.py, and parallelizingAntColonyMTSP's cluster loop (blocked oncore/random.spawn_streamsbeing single-thread-only).Test plan
flake8 ./src ./tests— cleanMYPYPATH=src mypy -p optimizers— clean (strict mode)black --check .— cleanPYTHONPATH=./src pytest tests/— 176 passed, 1 skipped (unchanged from baseline)test_multi_output.py::test_append_requires_outputs_when_tracking, which asserted on the old assert-raises-AssertionErrorbehavior, to expect the newValueErrorarchive/cvt.pyvectorization 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