« Back to top page

Built-In

Built-In

BoTorch Sampler

Class or Function Names BoTorchSampler Installation pip install optuna-integration botorch Example from optuna_integration import BoTorchSampler sampler = BoTorchSampler() Others See the documentation for more details.

Brute Force Search

Class or Function Names BruteForceSampler Example import optuna from optuna.samplers import BruteForceSampler def objective(trial): x = trial.suggest_float("x", -5, 5, step=1) return x**2 sampler = BruteForceSampler() study = optuna.create_study(sampler=sampler) study.optimize(objective, n_trials=10) Others See the documentation for more details.

CMA-ES Sampler

Class or Function Names CmaEsSampler Installation pip install cmaes Example import optuna from optuna.samplers import CmaEsSampler def objective(trial): x = trial.suggest_float("x", -1, 1) y = trial.suggest_int("y", -1, 1) return x**2 + y sampler = CmaEsSampler() study = optuna.create_study(sampler=sampler) study.optimize(objective, n_trials=20) Others See the documentation for more details.

Contour Plot

Class or Function Names plot_contour Example from optuna.visualization import plot_contour plot_contour(study) Others See the documentation for more details.

Empirical Distribution Function Plot

Class or Function Names plot_edf Example from optuna.visualization import plot_edf plot_edf(study) Others See the documentation for more details.

Gaussian Process-Based Sampler

Class or Function Names GPSampler Installation pip install scipy torch Example import optuna from optuna.samplers import GPSampler def objective(trial): x = trial.suggest_float("x", -5, 5) return x**2 sampler = GPSampler() study = optuna.create_study(sampler=sampler) study.optimize(objective, n_trials=100) Others See the documentation for more details.

Grid Search

Class or Function Names GridSampler Example import optuna from optuna.samplers import GridSampler def objective(trial): x = trial.suggest_float("x", -100, 100) y = trial.suggest_int("y", -100, 100) return x**2 + y**2 search_space = {"x": [-50, 0, 50], "y": [-99, 0, 99]} sampler = GridSampler(search_space) study = optuna.create_study(sampler=sampler) study.optimize(objective) Others See the documentation for more details.

Hyperband Pruner

Class or Function Names HyperbandPruner Example study = optuna.create_study( direction="maximize", pruner=optuna.pruners.HyperbandPruner( min_resource=1, max_resource=n_train_iter, reduction_factor=3 ), ) study.optimize(objective, n_trials=20) See example.py for a full example. Others See the documentation for more details.

Hyperparameter Importances Plot

Class or Function Names plot_param_importances Example from optuna.visualization import plot_param_importances plot_param_importances(study) Others See the documentation for more details.

Hypervolume History Plot

Class or Function Names plot_hypervolume_history Example from optuna.visualization import plot_hypervolume_history plot_hypervolume_history(study, reference_point) Others See the documentation for more details.

Intermediate Values Plot

Class or Function Names plot_intermediate_values Example from optuna.visualization import plot_intermediate_values plot_intermediate_values(study) Others See the documentation for more details.

Median Pruner

Class or Function Names MedianPruner Example import optuna from optuna.pruners import MedianPruner def objective(trial): s = 0 for step in range(20): x = trial.suggest_float(f"x_{step}", -5, 5) s += x**2 trial.report(s, step) if trial.should_prune(): raise optuna.TrialPruned() return s pruner = MedianPruner() study = optuna.create_study(pruner=pruner) study.optimize(objective, n_trials=20) Others See the documentation for more details.

Nop Pruner

Class or Function Names NopPruner Example study = optuna.create_study(direction="maximize", pruner=optuna.pruners.NopPruner()) study.optimize(objective, n_trials=20) See example.py for a full example. Others See the documentation for more details.

NSGAII Search

Class or Function Names NSGAIISampler Example import optuna from optuna.samplers import NSGAIISampler def objective(trial): x = trial.suggest_float("x", -5, 5) return x**2 sampler = NSGAIISampler() study = optuna.create_study(sampler=sampler) study.optimize(objective, n_trials=10) Others See the documentation for more details.

NSGAIII Search

Class or Function Names NSGAIIISampler Example import optuna from optuna.samplers import NSGAIIISampler def objective(trial): x = trial.suggest_float("x", -5, 5) return x**2 sampler = NSGAIIISampler() study = optuna.create_study(sampler=sampler) study.optimize(objective, n_trials=10) Others See the documentation for more details.

Optimization History Plot

Class or Function Names plot_optimization_history Example from optuna.visualization import plot_optimization_history plot_optimization_history(study) Others See the documentation for more details.

Parallel Coordinate Plot

Class or Function Names plot_parallel_coordinate Example from optuna.visualization import plot_parallel_coordinate plot_parallel_coordinate(study) Others See the documentation for more details.

Pareto-front Plot

Class or Function Names plot_pareto_front Example from optuna.visualization import plot_pareto_front plot_pareto_front(study) Others See the documentation for more details.

Partial Fixed Sampler

Class or Function Names PartialFixedSampler Example import optuna from optuna.samplers import PartialFixedSampler def objective(trial): x = trial.suggest_float("x", -1, 1) y = trial.suggest_int("y", -1, 1) return x**2 + y tpe_sampler = optuna.samplers.TPESampler() fixed_params = {"y": 0} partial_sampler = PartialFixedSampler(fixed_params, tpe_sampler) study = optuna.create_study(sampler=partial_sampler) study.optimize(objective, n_trials=10) Others See the documentation for more details.

