ConfigSampler

class ConfigSampler(configs: List[dict], random_generator: Optional[numpy.random._generator.Generator] = None, retries: int = 10)[source]

Bases: optuna.samplers._base.BaseSampler

Optuna based sampler for greedy search over different configurations.

Init Config sampler.

Parameters
  • configs (List[dict]) – pool of configs to sample from

  • random_generator (Optional[numpy.random._generator.Generator]) – numpy generator to get reproducible samples

  • retries (int) – number of retries to get new sample from storage. It could be useful if storage is not reliable.

Inherited-members

Methods

after_trial(study, trial, *args, **kwargs)

Stop study if all configs have been tested.

get_config_by_hash(hash)

Get config by hash.

infer_relative_search_space(*args, **kwargs)

Infer relative search space.

reseed_rng()

Reseed sampler's random number generator.

sample_independent(*args, **kwargs)

Sample independent.

sample_relative(study, trial, *args, **kwargs)

Sample configuration to test.

Attributes

rng

after_trial(study: optuna.study.study.Study, trial: optuna.trial._frozen.FrozenTrial, *args, **kwargs) None[source]

Stop study if all configs have been tested.

Parameters
  • study (optuna.study.study.Study) – current optuna study

  • trial (optuna.trial._frozen.FrozenTrial) –

Return type

None

get_config_by_hash(hash: str)[source]

Get config by hash.

Parameters

hash (str) – hash to get config for

infer_relative_search_space(*args, **kwargs)[source]

Infer relative search space. Not used.

reseed_rng() None

Reseed sampler’s random number generator.

This method is called by the Study instance if trials are executed in parallel with the option n_jobs>1. In that case, the sampler instance will be replicated including the state of the random number generator, and they may suggest the same values. To prevent this issue, this method assigns a different seed to each random number generator.

Return type

None

sample_independent(*args, **kwargs)[source]

Sample independent. Not used.

sample_relative(study: optuna.study.study.Study, trial: optuna.trial._frozen.FrozenTrial, *args, **kwargs) dict[source]

Sample configuration to test.

Parameters
  • study (optuna.study.study.Study) – current optuna study

  • trial (optuna.trial._frozen.FrozenTrial) – optuna trial to use

Returns

sampled configuration to run objective on

Return type

dict