Abstract
This package automatically selects an appropriate sampler for the provided search space based on the developers’ recommendation. The following articles provide detailed information about AutoSampler.
- 📰 AutoSampler: Automatic Selection of Optimization Algorithms in Optuna
- 📰 AutoSampler: Full Support for Multi-Objective & Constrained Optimization

APIs
AutoSampler(*, seed: int | None = None, constraints_func: Callable[[FrozenTrial], Sequence[float]] | None = None)seed: Random seed to initialize internal random number generator. Defaults to None (a seed is picked randomly).constraints_func: An optional function that computes the objective constraints. It must take aFrozenTrialand return the constraints. The return value must be a sequence offloats. A value strictly larger than0means that a constraints is violated. A value equal to or smaller than0is considered feasible. Ifconstraints_funcreturns more than one value for a trial, that trial is considered feasible if and only if all values are equal to0or smaller. Theconstraints_funcwill be evaluated after each successful trial.
This sampler currently accepts only seed and constraints_func. These arguments follow the same convention as the other samplers, so please take a look at the reference.
Installation
This sampler requires optional dependencies of Optuna.
$ pip install optunahub cmaes torch scipy
Note that since we may update the implementation of AutoSampler, it is highly encouraged to use the latest version of Optuna.
Example
import optuna
import optunahub
def objective(trial):
x = trial.suggest_float("x", -5, 5)
y = trial.suggest_float("y", -5, 5)
return x**2 + y**2
module = optunahub.load_module(package="samplers/auto_sampler")
study = optuna.create_study(sampler=module.AutoSampler())
study.optimize(objective, n_trials=300)
Test
To execute the tests for AutoSampler, please run the following commands. The test file is provided in the package. Please use optuna>=4.8 to run the tests.
pip install pytest
pytest package/samplers/auto_sampler/tests/
- Package
- samplers/auto_sampler
- Author
- Optuna Team
- License
- MIT License
- Verified Optuna version
- 4.5.0
- Last update
- 2026-02-25
- Discussions & Issues
- Create a discussion
- Create a bug report