optuna.storages¶
-
class
optuna.storages.RDBStorage(url: str, engine_kwargs: Optional[Dict[str, Any]] = None, skip_compatibility_check: bool = 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
Create an
RDBStorageinstance with customizedpool_sizeandtimeoutsettings.import optuna def objective(trial): x = trial.suggest_uniform('x', -100, 100) return x ** 2 storage = optuna.storages.RDBStorage( url='sqlite:///:memory:', engine_kwargs={ 'pool_size': 20, 'connect_args': { 'timeout': 10 } } ) study = optuna.create_study(storage=storage) study.optimize(objective, n_trials=10)
- Parameters
url – URL of the storage.
engine_kwargs – A dictionary of keyword arguments that is passed to sqlalchemy.engine.create_engine function.
skip_compatibility_check – Flag to skip schema compatibility check if set to True.
Note
If you use MySQL, pool_pre_ping will be set to
Trueby default to prevent connection timeout. You can turn it off withengine_kwargs['pool_pre_ping']=False, but it is recommended to keep the setting if execution time of your objective function is longer than the wait_timeout of your MySQL configuration.
-
class
optuna.storages.RedisStorage(url: str)[source]¶ Storage class for Redis 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
RedisStorageinstance using the given redis database URL.>>> import optuna >>> >>> def objective(trial): >>> ... >>> >>> storage = optuna.storages.RedisStorage( >>> url='redis://passwd@localhost:port/db', >>> ) >>> >>> study = optuna.create_study(storage=storage) >>> study.optimize(objective)
- Parameters
url – URL of the redis storage, password and db are optional. (ie: redis://localhost:6379)
Note
If you use plan to use Redis as a storage mechanism for optuna, make sure Redis in installed and running. Please execute
$ pip install -U redisto install redis python library.Note
Added in v1.4.0 as an experimental feature. The interface may change in newer versions without prior notice. See https://github.com/optuna/optuna/releases/tag/v1.4.0.