@@ -35,31 +35,6 @@ class OpenEvolve:
3535 LLM ensemble, evaluator, and program database.
3636 """
3737
38- # Mapping of language identifiers to their conventional file extensions
39- LANGUAGE_TO_EXTENSION = {
40- "python" : "py" ,
41- "javascript" : "js" ,
42- "typescript" : "ts" ,
43- "java" : "java" ,
44- "c" : "c" ,
45- "cpp" : "cpp" ,
46- "csharp" : "cs" ,
47- "go" : "go" ,
48- "rust" : "rs" ,
49- "php" : "php" ,
50- "ruby" : "rb" ,
51- "swift" : "swift" ,
52- "kotlin" : "kt" ,
53- "scala" : "scala" ,
54- "r" : "r" ,
55- "shell" : "sh" ,
56- "sql" : "sql" ,
57- "html" : "html" ,
58- "css" : "css" ,
59- "yaml" : "yaml" ,
60- "json" : "json" ,
61- }
62-
6338 def __init__ (
6439 self ,
6540 initial_program_path : str ,
@@ -90,6 +65,16 @@ def __init__(
9065 self .initial_program_code = self ._load_initial_program ()
9166 self .language = extract_code_language (self .initial_program_code )
9267
68+ # Extract file extension from initial program
69+ self .file_extension = os .path .splitext (initial_program_path )[1 ]
70+ if not self .file_extension :
71+ # Default to .py if no extension found
72+ self .file_extension = ".py"
73+ else :
74+ # Make sure it starts with a dot
75+ if not self .file_extension .startswith ("." ):
76+ self .file_extension = f".{ self .file_extension } "
77+
9378 # Initialize components
9479 self .llm_ensemble = LLMEnsemble (self .config .llm )
9580 self .prompt_sampler = PromptSampler (self .config .prompt )
@@ -347,11 +332,10 @@ def _save_best_program(self, program: Program) -> None:
347332 best_dir = os .path .join (self .output_dir , "best" )
348333 os .makedirs (best_dir , exist_ok = True )
349334
350- # Convert language name to proper file extension
351- extension = self .LANGUAGE_TO_EXTENSION .get (program .language .lower (), program .language )
335+ # Use the extension from the initial program file
336+ filename = f"best_program{ self .file_extension } "
337+ code_path = os .path .join (best_dir , filename )
352338
353- # Save the program code
354- code_path = os .path .join (best_dir , f"best_program.{ extension } " )
355339 with open (code_path , "w" ) as f :
356340 f .write (program .code )
357341
0 commit comments