Patient Pruner

Class or Function Names PatientPruner Example study = optuna.create_study( direction="maximize", pruner=optuna.pruners.PatientPruner(optuna.pruners.MedianPruner(), patience=1), ) study.optimize(objective, n_trials=20) See example.py for a full example. Others See the documentation for more details.

Percentile Pruner

Class or Function Names PercentilePruner Example import optuna from optuna.pruners import PercentilePruner def objective(trial): s = 0 for step in range(20): x = trial.suggest_float(f"x_{step}", -5, 5) s += x**2 trial.report(s, step) if trial.should_prune(): raise optuna.TrialPruned() return s pruner = PercentilePruner(25.0) study = optuna.create_study(pruner=pruner) study.optimize(objective, n_trials=20) Others See the documentation for more details.

PyCMA Sampler

Class or Function Names PyCmaSampler Installation pip install optuna-integration cma Example from optuna_integration import PyCmaSampler sampler = PyCmaSampler() Others See the documentation for more details.

QMC Search

Class or Function Names QMCSampler Example import optuna from optuna.samplers import QMCSampler def objective(trial): x = trial.suggest_float("x", -5, 5) return x**2 sampler = QMCSampler() study = optuna.create_study(sampler=sampler) study.optimize(objective, n_trials=10) Others See the documentation for more details.

Random Search

Class or Function Names RandomSampler Example import optuna from optuna.samplers import RandomSampler def objective(trial): x = trial.suggest_float("x", -5, 5) return x**2 sampler = RandomSampler() study = optuna.create_study(sampler=sampler) study.optimize(objective, n_trials=10) Others See the documentation for more details.

Rank Plot

Class or Function Names plot_rank Example from optuna.visualization import plot_rank plot_rank(study) Others See the documentation for more details.

Slice Plot

Class or Function Names plot_slice Example from optuna.visualization import plot_slice plot_slice(study) Others See the documentation for more details.

Successive Halving Pruner

Class or Function Names SuccessiveHalvingPruner Example study = optuna.create_study( direction="maximize", pruner=optuna.pruners.SuccessiveHalvingPruner() ) study.optimize(objective, n_trials=20) See example.py for a full example. Others See the documentation for more details.

Terminator Callback

Abstract This callback implements an automatic stopping mechanism for Optuna studies, aiming to avoid unnecessary computation. The optimization is terminated when the statistical error of the objective function (e.g., cross-validation error) exceeds the room left for optimization (i.e., the estimated potential for improvement). The mechanism is described in the following papers: A. Makarova et al. Automatic termination for hyperparameter optimization. <https://proceedings.mlr.press/v188/makarova22a.html>__ H. Ishibashi et al. A stopping criterion for Bayesian optimization by the gap of expected minimum simple regrets.

Terminator Improvement Plot

Class or Function Names plot_terminator_improvement Example from optuna.visualization import plot_terminator_improvement plot_terminator_improvement(study) Others See the documentation for more details.

Threshold Pruner

Class or Function Names ThresholdPruner Example study = create_study(pruner=ThresholdPruner(upper=1.0)) study.optimize(objective_for_upper, n_trials=10) study = create_study(pruner=ThresholdPruner(lower=0.0)) study.optimize(objective_for_lower, n_trials=10) See example.py for a full example. Others See the documentation for more details.

Timeline Plot

Class or Function Names plot_timeline Example from optuna.visualization import plot_timeline plot_timeline(study) Others See the documentation for more details.

TPE Sampler

Class or Function Names TPESampler Example import optuna from optuna.samplers import TPESampler def objective(trial): x = trial.suggest_float("x", -10, 10) return x**2 sampler = TPESampler() study = optuna.create_study(sampler=sampler) study.optimize(objective, n_trials=10) Others See the documentation for more details.

Trackio Callback

Installation pip install trackio Abstract This callback enables tracking of Optuna studies in Trackio. By default, the study is tracked as a single experiment run, where all suggested hyperparameters and optimized metrics are logged and visualized as a function of optimizer steps. Trackio is offline-first and does not require authentication for local experiment tracking. Optionally, tracked experiments can be synchronized to Hugging Face Spaces for remote visualization and sharing. The callback also supports multi-run mode, where each Optuna trial is tracked as an independent Trackio run.

Weights & Biases Callback

Abstract This callback enables tracking of Optuna study in Weights & Biases. The study is tracked as a single experiment run, where all suggested hyperparameters and optimized metrics are logged and plotted as a function of optimizer steps. APIs WeightsAndBiasesCallback(metric_name: str | Sequence[str] = "value", wandb_kwargs: dict[str, Any] | None = None, as_multirun: bool = False) metric_name: Name assigned to optimized metric. In case of multi-objective optimization, list of names can be passed.

Wilcoxon Pruner

Class or Function Names WilcoxonPruner Example study = optuna.create_study(pruner=optuna.pruners.WilcoxonPruner(p_threshold=0.1)) study.optimize(objective, n_trials=100) See example.py for a full example. Others See the documentation for more details.