Skip to content

fix(metrics): exclude boolean flags from numeric sums and standardize fitness ranking in workers - #607

Merged
codelion merged 1 commit into
algorithmicsuperintelligence:mainfrom
im-apratap:fix-boolean-metrics-and-fitness-ranking
Nov 23, 2026
Merged

codelion merged 1 commit into
algorithmicsuperintelligence:mainfrom
im-apratap:fix-boolean-metrics-and-fitness-ranking

Conversation

@im-apratap

Copy link
Copy Markdown
Contributor

Overview & Problem Statement

In Python, bool is a subclass of int (isinstance(True, (int, float)) evaluates to True). In OpenEvolve, boolean values in evaluation metric dictionaries represent status/metadata flags (e.g. {"timeout": True, "error": 0.0}, {"valid": True}) rather than numeric scores. Naive numeric type checks treat booleans as 1.0 and 0.0.

While prior work guarded safe_numeric_average, several critical locations were missed:

  1. safe_numeric_sum (openevolve/utils/metrics_utils.py):
    Filtered isinstance(value, (int, float)) without checking not isinstance(value, bool). A metric dictionary like {"score": 10.0, "valid": True} summed to 11.0. Non-finite floats like NaN were also not safely rejected using math.isnan.

  2. get_fitness_score (openevolve/utils/metrics_utils.py):
    Directly called float(metrics["combined_score"]). When an evaluation fails returning {"combined_score": False, "error": ...}, float(False) became 0.0. In loss-based or error-minimization benchmarks where valid scores are negative (e.g. -5.0), failed programs improperly outscored valid programs.

  3. format_feature_coordinates (openevolve/utils/metrics_utils.py):
    Formatted boolean MAP-Elites feature coordinates as floating point numbers (e.g. valid=1.00) instead of boolean literals (valid=True), creating confusing prompt inputs.

  4. Worker Top Program Ranking (openevolve/process_parallel.py):
    _run_iteration_worker sorted island programs using key=lambda p: p.metrics.get("combined_score", safe_numeric_average(p.metrics)). This bypassed get_fitness_score:

    • NaN combined scores were not mapped to -inf, leading to inconsistent Timsort ordering.
    • When combined_score was missing, safe_numeric_average included MAP-Elites feature dimensions (e.g., complexity: 500), causing high-complexity programs to be misclassified as top performers and fed to the LLM.
  5. Target Score & Early Stopping Safeguards (openevolve/process_parallel.py):
    Target score and early stopping checks now guard against boolean flags and NaN values, and default early stopping falls back to get_fitness_score(..., feature_dimensions) to avoid feature metric pollution.

  6. Threshold Checks (openevolve/evaluator.py):
    _passes_threshold now guards combined_score against booleans and NaN, preventing boolean flags like False from meeting threshold <= 0.0.

  7. Prompt Evolution History (openevolve/prompt/sampler.py):
    _format_evolution_history now formats boolean metrics as literal True/False and excludes them from numeric metric improvement comparisons, preventing a boolean flag flip (e.g. valid: False -> valid: True) from falsely marking an attempt as "All metrics improved".


Changes

  • openevolve/utils/metrics_utils.py:
    • Exclude boolean flags and NaN in safe_numeric_sum.
    • Guard combined_score against boolean values and map NaN to -inf in get_fitness_score.
    • Render boolean feature coordinates as literals in format_feature_coordinates.
    • Added thorough docstrings and inline explanatory comments.
  • openevolve/process_parallel.py:
    • Sort worker island programs using get_fitness_score(p.metrics, feature_dims) to handle NaNs and exclude MAP-Elites features.
    • Guard target score comparison and early stopping metric tracking against booleans and NaN.
  • openevolve/evaluator.py:
    • Guard combined_score against booleans and NaN in _passes_threshold.
  • openevolve/prompt/sampler.py:
    • Render booleans as literals in history performance formatting.
    • Exclude boolean flags from numeric improvement/regression calculations in history comparisons.
  • tests/test_boolean_metrics_extended.py:
    • Added 15 comprehensive unit tests covering all functions and edge cases with full PEP 257 docstrings.

Verification

  • Code Formatting & Linting:
    • Passed black --check across all modified files.
    • Passed isort --check across all modified files.
  • Tests:
    • tests/test_boolean_metrics_extended.py: 15/15 passed.
    • tests/test_boolean_metrics.py: 9/9 passed.
    • Full pytest suite: 1,075 passed, 7 skipped, 28 deselected.

…ize fitness ranking in workers

- safe_numeric_sum: explicitly exclude boolean flags and NaNs
- get_fitness_score: guard combined_score against boolean false positives and convert NaNs to -inf
- format_feature_coordinates: format boolean coordinates as boolean literals rather than floats
- Evaluator._passes_threshold: guard combined_score against booleans and NaNs
- PromptSampler._format_evolution_history: exclude boolean flags from numeric comparisons and format as boolean literals
- ProcessParallelController: standardize island program sorting with get_fitness_score and safeguard target_score/early_stopping
- Add comprehensive docstrings, inline explanatory comments, and test suite
@CLAassistant

CLAassistant commented Nov 22, 2026 •

Copy link
Copy Markdown

CLA assistant check
All committers have signed the CLA.

@CLAassistant

Copy link
Copy Markdown

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you sign our Contributor License Agreement before we can accept your contribution.
You have signed the CLA already but the status is still pending? Let us recheck it.

@codelion
codelion merged commit 5834310 into algorithmicsuperintelligence:main Nov 23, 2026
5 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.

3 participants