Optuna
Class resolvers for Optuna.
- pruner_resolver = <class_resolver.api.ClassResolver object>
A resolver for
optuna.pruners.BasePruner
subclasses.Building on the simple example from the Optuna website’s homepage, you can parametrize
optuna.create_study()
with a pruner instantiated withclass_resolver
.import optuna from class_resolver import Hint from class_resolver.contrib.optuna import pruner_resolver from optuna.pruner import BasePruner def objective(trial): x = trial.suggest_float('x', -10, 10) return (x - 2) ** 2 def optimize_study(pruner: Hint[BasePruner] = None): study = optuna.create_study( pruner=pruner_resolver.make(pruner), ) study.optimize(objective, n_trials=100) return study study = optimize_study(pruner="median") study.best_params # E.g. {'x': 2.002108042}
- sampler_resolver = <class_resolver.api.ClassResolver object>
A resolver for
optuna.samplers.BaseSampler
subclasses.Building on the simple example from the Optuna website’s homepage, you can parametrize
optuna.create_study()
with a sampler instantiated withclass_resolver
.import optuna from class_resolver import Hint from class_resolver.contrib.optuna import sampler_resolver from optuna.sampler import BaseSampler def objective(trial): x = trial.suggest_float('x', -10, 10) return (x - 2) ** 2 def optimize_study(sampler: Hint[BaseSampler] = None): study = optuna.create_study( sampler=sampler_resolver.make(sampler), ) study.optimize(objective, n_trials=100) return study study = optimize_study(sampler="TPE") study.best_params # E.g. {'x': 2.002108042}