Storages

class optuna.storages.RDBStorage(url, engine_kwargs=None, enable_cache=True, skip_compatibility_check=False)[source]

Storage class for RDB backend.

Note that library users can instantiate this class, but the attributes provided by this class are not supposed to be directly accessed by them.

Example

We create an RDBStorage instance with customized pool_size and max_overflow settings.

>>> import optuna
>>>
>>> def objective(trial):
>>>     ...
>>>
>>> storage = optuna.storages.RDBStorage(
>>>     url='postgresql://foo@localhost/db',
>>>     engine_kwargs={
>>>         'pool_size': 20,
>>>         'max_overflow': 0
>>>     }
>>> )
>>>
>>> study = optuna.create_study(storage=storage)
>>> study.optimize(objective)
Parameters:
  • url – URL of the storage.
  • engine_kwargs – A dictionary of keyword arguments that is passed to sqlalchemy.engine.create_engine function.
  • enable_cache – Flag to control whether to enable storage layer caching. If this flag is set to True (the default), the finished trials are cached on memory and never re-fetched from the storage. Otherwise, the trials are fetched from the storage whenever they are needed.