fix(optimizers): fallback to seed_candidates in propose_new_candidates#41
Open
lelouar wants to merge 1 commit intoSynaLinks:mainfrom
Open
fix(optimizers): fallback to seed_candidates in propose_new_candidates#41lelouar wants to merge 1 commit intoSynaLinks:mainfrom
lelouar wants to merge 1 commit intoSynaLinks:mainfrom
Conversation
`EvolutionaryOptimizer.propose_new_candidates` calls `select_candidate` on `best_candidates`, which on the very first training step is still empty (it is populated later by `maybe_add_candidate`). The resulting `None` was then passed as `selected_candidate` into `mutate_candidate` / `merge_candidate`, crashing subclasses such as OMEGA on `selected_candidate.items()` in `omega.py`. Apply the same seed-candidate fallback that `on_batch_begin` already uses, so mutation/crossover always receives a valid starting point. Add a regression test covering the empty-`best_candidates` path.
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
EvolutionaryOptimizer.propose_new_candidatescallsselect_candidateonbest_candidates, which on the very first training step is still empty (it is populated later bymaybe_add_candidate). The resultingNoneis then passed asselected_candidateintomutate_candidate/merge_candidate, crashing concrete subclasses such asOMEGAonselected_candidate.items()inomega.py.The companion method
on_batch_beginalready handles this situation by falling back to a random seed candidate. This PR applies the exact same fallback inpropose_new_candidates, keeping behaviour consistent across the class and letting OMEGA (and any futureEvolutionaryOptimizersubclass) runfit()without pre-populatingbest_candidates.Reproduction
Before the fix this crashes at step 0 with:
Changes
synalinks/src/optimizers/evolutionary_optimizer.py: inpropose_new_candidates, whenselect_candidate(best_candidates)returnsNone, fall back to a random seed candidate (mirroringon_batch_begin).synalinks/src/optimizers/evolutionary_optimizer_test.py: addtest_propose_new_candidates_falls_back_to_seed_when_best_empty. The test subclassesEvolutionaryOptimizerto record whatmutate_candidatereceives, and verifies it is the seed candidate (notNone). The test fails onmainand passes with this fix.Test plan
evolutionary_optimizer_test.pysuite passes (15/15)