Repository navigation
fix(metrics): exclude boolean flags from numeric sums and standardize fitness ranking in workers - #607
Merged
codelion merged 1 commit intoNov 23, 2026
Conversation
…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
|
|
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.
Overview & Problem Statement
In Python,
boolis a subclass ofint(isinstance(True, (int, float))evaluates toTrue). 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 as1.0and0.0.While prior work guarded
safe_numeric_average, several critical locations were missed:safe_numeric_sum(openevolve/utils/metrics_utils.py):Filtered
isinstance(value, (int, float))without checkingnot isinstance(value, bool). A metric dictionary like{"score": 10.0, "valid": True}summed to11.0. Non-finite floats likeNaNwere also not safely rejected usingmath.isnan.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)became0.0. In loss-based or error-minimization benchmarks where valid scores are negative (e.g.-5.0), failed programs improperly outscored valid programs.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.Worker Top Program Ranking (
openevolve/process_parallel.py):_run_iteration_workersorted island programs usingkey=lambda p: p.metrics.get("combined_score", safe_numeric_average(p.metrics)). This bypassedget_fitness_score:NaNcombined scores were not mapped to-inf, leading to inconsistent Timsort ordering.combined_scorewas missing,safe_numeric_averageincluded MAP-Elites feature dimensions (e.g.,complexity: 500), causing high-complexity programs to be misclassified as top performers and fed to the LLM.Target Score & Early Stopping Safeguards (
openevolve/process_parallel.py):Target score and early stopping checks now guard against boolean flags and
NaNvalues, and default early stopping falls back toget_fitness_score(..., feature_dimensions)to avoid feature metric pollution.Threshold Checks (
openevolve/evaluator.py):_passes_thresholdnow guardscombined_scoreagainst booleans andNaN, preventing boolean flags likeFalsefrom meetingthreshold <= 0.0.Prompt Evolution History (
openevolve/prompt/sampler.py):_format_evolution_historynow formats boolean metrics as literalTrue/Falseand 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:NaNinsafe_numeric_sum.combined_scoreagainst boolean values and mapNaNto-infinget_fitness_score.format_feature_coordinates.openevolve/process_parallel.py:get_fitness_score(p.metrics, feature_dims)to handle NaNs and exclude MAP-Elites features.NaN.openevolve/evaluator.py:combined_scoreagainst booleans andNaNin_passes_threshold.openevolve/prompt/sampler.py:tests/test_boolean_metrics_extended.py:Verification
black --checkacross all modified files.isort --checkacross all modified files.tests/test_boolean_metrics_extended.py: 15/15 passed.tests/test_boolean_metrics.py: 9/9 passed.