Repository navigation
Speed up long runs without changing results (ref #101) - #118
Merged
Merged
Conversation
Profile of the #73 regression scenario (seed 19, 30 organisms, 1000 generations; new example long_run_profile) showed evolve dominating and growing with the genome (~400 genes / ~150 neurons at the end): speciation spent its time rebuilding and sorting neuron lists in every compatibility distance, crossover scanned every gene for each neuron (has_neuron) and inserted genes one by one, and add-connection listed every possible pair. - Genome keeps its sorted neuron ids up to date as genes are added, so neurons()/has_neuron() no longer rebuild/scan the gene list. - Compatibility distance walks both neuron lists together, no allocation. - FirstCompatible speciation stops at the first compatible species (by id) instead of measuring the distance to all of them. - Crossover walks both sorted gene lists together and builds the child's genes in one go instead of binary searches and sorted inserts. - Add-connection counts the new connections and finds the drawn one without listing all ~n^2 pairs (same pair for the same draw). - Gene::cmp compares (in, out) tuples directly (same order). - Interspecies mating candidates are copied without their compiled phenotype (Organism::clone_for_mating). Every random draw happens in the same order, so results are identical: tests/long_run_identity_tests.rs checks a digest of 300 generations recorded before the change (Linux x86_64), and Banco A seeds 1/101/201/301 give the same per-run results. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
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.
What changes
This speeds up the per-generation cost of long runs without changing any result (every random draw happens in the same order):
Genomekeeps its sorted neuron ids up to date as genes are added, soneurons()andhas_neuron()no longer rebuild or scan the gene list. Genes are never removed and never change their ends.FirstCompatiblespeciation stops at the first compatible species (lowest id) instead of measuring the distance to every species.new_connection_count/nth_new_connection). It picks the same pair for the same draw.Gene::cmpcompares(in, out)tuples directly. The order is the same.species_parents) are copied without their compiled phenotype or CTRNN state (Organism::clone_for_mating).long_run_profile: the Cerrar #19 y #45 con test de regresión #73 scenario with per-generation timing of evolve and evaluate, genome sizes, and a digest of every generation.How it was verified
tests/long_run_identity_tests.rschecks a digest of 300 generations of the Cerrar #19 y #45 con test de regresión #73 scenario, recorded on develop before the change. It is checked on Linux x86_64 only because fitness goes throughexp; elsewhere it checks reproducibility. The 1000-generation digest fromlong_run_profileis the same before and after (87e3c9f6901f412c, and475adde81536aafcwith pop 60).xor_bench 50 500 init reset=1, seeds 1/101/201/301): per-run results are bit-identical to develop, sorted and with timings stripped. Medians are 52/53/53/51, unchanged.cargo fmt -- --checkOK.cargo clippy --release --all-targetsgives 56 warnings, the same as develop, none new.cargo build --release --examplesOK.cargo test --release --no-fail-fastall green (133 lib tests).Closing criterion
Develop and branch binaries were run alternately on a heavily loaded machine, best of 3 runs each:
Evolve alone is about 5× faster, and evaluation is now about half of the remaining time. The full profile is posted on the issue. Target ≥ 2×: met.
ref #101
Part of epic #55
🤖 Generated with Claude Code