Repository navigation
Conversation
The evaluator writes candidate programs as UTF-8, but the controller read the initial program and island seeds, and wrote best_program files, in the locale's encoding, and TemplateManager read the prompt templates the same way. The default fragments.json contains U+2192, so under a locale that cannot decode it (e.g. GBK on Windows) OpenEvolve failed in its constructor, and a best program with non-ASCII text could not be saved under an ASCII or cp1252 locale. Use UTF-8 for these files regardless of locale.
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.
Problem
The evaluator writes each candidate program to disk as UTF-8 (
program_code.encode("utf-8")), but the controller andTemplateManageropen the same kind of text with the locale's default encoding:controller.py: reading the initial program andisland_initial_programs, writingbest/best_program.*andcheckpoint_N/best_program.*prompt/templates.py: reading the.txttemplates andfragments.jsonUnder a non-UTF-8 locale this breaks in two ways.
1. OpenEvolve cannot start. The default
fragments.jsoncontains→(U+2192) infitness_improved/fitness_declined. On Windows with a GBK code page (the default for Chinese-language systems), constructingOpenEvolvefails:With cp1252 the bytes decode without an error, so the arrow reaches the LLM prompt as mojibake instead.
2. Programs with non-ASCII text are misread or cannot be saved. An initial program with a non-ASCII comment or string fails to load (or loads as mojibake that is then evolved):
and a best program containing a character the locale cannot encode raises
UnicodeEncodeErrorwhen the checkpoint or the final best program is written, after the evolution has already run.Fix
Pass
encoding="utf-8"to these sixopen()calls, matching what the evaluator already does for candidate programs.Other text files opened without an encoding (e.g.
api.py,coevolution.py, config YAML) are left for separate changes to keep this one small.Tests
tests/test_controller_utf8_programs.pyfollowstest_cli_utf8.py: it runs a realOpenEvolvein a subprocess under a non-UTF-8 locale (LC_ALL=C,PYTHONUTF8=0; skipped if the platform still reports UTF-8) and checks that the initial program and an island seed load unchanged, and that bothbest_programfiles are valid UTF-8 with the original text. It fails onmainwith the errors above.On a Windows machine with a GBK code page, this change also takes the existing suite from 111 errors to 48; the remaining ones I looked at come from other files opened without an encoding (e.g. the evaluator script written by
api.py) and from tests that assume POSIX paths.