Created
November 8, 2022 16:22
-
-
Save xadrianzetx/753781c0dd89132343a7c1da6f73dd8e to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import time | |
import optuna | |
import optuna_distributed | |
def objective(trial): | |
x = trial.suggest_float("x", -100, 100) | |
y = trial.suggest_categorical("y", [-1, 0, 1]) | |
time.sleep(1.0) | |
return x**2 + y | |
sequential_start = time.time() | |
study = optuna.create_study() | |
study.optimize(objective, n_trials=20) | |
sequential_duration = time.time() - sequential_start | |
sequential_best_value = study.best_value | |
distributed_start = time.time() | |
distributed_study = optuna_distributed.from_study(study) | |
distributed_study.optimize(objective, n_trials=20) | |
distributed_duration = time.time() - distributed_start | |
distributed_best_value = distributed_study.best_value | |
print(f"Sequential optimization took {sequential_duration:.2f} seconds with best value of {sequential_best_value:.4f}") | |
print(f"Asynchronous optimization took {distributed_duration:.2f} seconds with best value of {distributed_best_value:.4f}") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment