Questions about TPE Sampler in parallel settings
Let's say I create a study with a TPE sampler with 100 startup trials as follows:
study_name = ...
storage = ...
sampler= optuna.samplers.TPESampler( n_startup_trials = 100 )
study = optuna.load_study(study_name=study_name, storage=storage, sampler=sampler)
study.optimize(lambda trial: objective(trial), n_trials=1000)
Let's say I then execute the above script in 5 different processes in parallel.
Will each process run 100 startup trials (so I get 500 startup trials in total), or will there be 100 startup trials total in the entire shared study? I.e., the samplers will work together to create the 100 startup trials?
Thank you for your question. That's a good point.
The short answer is that there will be 100 startup trials in the shared study.
I'll show the corresponding code.
In the TPE sampler, n_startup_trials is compared with the number of observed scores.
https://github.com/optuna/optuna/blob/745c9dc3eb89b9be378458da7ee1ee7270c0b4fa/optuna/samplers/_tpe/sampler.py#L405-L416
And, the _get_observation_pairs function collects the observed scores of COMPLETE and PRUNED trials in the study:
https://github.com/optuna/optuna/blob/745c9dc3eb89b9be378458da7ee1ee7270c0b4fa/optuna/samplers/_tpe/sampler.py#L590-L629
So, the sampler counts the number of finished trials in a study to check the n_startup_trials.
Got it - thank you very much! 👍