Namespace OptunaSharp.Storages
Classes
- BaseHeartbeatThread
Python
BaseHeartbeatThread(context manager → IDisposable).
- BaseStorage
Base class for storages. Port of
optuna/storages/_base.py: BaseStorage.This class is not supposed to be directly accessed by library users. It abstracts a backend database and provides internal interfaces to read/write histories of studies and trials.
Thread safety — a storage class instance can be shared among multiple threads, and must therefore be thread-safe. It must guarantee that a data instance read from the storage must not be modified by subsequent writes: a FrozenTrial returned by GetTrial(int) should not be updated by subsequent
SetTrial...calls. This is usually achieved by replacing the old data with a copy on write.Ownership of RUNNING trials — trials in finished states are not allowed to be modified; trials in the WAITING state are not allowed to be modified except for the state field.
- CachedStorage
A wrapper class of storage backends. Port of
optuna/storages/_cached_storage.py: _CachedStorage(public in C# so the satellite RDB packages can compose with it).Data persistence — this class does not guarantee that write operations are logged into a persistent storage, even when write methods succeed. Thus, when process failure occurs, some writes might be lost. As exceptions, when a persistent storage is available, any writes on any attributes of Study and writes on state of Trial are guaranteed to be persistent. Additionally, any preceding writes on any attributes of Trial are guaranteed to be written into a persistent storage before writes on state of Trial succeed. The same applies for param, user_attrs, system_attrs and intermediate_values attributes.
- HeartbeatHelpers
Module-level functions of
optuna/storages/_heartbeat.py.
- HeartbeatThread
Background thread that records liveness until the owning optimization scope ends.
- InMemoryStorage
Storage class that stores data in memory of the current process. Port of
optuna/storages/_in_memory.py: InMemoryStorage.
- NullHeartbeatThread
No-op heartbeat worker used when the storage has heartbeats disabled.
- RetryFailedTrialCallback
Deprecated alias of RetryHeartbeatStaleTrialCallback.
- RetryHeartbeatStaleTrialCallback
Retry a heartbeat-stale trial up to a maximum number of times. Port of
optuna/storages/_callbacks.py: RetryHeartbeatStaleTrialCallback(experimental since 2.8.0).When a running trial becomes stale due to the heartbeat mechanism, this callback can be used with a storage class to recreate the trial in Waiting to queue up the trial to be run again.
The original stale trial can be identified by RetriedTrialNumber(FrozenTrial). Even if repetitive failure occurs (a retried trial becomes stale again), this method returns the number of the original trial. To get a full list including the numbers of the retried trials as well as their original trial, call RetryHistory(FrozenTrial).
- StorageFunctions
Module-level functions of
optuna/storages/init.py.
- TrialsPrefixView
A zero-copy, fixed-length window over the first Count trials of a study's live trial list — what GetTrialsPrefixView(int) returns. Constructing one is O(1) where
GetAllTrials(deepcopy: false)is O(N) (it copies the list), which is the difference between a linear and a quadratic optimization loop for samplers that consult history on every ask.
Interfaces
- IBaseHeartbeat
Base interface for heartbeat. Port of
optuna/storages/_heartbeat.py: BaseHeartbeat(a mixin class in Python; an interface in C# so storage backends can combine it with BaseStorage).The heartbeat mechanism periodically checks whether each trial process is alive during an optimization loop.
- ICachedStorageBackend
The backend contract CachedStorage wraps — the internal RDBStorage surface it drives in Python (
_create_new_trial,_set_trial_param,_get_best_trial_id,_get_trials). The Tier XOptunaSharp.Storage.Sqlite/EFCoreRDB storages implement this (PORTING_PLAN 4.1/4.2); the wrapper itself is Tier N because the read-through cache logic is reused there unchanged.