Skip to content

fix: use island-aware inspiration sampling in sample_from_island#471

Open
pathakanshika144-afk wants to merge 1 commit into
algorithmicsuperintelligence:mainfrom
pathakanshika144-afk:fix/island-inspiration-sampling
Open

fix: use island-aware inspiration sampling in sample_from_island#471
pathakanshika144-afk wants to merge 1 commit into
algorithmicsuperintelligence:mainfrom
pathakanshika144-afk:fix/island-inspiration-sampling

Conversation

@pathakanshika144-afk

Copy link
Copy Markdown

Summary

Fixes #437.

sample_from_island() selects the parent with the same exploration/exploitation/weighted strategy as sample(), but samples inspirations with plain random.sample() when the island is non-empty. Only the empty-island fallback (self.sample()) uses _sample_inspirations(), which applies the island-best + elite + feature-cell diversity strategy. As the issue notes, _sample_inspirations() should be used in all cases.

Change

  • Add island_id: Optional[int] = None to _sample_inspirations(). When provided, it overrides parent.metadata["island"]; when omitted, behavior is unchanged.
  • sample_from_island() now calls self._sample_inspirations(parent, n=num_inspirations, island_id=island_id) instead of random.sample(other_programs, ...).

Why an explicit island_id

_sample_inspirations() resolves the island via parent.metadata.get("island", self.current_island). Reusing it naively would reintroduce two problems:

  1. Thread safetysample_from_island() is documented as thread-safe and does not touch shared state. The current_island fallback would reintroduce a shared-state read for parallel workers.
  2. Archive fallback isolation_sample_from_archive_for_island() falls back to any archive program when the requested island has none, so the returned parent's metadata["island"] may differ from the requested island_id. Relying on parent.metadata would pull inspirations from the wrong island, breaking the genetic isolation that test_sample_from_island_returns_from_correct_island asserts.

Passing island_id explicitly closes both gaps.

Compatibility

  • sample() is unchanged — it calls _sample_inspirations(parent, n=...) without island_id, preserving the existing parent.metadata -> current_island resolution.
  • parent_island %= len(self.islands) is added defensively; sample_from_island() already wraps island_id at entry, so this is a no-op for the new call site but guards future callers.

Tests

New tests/test_sample_from_island_inspirations.py (3 tests):

  • test_sample_from_island_reuses_strategy_aware_inspiration_sampler — verifies delegation to _sample_inspirations(parent, n=..., island_id=island_id).
  • test_explicit_island_overrides_parent_metadata_for_inspirations — parent from island 0, request island 1; inspirations come from island 1, not the parent's island.
  • test_zero_inspirations_is_forwarded_without_random_samplingnum_inspirations=0 is forwarded without random sampling.

Existing tests/test_sample_from_island_ratios.py (8 tests) still passes, including test_sample_from_island_returns_from_correct_island (inspirations stay on the requested island) and test_single_program_island (single-program island returns no inspirations).

sample_from_island() used plain random.sample() for inspirations when the island was non-empty, while only the empty-island fallback used _sample_inspirations() (island best + elites + feature-cell diversity). Add an explicit island_id parameter to _sample_inspirations() and reuse it in sample_from_island(). This keeps parallel workers isolated even when archive fallback returns a parent whose metadata belongs to a different island, and avoids the shared current_island fallback.

Closes algorithmicsuperintelligence#437
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.

BUG: sample_from_island method in PromptDatabase

1 participant