1616from openevolve .evaluator import Evaluator
1717from openevolve .evolution_trace import EvolutionTracer
1818from openevolve .llm .ensemble import LLMEnsemble
19- from openevolve .prompt .sampler import PromptSampler
2019from openevolve .process_parallel import ProcessParallelController
21- from openevolve .utils .code_utils import (
22- extract_code_language ,
23- )
24- from openevolve .utils .format_utils import (
25- format_metrics_safe ,
26- format_improvement_safe ,
27- )
20+ from openevolve .prompt .sampler import PromptSampler
21+ from openevolve .utils .code_utils import extract_code_language
22+ from openevolve .utils .format_utils import format_improvement_safe , format_metrics_safe
2823
2924logger = logging .getLogger (__name__ )
3025
@@ -75,17 +70,11 @@ def __init__(
7570 self ,
7671 initial_program_path : str ,
7772 evaluation_file : str ,
78- config_path : Optional [str ] = None ,
79- config : Optional [Config ] = None ,
73+ config : Config ,
8074 output_dir : Optional [str ] = None ,
8175 ):
82- # Load configuration
83- if config is not None :
84- # Use provided Config object directly
85- self .config = config
86- else :
87- # Load from file or use defaults
88- self .config = load_config (config_path )
76+ # Load configuration (loaded in main_async)
77+ self .config = config
8978
9079 # Set up output directory
9180 self .output_dir = output_dir or os .path .join (
@@ -98,9 +87,10 @@ def __init__(
9887
9988 # Set random seed for reproducibility if specified
10089 if self .config .random_seed is not None :
90+ import hashlib
10191 import random
92+
10293 import numpy as np
103- import hashlib
10494
10595 # Set global random seeds
10696 random .seed (self .config .random_seed )
@@ -139,7 +129,7 @@ def __init__(
139129 self .file_extension = f".{ self .file_extension } "
140130
141131 # Set the file_suffix in config (can be overridden in YAML)
142- if not hasattr (self .config , ' file_suffix' ) or self .config .file_suffix == ".py" :
132+ if not hasattr (self .config , " file_suffix" ) or self .config .file_suffix == ".py" :
143133 self .config .file_suffix = self .file_extension
144134
145135 # Initialize components
@@ -175,18 +165,17 @@ def __init__(
175165 if not trace_output_path :
176166 # Default to output_dir/evolution_trace.{format}
177167 trace_output_path = os .path .join (
178- self .output_dir ,
179- f"evolution_trace.{ self .config .evolution_trace .format } "
168+ self .output_dir , f"evolution_trace.{ self .config .evolution_trace .format } "
180169 )
181-
170+
182171 self .evolution_tracer = EvolutionTracer (
183172 output_path = trace_output_path ,
184173 format = self .config .evolution_trace .format ,
185174 include_code = self .config .evolution_trace .include_code ,
186175 include_prompts = self .config .evolution_trace .include_prompts ,
187176 enabled = True ,
188177 buffer_size = self .config .evolution_trace .buffer_size ,
189- compress = self .config .evolution_trace .compress
178+ compress = self .config .evolution_trace .compress ,
190179 )
191180 logger .info (f"Evolution tracing enabled: { trace_output_path } " )
192181 else :
@@ -305,8 +294,11 @@ async def run(
305294 # Initialize improved parallel processing
306295 try :
307296 self .parallel_controller = ProcessParallelController (
308- self .config , self .evaluation_file , self .database , self .evolution_tracer ,
309- file_suffix = self .config .file_suffix
297+ self .config ,
298+ self .evaluation_file ,
299+ self .database ,
300+ self .evolution_tracer ,
301+ file_suffix = self .config .file_suffix ,
310302 )
311303
312304 # Set up signal handlers for graceful shutdown
@@ -349,7 +341,7 @@ def force_exit_handler(signum, frame):
349341 if self .parallel_controller :
350342 self .parallel_controller .stop ()
351343 self .parallel_controller = None
352-
344+
353345 # Close evolution tracer
354346 if self .evolution_tracer :
355347 self .evolution_tracer .close ()
0 commit comments