Getting AttributeError when running optuna study

153 views Asked by At

I am trying to run optimization using optuna:

study = optuna.create_study(direction='minimize', sampler=optuna.samplers.GridSampler(search_space))
study.optimize(objective, n_trials=20)

For which I am getting below error:

AttributeError: module optuna.samplers has no attribute GridSampler

optuna version is 0.10.0

Could someone please help me on how to fix this issue.

1

There are 1 answers

11
Talha Tayyab On BEST ANSWER

I tried to reproduce your example:

pip install optuna==0.10.0

Then:

print(dir(optuna.samplers))

#output
['BaseSampler',
 'RandomSampler',
 'TPESampler',
 '__builtins__',
 '__cached__',
 '__doc__',
 '__file__',
 '__loader__',
 '__name__',
 '__package__',
 '__path__',
 '__spec__',
 'base',
 'random',
 'tpe']

I see that we do not have GridSampler

You need to upgrade your optuna

optuna.samplers.GridSampler


pip install optuna --upgrade

#Successfully installed optuna-3.4.0

Now,

print(dir(optuna.samplers))

#output
['BaseSampler',
 'BruteForceSampler',
 'CmaEsSampler',
 'GridSampler',
 'IntersectionSearchSpace',
 'MOTPESampler',
 'NSGAIIISampler',
 'NSGAIISampler',
 'PartialFixedSampler',
 'QMCSampler',
 'RandomSampler',
 'TPESampler',
 '__all__',
 '__builtins__',
 '__cached__',
 '__doc__',
 '__file__',
 '__loader__',
 '__name__',
 '__package__',
 '__path__',
 '__spec__',
 '_base',
 '_brute_force',
 '_cmaes',
 '_grid',
 '_lazy_random_state',
 '_nsgaiii',
 '_partial_fixed',
 '_qmc',
 '_random',
 '_search_space',
 '_tpe',
 'intersection_search_space',
 'nsgaii']