Note
Click here to download the full example code
Easy Parallelization¶
It’s straightforward to parallelize optuna.optimize()
.
If you want to manually execute Optuna optimization:
start an RDB server (this example uses MySQL)
create a study with –storage argument
share the study among multiple nodes and processes
Of course, you can use Kubernetes as in the kubernetes examples.
To just see how parallel optimization works in Optuna, check the below video.
Create a Study¶
You can create a study using optuna create-study
command.
Alternatively, in Python script you can use optuna.create_study()
.
$ mysql -u root -e "CREATE DATABASE IF NOT EXISTS example"
$ optuna create-study --study-name "distributed-example" --storage "mysql://root@localhost/example"
[I 2020-07-21 13:43:39,642] A new study created with name: distributed-example
Then, write an optimization script. Let’s assume that foo.py
contains the following code.
import optuna
def objective(trial):
x = trial.suggest_uniform("x", -10, 10)
return (x - 2) ** 2
if __name__ == "__main__":
study = optuna.load_study(
study_name="distributed-example", storage="mysql://root@localhost/example"
)
study.optimize(objective, n_trials=100)