Skip to content

Lunar lander: workers use the population's CTRNN settings; expose new mutation config - #111

Merged
TLmaK0 merged 1 commit into
developfrom
issue-94-lander-worker-config
Nov 25, 2026
Merged

TLmaK0 merged 1 commit into
developfrom
issue-94-lander-worker-config

Conversation

@TLmaK0

@TLmaK0 TLmaK0 commented Nov 25, 2026

Copy link
Copy Markdown
Owner

What changes

  • Workers now run the evolved dynamics. The Python workers built organisms with Organism::new (τ 0.01, step_time 0.1), but the population and test_champion used τ 0.1 and step_time 0.5. The genome dict sent to the workers now carries the organism's tau, dt, step_time and output_activation. create_organism requires all of them, so a missing setting fails instead of falling back to the defaults.
  • Shared construction logic, tested without Python. OrganismData (snapshot → rebuild), ChampionFile and ConfigFile move to examples/lunar_lander_common/mod.rs. openai_lunar_lander and test_champion both use it, and tests/lunar_lander_tests.rs includes it through #[path]. That test file is compiled in the default CI and does not need pyo3. create_organism only forwards its arguments to OrganismData::to_organism.
  • best_config.json exposes every MutationConfig parameter: per-gene rates, gaussian σ, clipping, compatibility coefficients, target species (null = fixed threshold), stagnation and elitism, disabled-gene inheritance, interspecies mating, dt, and τ mutation.
    • New parameters default to MutationConfig::default().
    • The lander-tuned ones keep the example's values.
    • Missing fields take their defaults and unknown fields are ignored, so old files still load.
    • An unparsable file is now reported. Before, it was silently ignored.
  • weight_mutate_power = 0.87 (gaussian σ). Since Mutación de pesos por gen, gaussiana y con recorte #64 this parameter is the σ of a gaussian. Before Mutación de pesos por gen, gaussiana y con recorte #64, 1.5 meant a uniform ±1.5 perturbation, whose standard deviation is 1.5/√3 ≈ 0.87. Keeping 1.5 would make each perturbation ≈1.7× wider (2.6× in variance) than the one the lander was tuned with. 0.87 keeps the old spread, and it also fits the problem's scale:
    • Observations are mostly in [-1, 1].
    • An output changes action band (thresholds 0.33 / 0.5 / 0.66 on σ(y+θ)) when y moves by about 0.7.
    • So a typical step can change the chosen action without saturating the output. With σ = 1.5, 3σ ≈ 4.5 would often saturate it.
    • I could not run gymnasium here, so this value comes from scale arguments only and has not been checked by a lander run.
  • champion.json stores the CTRNN settings. Old champions load with the values they were evolved with (τ 0.1, dt 0.01, step_time 0.5, sigmoid). serde_json now uses float_roundtrip: without it, a weight such as 0.2084075528757128 loaded back as 0.20840755287571278, so a saved champion was not exactly the one that was evolved. The new round-trip test caught this.
  • serde and serde_json are added as dev-dependencies, for the test.

How it was verified

  • TDD: with the old worker behaviour (Organism::new defaults), tests/lunar_lander_tests.rs was red. Organism 0 gave [0.3136…, 0.6292…] in the population and [0.3145…, 0.6293…] in the worker. With every CTRNN setting changed, the outputs were completely different. With the fix, all 9 tests pass.
  • The main test evolves a population for 15 generations with the lander config (and once more with τ, dt, step_time, linear output and τ genes all changed). It then rebuilds every organism through the worker path and requires bit-identical outputs over 40 random observations, with the CTRNN state carried across steps.
  • Gates (rust:1-slim):
    • cargo fmt -- --check: OK.
    • cargo clippy --release --all-targets: 56 warnings, the same count as develop.
    • cargo build --release --examples: OK.
    • cargo test --release --no-fail-fast: all green (122 unit, 9 new lander tests, the other integration tests, doc-tests).
  • OpenAI examples: cargo check/clippy --release --features openai --example openai_lunar_lander --example test_champion with the stub pyo3 config: OK. --examples as a whole fails on examples/openai.rs (extern crate cpython), which fails the same way on develop and is not touched here.

Closing criterion

  • Workers use the population's τ/dt/step_time/output activation, and a test proves bit-identical outputs for the same genome: met.
  • ConfigFile exposes the new parameters with documented defaults: met.
  • weight_mutate_power re-chosen (0.87) and justified for the gaussian semantics: met. The justification is analytical only; no lander run was possible here.

ref #94
Parte de la épica #55

🤖 Generated with Claude Code

… config, ref #94

- Python workers built organisms with Organism::new (tau 0.01, step_time
  0.1) while the population and test_champion use tau 0.1, step_time 0.5.
  The genome dict now carries the organism's tau, dt, step_time and output
  activation, and create_organism requires them.
- The construction logic (OrganismData, ChampionFile, ConfigFile) moves to
  examples/lunar_lander_common, shared by openai_lunar_lander and
  test_champion and tested without Python in tests/lunar_lander_tests.rs:
  worker-built organisms give bit-identical outputs to the population's for
  every organism of an evolved population.
- best_config.json exposes every MutationConfig parameter; new ones default
  to MutationConfig::default(), missing fields take defaults, unknown fields
  are ignored, and an invalid file is reported instead of silently ignored.
- weight_mutate_power for the lander: 0.87 (gaussian sigma), the standard
  deviation of the old uniform +-1.5 perturbation.
- champion.json stores the CTRNN settings (old files load with the lander
  values) and serde_json uses float_roundtrip so weights load back exactly.
- serde/serde_json as dev-dependencies for the test.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@TLmaK0
TLmaK0 merged commit 348df46 into develop Nov 25, 2026
7 checks passed
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