Table of Contents

Class StorageFunctions

Namespace
OptunaSharp.Storages
Assembly
OptunaSharp.dll

Module-level functions of optuna/storages/init.py.

public static class StorageFunctions
Inheritance
StorageFunctions
Inherited Members

Methods

GetStorage(BaseStorage?)

Python optuna.storages.get_storage — only for internal usage. It might be deprecated in the future.

null maps to a fresh InMemoryStorage. An RDB-style backend (any ICachedStorageBackend, e.g. the Tier X OptunaSharp.Storage.Sqlite RDBStorage) is wrapped in a CachedStorage — mirroring Python's get_storage, which returns _CachedStorage(RDBStorage(...)). Everything else (in-memory, journal, an already-wrapped cache) is returned as-is.

public static BaseStorage GetStorage(BaseStorage? storage)

Parameters

storage BaseStorage

Storage backend holding study and trial records.

Returns

BaseStorage

A fresh in-memory backend for null, an RDB cache wrapper, or the supplied storage instance.

GetStorage(string)

Python optuna.storages.get_storage for a storage URL: opens the RDB storage the URL names and wraps it in a CachedStorage, exactly as Python returns _CachedStorage(RDBStorage(url)). sqlite:///… URLs open through the OptunaSharp.Storage.Sqlite package, and postgresql://…, mysql://… and mariadb://… URLs through OptunaSharp.Storage.EFCore. The application must reference the package that serves the URL's dialect; Core finds it by name.

public static BaseStorage GetStorage(string storageUrl)

Parameters

storageUrl string

A SQLAlchemy-style storage URL such as sqlite:///study.db or postgresql://user:password@host:5432/optuna. null gives a fresh InMemoryStorage, as Python's None does, so a storage URL read from an unset environment variable behaves as in Python.

Returns

BaseStorage

A CachedStorage over the newly opened RDB storage, or an in-memory storage for null.

Remarks

The storage package's constructor runs with its defaults, so anything it throws for this URL (an unreachable server, an incompatible schema version) propagates unchanged.

Footgun: like Python's, the returned cache does not own the storage it wraps, so nothing ever disposes the database connection. A long-running process that calls this repeatedly keeps every connection open; dispose ((CachedStorage)storage).Backend when done, or construct the package's RDBStorage in a using and pass that instead. Python marks this function "only for internal usage".

Exceptions

ValueError

The URL starts with redis: Optuna removed RedisStorage in v3.1.0 (use a Redis journal backend).

ArgumentException

The URL does not start with name:// (for example a bare file path), or it names a dialect SQLAlchemy does not know (for example postgres). The messages are SQLAlchemy's.

NotSupportedException

No OptunaSharp package serves the URL's dialect (oracle, mssql), or the application does not reference the package that does. The message starts with Optuna's ImportError text.