feat: add SQLite storage backend for multi-process optimization

This commit is contained in:
Manuel Raimann
2026-02-11 23:21:47 +01:00
parent ed1e9e31da
commit ed80c59795
7 changed files with 423 additions and 3 deletions
+28
View File
@@ -2355,6 +2355,34 @@ where
}
}
#[cfg(feature = "sqlite")]
impl<V> Study<V>
where
V: PartialOrd + Send + Sync + serde::Serialize + serde::de::DeserializeOwned + 'static,
{
/// Creates a study backed by a `SQLite` database.
///
/// Any existing trials in the database are loaded into memory and
/// the trial ID counter is set to one past the highest stored ID.
/// New trials are written through to the database on completion.
///
/// Uses WAL mode for concurrent readers, making it suitable for
/// single-machine multi-process optimization.
///
/// # Errors
///
/// Returns a [`Storage`](crate::Error::Storage) error if the
/// database cannot be opened.
pub fn with_sqlite(
direction: Direction,
sampler: impl Sampler + 'static,
path: impl AsRef<std::path::Path>,
) -> crate::Result<Self> {
let storage = crate::storage::SqliteStorage::<V>::new(path)?;
Ok(Self::with_sampler_and_storage(direction, sampler, storage))
}
}
impl Study<f64> {
/// Generates an HTML report with interactive Plotly.js charts.
///