Skip to main content

Module storage

Module storage 

Source
Expand description

Trial storage backends.

The Storage trait defines how completed trials are persisted and retrieved. Every Study owns an Arc<dyn Storage<V>> so storage is transparently shared across threads.

§Available backends

BackendDescriptionFeature flag
MemoryStorageIn-memory Vec behind a read-write lock (the default)
JournalStorageJSONL file with fs2 file locking for multi-process sharingjournal

§When to swap backends

The default MemoryStorage is sufficient for single-process studies where persistence is not needed. Switch to JournalStorage when you want to:

  • Resume a study after a process restart.
  • Share state across multiple processes writing to the same file.
  • Inspect trial history in a human-readable JSONL file.

§Implementing a custom backend

Implement the Storage trait to plug in your own backend (e.g. a database). The trait requires four methods: push, trials_arc, next_trial_id, and optionally refresh for external data sources.

Inject your storage into a study via the builder:

use optimizer::prelude::*;
use optimizer::storage::MemoryStorage;

let storage = MemoryStorage::<f64>::new();
let study = Study::builder().minimize().storage(storage).build();

Structs§

MemoryStorage
In-memory trial storage (the default).

Traits§

Storage
Trait for storing and retrieving completed trials.