2626from pdl .optimize .optimizer_evaluator import OptimizerEvaluator
2727from pdl .optimize .pdl_evaluator import PdlEvaluator
2828from pdl .optimize .util import CandidateResult , TrialOutput , console , execute_threads
29+ from pdl .pdl import InterpreterConfig
2930from pdl .pdl_ast import AdvancedBlockType , DataBlock , Program
3031from pdl .pdl_dumper import dump_program_exclude_internals
32+ from pdl .pdl_scheduler import create_event_loop_thread
3133
3234warnings .filterwarnings ("ignore" , category = TqdmExperimentalWarning )
3335FORMAT = "%(message)s"
3638logger .addHandler (RichHandler ())
3739rng = default_rng ()
3840
41+ _LOOP = create_event_loop_thread ()
42+
3943
4044def resave_pdl (input_path : Path , output_path : Path , state : dict ) -> int :
4145 with (input_path .open (encoding = "utf-8" ) as pdl ,):
@@ -73,6 +77,7 @@ def __init__(
7377 self ,
7478 dataset : DatasetDict ,
7579 config : OptimizationConfig ,
80+ pdl_config : InterpreterConfig ,
7681 trial_thread : type [OptimizerEvaluator ],
7782 yield_output : bool ,
7883 experiment_path : Path ,
@@ -81,6 +86,7 @@ def __init__(
8186 self .yield_output = yield_output
8287
8388 self .config = config
89+ self .pdl_config = pdl_config
8490 self .pdl_path = Path (config .pdl_path )
8591 self .parallelism = config .parallelism
8692 self .num_demonstrations = config .num_demonstrations
@@ -631,6 +637,7 @@ def evaluate(
631637 timeout = self .timeout ,
632638 yield_output = self .yield_output ,
633639 config = self .config ,
640+ pdl_config = self .pdl_config ,
634641 cwd = pdl_file_parent ,
635642 ),
636643 )
@@ -827,13 +834,17 @@ def run_optimizer() -> int:
827834 print (f"Unknown dataset: { config .dataset } " )
828835 sys .exit (1 )
829836
837+ pdl_config = InterpreterConfig ()
838+ pdl_config ["event_loop" ] = _LOOP
839+
830840 # Create optimizer instance
831841 optimizer = PDLOptimizer (
832842 dataset = dataset ,
833843 trial_thread = PdlEvaluator ,
834844 yield_output = args .yield_output ,
835845 experiment_path = args .experiments_path ,
836846 config = config ,
847+ pdl_config = pdl_config ,
837848 )
838849 optimizer .run ()
839850 return 0
0 commit comments