Skip to content

Instantly share code, notes, and snippets.

@gyu-don
Created December 3, 2018 11:46
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gyu-don/d63a33e98c4ca30d32302b47bb82f96d to your computer and use it in GitHub Desktop.
Save gyu-don/d63a33e98c4ca30d32302b47bb82f96d to your computer and use it in GitHub Desktop.
Blueqat VQE minimizer using PFN's Optuna library
import optuna
def get_optuna_minimizer(n_trials, study=None):
if study is None:
study = optuna.create_study()
def minimizer(objective, n_params):
def optuna_objective(trial):
params = [trial.suggest_uniform(f'params[{i}]', 0.0, 1.0) for i in range(n_params)]
return objective(params)
study.optimize(optuna_objective, n_trials=n_trials)
return [study.best_params[k] for k in sorted(study.best_params)]
return minimizer
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment