Repository navigation
feat: genome contracts, genetics config and pure genetics engine (Phase 4, PR 2/5) - #98
Merged
Merged
Conversation
…ngine Phase 4 PR 2. Adds everything needed to build, mutate, recombine, validate and compare genomes, without wiring any of it into the World yet (no new behavior, no hash change, goldens untouched). contracts: Genome and its gene groups, GENE_DEFINITIONS (the fixed canonical gene order, with orderedAfter links for the life-stage ages), GeneRange, GeneticsConfig, LearningInheritanceMode, LineageRecord. config: WorldConfig.genetics (mutation scales, blend alpha, brain architecture, founder learning baseline, learning inheritance, per-gene overrides), organisms.hue, and DEFAULT_GENE_RANGES. Default ranges widen to include a changed founder baseline, so overriding a baseline never needs a matching range override. Replaces reproduction.energyCost/offspringEnergy with offspringInvestment/overheadFraction (12.5 and 0.6 reproduce Phase 3's 20 paid and 25 to the child exactly); ReproductionSystem is the only simulation code touched, and the determinism suite passes against the unchanged goldens. Shared check helpers moved unchanged into config/src/checks.ts. simulation/genetics: table-driven mutation (per-kind operators, correlated trait-shift, relative learning-rate mutation, sparse brain-weight mutation), blend and per-block segment crossover so both parents' brains contribute, validateGenome/repairGenome, genomeDistance, inheritedBrainWeights (all three learning-inheritance modes), and founder genome creation. Operators work on gene vectors over a spec table so integer, boolean, circular and correlated genes are tested with synthetic tables. Design refinements made while implementing, with ADR 0006 and the genetics docs updated to match: life-stage ordering is enforced by the operators (orderedAfter) instead of requiring disjoint ranges; learningRate mutates multiplicatively because the engine has no deterministic exp; reproduction will require energy >= max(minEnergy, cost) so paying cannot go negative. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
5 tasks done
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
Second of five Phase 4 PRs, implementing the design merged in #97 (ADR 0006). Everything needed to build, mutate, recombine, validate and compare genomes, with none of it wired into the
Worldyet. There is no new simulated behavior and no hash change; the existing golden hashes are untouched and the determinism suite passes against them.@evo/contracts:Genomeand its gene groups;GENE_DEFINITIONS(the fixed canonical gene order, 23 genes);GeneRange,GeneticsConfig,LearningInheritanceMode,LineageRecord.@evo/config:WorldConfig.genetics(mutation scales, blend alpha, brain architecture, founder learning baseline, learning inheritance, per-gene overrides),organisms.hue,DEFAULT_GENE_RANGES, full validation with tests. Shared check helpers moved unchanged intochecks.ts.simulation/src/genetics/(pure functions, noWorldintegration):validateGenome/repairGenome,genomeDistance,inheritedBrainWeights(all three learning-inheritance modes), founder creation.One behavior-preserving change outside the new code
reproduction.energyCost/offspringEnergyare replaced byoffspringInvestment/overheadFraction(per ADR 0006). The defaults (12.5 and 0.6) give exactly Phase 3's 20 paid and 25 to the child (verified exactly in floating point), andReproductionSystemis the only simulation code touched. The determinism suite passes against the unchanged goldens, which is the proof that nothing moved.Design refinements made while implementing (ADR 0006 / genetics docs updated in this PR)
orderedAfteranother has its lower bound raised above it in mutation, recombination and repair, somaturityAge < senescenceAge < maxAgeholds for any ranges. The ADR originally required non-overlapping ranges, which would have rejected ordinary baseline overrides (for example small ages in tests).organisms.*/reproduction.*never needs a matching range override. An edge set explicitly ingenetics.genesis never moved, and validation rejects a baseline outside it.learningRatemutates multiplicatively (a Gaussian fraction of its value) because the engine has no deterministicexpfor log-space mutation.energy >= max(minEnergy, cost), so paying can never drive energy negative regardless of gene combination.Test plan
pnpm format:checkclean in a fresh clonepnpm checkgreen in a fresh clone: 7 contracts, 55 config (up from 29), 326 simulation (up from 212, 114 new genetics tests)pnpm buildgreen (all 8 packages/apps)pnpm test:determinism: 17/17 against the unchanged goldensObject.keys,**,Math.exp,Math.randomandfor...ininsidegenetics/all fail the determinism lint (temporary violations, reverted)Next: PR 3 makes organisms carry genomes (behavior-preserving, with an equivalence gate against Phase 3's pinned scenarios).
🤖 Generated with Claude Code