Skip to content

fix(metrics): rank a NaN combined_score as the worst score - #603

Merged
codelion merged 2 commits into
algorithmicsuperintelligence:mainfrom
Bhaveshmeghwal21:fix/nan-combined-score
Nov 20, 2026
Merged

codelion merged 2 commits into
algorithmicsuperintelligence:mainfrom
Bhaveshmeghwal21:fix/nan-combined-score

Conversation

@Bhaveshmeghwal21

@Bhaveshmeghwal21 Bhaveshmeghwal21 commented Nov 19, 2026 •

Copy link
Copy Markdown
Contributor

get_fitness_score returns combined_score as it is, so a NaN score (a numpy 0/0, the mean of an empty array) gives the program a NaN fitness. Every comparison with NaN is False, so _is_better is never true against it. If that program is the first one in the database, a cell or an island, nothing can replace it and it stays the best program:

db.add(Program(id="nan", code="x = 1", metrics={"combined_score": float("nan")}))
db.add(Program(id="good", code="x = 2", metrics={"combined_score": 0.9}))
db.best_program_id  # "nan" before, "good" after

A NaN combined_score now gives -inf, so that program ranks below every other one, negative scores included. Valid scores, inf and -inf are unchanged.

I first fell back to averaging the other metrics, as for a combined_score that cannot be converted to a float. That let a NaN program that also reported eval_time or similar outrank valid programs, so I dropped it.

Not changed: process_parallel.py sorts the programs shown in the prompt by the raw combined_score, so a NaN still sorts oddly there. Using get_fitness_score for that sort would be a small follow-up.

tests/test_nan_combined_score.py has four tests. Two fail without the change; the other two check that valid scores are unchanged and that a NaN program does not replace a valid one. The full unittest run has the same 33 failing tests with and without the change (all environment-related on my Windows checkout).

get_fitness_score returned a NaN combined_score as it was. NaN loses every
comparison, so a program with that fitness could never be beaten and stayed
the best program. Fall back to the other metrics, as for any other unusable
combined_score.
@CLAassistant

CLAassistant commented Nov 19, 2026 •

Copy link
Copy Markdown

CLA assistant check
All committers have signed the CLA.

… other metrics

Averaging the other metrics for a NaN combined_score let a program with a NaN
score outrank valid programs when it reported another metric such as eval_time.
Return -inf so it ranks below every other program, and test that a valid
program is not replaced by one.
@Bhaveshmeghwal21 Bhaveshmeghwal21 changed the title fix(metrics): ignore a NaN combined_score when computing fitness fix(metrics): rank a NaN combined_score as the worst score Nov 19, 2026
@codelion
codelion merged commit 4167db4 into algorithmicsuperintelligence:main Nov 20, 2026
5 checks passed
will-rice added a commit to will-rice/openevolve that referenced this pull request Nov 21, 2026
Upstream's fixes: a NaN combined_score ranks worst (algorithmicsuperintelligence#603), the evaluator's and
the novelty judge's LLM calls count in the token totals (algorithmicsuperintelligence#604), Mistral API
support (algorithmicsuperintelligence#602), responses cut off at max_tokens are reported (algorithmicsuperintelligence#599), nested
candidate definitions dedent (algorithmicsuperintelligence#601), llm.system_message is no longer dropped
(algorithmicsuperintelligence#598), Gemini seeding without a trailing slash (algorithmicsuperintelligence#600) and an R example fix (algorithmicsuperintelligence#597).

Two conflicts, both where the fork had moved upstream's code:
- llm/ensemble.py: upstream's per-call usage sum (_record_usage, take_usage)
  beside the fork's last_message and last_backend, both kept.
- process_parallel.py: the fork evaluates a child in _evaluate_child (generated
  and injected children alike); upstream's count of the evaluator's own LLM calls
  moves there, after the evaluation, into the result's and the metadata's usage.

The fork's suite fails the same 23 tests before and after the merge (upstream's
own, unrelated to it).

Claude-Session: https://claude.ai/code/session_01RnaESRvvoubZsW6wWrQAPQ
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