Skip to content

Commit 9f8b3c4

Browse files
committed
Simplify config loading in main_async
1 parent b14064a commit 9f8b3c4

File tree

2 files changed

+21
-31
lines changed

2 files changed

+21
-31
lines changed

openevolve/cli.py

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -78,12 +78,11 @@ async def main_async() -> int:
7878
print(f"Error: Evaluation file '{args.evaluation_file}' not found")
7979
return 1
8080

81+
# Load base config from file or defaults
82+
config = load_config(args.config)
83+
8184
# Create config object with command-line overrides
82-
config = None
8385
if args.api_base or args.primary_model or args.secondary_model:
84-
# Load base config from file or defaults
85-
config = load_config(args.config)
86-
8786
# Apply command-line overrides
8887
if args.api_base:
8988
config.llm.api_base = args.api_base
@@ -110,7 +109,6 @@ async def main_async() -> int:
110109
initial_program_path=args.initial_program,
111110
evaluation_file=args.evaluation_file,
112111
config=config,
113-
config_path=args.config if config is None else None,
114112
output_dir=args.output,
115113
)
116114

openevolve/controller.py

Lines changed: 18 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -16,15 +16,10 @@
1616
from openevolve.evaluator import Evaluator
1717
from openevolve.evolution_trace import EvolutionTracer
1818
from openevolve.llm.ensemble import LLMEnsemble
19-
from openevolve.prompt.sampler import PromptSampler
2019
from 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

2924
logger = 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

Comments
 (0)