Skip to content

Deprecate legacy methods that bypass the population's RNG, config or registry (ref #103) - #120

Merged
TLmaK0 merged 1 commit into
developfrom
issue-103-legacy-api-consistency
Nov 25, 2026
Merged

TLmaK0 merged 1 commit into
developfrom
issue-103-legacy-api-consistency

Conversation

@TLmaK0

@TLmaK0 TLmaK0 commented Nov 25, 2026 •

Copy link
Copy Markdown
Owner

What changes

Every public method that bypasses the population's random generator, MutationConfig or InnovationRegistry is now #[deprecated] with a note naming the variant Population uses, and its rustdoc says what it bypasses. No behaviour changes: each deprecated method runs the same code as before.

  • Genome: new_initialized, mutate, mutate_with_config, mutate_with_config_and_rng, mate, mate_with_rng, mate_equal_with_rng, is_same_specie, is_same_specie_with_threshold, compatibility_distance.
  • Organism: mutate, mutate_with_config, mutate_with_config_and_rng, mate, mate_with_rng. New Organism::with_config(genome, &config) (the population uses it for its initial organisms); Organism::new is documented as with_config with the default config.
  • Specie: match_genome, match_genome_with_threshold, generate_offspring, generate_offspring_with_config, generate_offspring_with_config_and_rng, parents, choose_new_representative.
  • Gene: generate_weight, generate_weight_in_range, new_connection. The genome used new_connection as a binary-search key (one thread_rng draw per lookup in the add-connection path); it now uses a draw-free internal key.
  • MutationConfig: new() (returns a builder) is deprecated in favour of the new MutationConfig::builder().
  • Genome::add_gene is kept: it is a construction primitive, not a legacy variant. Its re-enabling of an existing connection (keeping the old weight) is now documented and tested.

Internally, Specie::create_child and the deprecated wrappers call pub(crate) mutate_with_registry helpers, so no crate code uses deprecated items. Examples, README and tests moved to the non-deprecated variants. The full inventory table is in the comment on #103.

Verification

  • TDD: tests/legacy_api_tests.rs (12 tests) was red first (no MutationConfig::builder, no Organism::with_config). It checks each deprecated method against the variant it points to, using the same seed: identical genomes, distances and species decisions. It also checks Organism::new == with_config(default) and add_gene re-enabling.
  • cargo fmt -- --check: OK
  • cargo clippy --release --all-targets -- -D warnings: 0 warnings (also --features telemetry and --all-features with the pyo3 stub)
  • cargo build --release --examples: OK; cargo check --release --features openai --examples: OK
  • cargo test --release --no-fail-fast: all green (133 unit, all integration binaries, 5 doc-tests), including long_run_identity_tests (hash unchanged)

Closing criterion

Each legacy method is either deprecated pointing to the correct variant, or kept and documented (add_gene, Organism::new, impl Default for Gene). All are documented in rustdoc, and tests cover the chosen behaviour.

Results unchanged. Banco A (xor_bench 50 500 init reset=1 seed=S), develop 0bb2e78 vs this branch, SUMMARY lines identical except total_secs:
seeds 1/101/201/301 → 50/50 solved each, medians 52/53/53/51, means 52.6/53.6/52.0/50.4.

ref #103
Part of epic #55

🤖 Generated with Claude Code

…registry, ref #103

Every public method that draws from rand::thread_rng, uses the default
MutationConfig instead of the population's, or numbers new neurons without
the InnovationRegistry is now #[deprecated] with a note naming the variant
the population uses, and documents what it bypasses. Behaviour is unchanged:
each deprecated method calls the same code as before.

- Genome: new_initialized, mutate, mutate_with_config,
  mutate_with_config_and_rng, mate, mate_with_rng, mate_equal_with_rng,
  is_same_specie, is_same_specie_with_threshold, compatibility_distance.
- Organism: mutate, mutate_with_config, mutate_with_config_and_rng, mate,
  mate_with_rng. New Organism::with_config(genome, &config) (used by the
  population); Organism::new documented as with_config(default).
- Specie: match_genome, match_genome_with_threshold, generate_offspring,
  generate_offspring_with_config, generate_offspring_with_config_and_rng,
  parents, choose_new_representative.
- Gene: generate_weight, generate_weight_in_range, new_connection (the
  genome now looks genes up with a draw-free internal key).
- MutationConfig::new() (returns a builder) deprecated in favour of the new
  MutationConfig::builder().
- Genome::add_gene kept as a construction primitive; its re-enabling of an
  existing connection is documented and tested.

Crate code, examples, README and tests use the non-deprecated variants;
tests/legacy_api_tests.rs checks each deprecated method against the variant
it points to. Banco A (seeds 1/101/201/301) is bit-identical and the
long-run identity hash is unchanged.

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