File tree Expand file tree Collapse file tree 4 files changed +26
-1
lines changed Expand file tree Collapse file tree 4 files changed +26
-1
lines changed Original file line number Diff line number Diff line change @@ -83,6 +83,9 @@ class DatabaseConfig:
8383 # Migration parameters for island-based evolution
8484 migration_interval : int = 50 # Migrate every N generations
8585 migration_rate : float = 0.1 # Fraction of population to migrate
86+
87+ # Random seed for reproducible sampling
88+ random_seed : Optional [int ] = None
8689
8790
8891@dataclass
@@ -209,6 +212,7 @@ def to_dict(self) -> Dict[str, Any]:
209212 "feature_bins" : self .database .feature_bins ,
210213 "migration_interval" : self .database .migration_interval ,
211214 "migration_rate" : self .database .migration_rate ,
215+ "random_seed" : self .database .random_seed ,
212216 },
213217 "evaluator" : {
214218 "timeout" : self .evaluator .timeout ,
Original file line number Diff line number Diff line change @@ -66,6 +66,14 @@ def __init__(
6666
6767 # Set up logging
6868 self ._setup_logging ()
69+
70+ # Set random seed for reproducibility if specified
71+ if self .config .random_seed is not None :
72+ import random
73+ import numpy as np
74+ random .seed (self .config .random_seed )
75+ np .random .seed (self .config .random_seed )
76+ logger .info (f"Set random seed to { self .config .random_seed } for reproducibility" )
6977
7078 # Load initial program
7179 self .initial_program_path = initial_program_path
@@ -85,6 +93,11 @@ def __init__(
8593 # Initialize components
8694 self .llm_ensemble = LLMEnsemble (self .config .llm )
8795 self .prompt_sampler = PromptSampler (self .config .prompt )
96+
97+ # Pass random seed to database if specified
98+ if self .config .random_seed is not None :
99+ self .config .database .random_seed = self .config .random_seed
100+
88101 self .database = ProgramDatabase (self .config .database )
89102 self .evaluator = Evaluator (self .config .evaluator , evaluation_file , self .llm_ensemble )
90103
Original file line number Diff line number Diff line change @@ -97,6 +97,12 @@ def __init__(self, config: DatabaseConfig):
9797 # Load database from disk if path is provided
9898 if config .db_path and os .path .exists (config .db_path ):
9999 self .load (config .db_path )
100+
101+ # Set random seed for reproducible sampling if specified
102+ if config .random_seed is not None :
103+ import random
104+ random .seed (config .random_seed )
105+ logger .debug (f"Database: Set random seed to { config .random_seed } " )
100106
101107 logger .info (f"Initialized program database with { len (self .programs )} programs" )
102108
Original file line number Diff line number Diff line change @@ -36,8 +36,10 @@ def __init__(
3636
3737 async def generate (self , prompt : str , ** kwargs ) -> str :
3838 """Generate text from a prompt"""
39+ # Use default system message if not provided in kwargs
40+ system_message = kwargs .pop ('system_message' , "You are a helpful assistant." )
3941 return await self .generate_with_context (
40- system_message = self . config . system_message ,
42+ system_message = system_message ,
4143 messages = [{"role" : "user" , "content" : prompt }],
4244 ** kwargs ,
4345 )
You can’t perform that action at this time.
0 commit comments