From 3f435f8459871e30e48a4491d65ebe5c1f29a63f Mon Sep 17 00:00:00 2001 From: johba Date: Fri, 13 Mar 2026 10:02:24 +0100 Subject: [PATCH] =?UTF-8?q?fix:=20evolution=20scoring=20=E2=80=94=203=20bu?= =?UTF-8?q?gs=20made=20all=20candidates=20report=20fitness=3D0=20(#665)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ## Three bugs in evolve.sh 1. **Heredoc stdin conflict** — `py_stats()` used `<9.2e18) → best always tracked as 0 3. **candidate_id mismatch** — evolve.sh looked up `gen0_c000` but batch-eval produces `candidate_000` (derived from filename) → score lookup always returned default 0 All 3 previous evolution runs (150+ candidates) reported all zeros despite batch-eval correctly scoring them at ~8.26e21 wei. ## Fix - `py_stats`: heredoc → `python3 -c` inline - Global best: bash `[ -gt ]` → `python3` big number comparison - Score lookup: use `basename $CAND_FILE` instead of synthetic CID Co-authored-by: root Reviewed-on: https://codeberg.org/johba/harb/pulls/665 Reviewed-by: review_bot --- tools/push3-evolution/evolve.sh | 16 +++++----------- 1 file changed, 5 insertions(+), 11 deletions(-) diff --git a/tools/push3-evolution/evolve.sh b/tools/push3-evolution/evolve.sh index 3d2ea4e..6e6d737 100755 --- a/tools/push3-evolution/evolve.sh +++ b/tools/push3-evolution/evolve.sh @@ -156,15 +156,7 @@ run_seed_gen_cli() { # Integer min/max/mean via python3 (bash arithmetic overflows on wei values). py_stats() { - # Args: space-separated integers on stdin as a Python list literal - python3 - "$@" <<'PYEOF' -import sys -nums = [int(x) for x in sys.stdin.read().split()] -if not nums: - print("0 0 0") - sys.exit(0) -print(min(nums), max(nums), round(sum(nums) / len(nums))) -PYEOF + python3 -c "import sys; nums = [int(x) for x in sys.stdin.read().split()]; print(min(nums) if nums else 0, max(nums) if nums else 0, round(sum(nums)/len(nums)) if nums else 0)" } # Top-N selection: return filepaths of the N highest-scoring candidates (descending). @@ -383,7 +375,9 @@ for gen in $(seq 0 $((GENERATIONS - 1))); do if [ "$EVAL_MODE" = "revm" ] && [ -f "$BATCH_SCORES_FILE" ]; then # Look up pre-computed score from batch-eval.sh output. - SCORE=$(python3 - "$CID" "$BATCH_SCORES_FILE" <<'PYEOF' + # batch-eval uses filename as candidate_id (e.g. "candidate_000") + BATCH_CID="$(basename "$CAND_FILE" .push3)" + SCORE=$(python3 - "$BATCH_CID" "$BATCH_SCORES_FILE" <<'PYEOF' import json, sys cid = sys.argv[1] with open(sys.argv[2]) as f: @@ -451,7 +445,7 @@ print(max(entries, key=lambda x: x[0])[1]) PYEOF ) || fail "Could not determine best candidate from $SCORES_FILE" - if [ "$MAX" -gt "$GLOBAL_BEST_FITNESS" ] || [ "$GLOBAL_BEST_FITNESS" -eq -1 ]; then + if python3 -c "import sys; sys.exit(0 if int(sys.argv[1]) > int(sys.argv[2]) else 1)" "$MAX" "$GLOBAL_BEST_FITNESS" || [ "$GLOBAL_BEST_FITNESS" = "-1" ]; then GLOBAL_BEST_FITNESS="$MAX" GLOBAL_BEST_GEN="$gen" GLOBAL_BEST_CAND="$BEST_FILE_THIS_GEN"