feat: add Storage trait and JSONL journal backend

Replace the internal Vec<CompletedTrial<V>> with a pluggable Storage<V>
trait. MemoryStorage is the default (no behavior change for existing
users). Behind the `journal` feature flag, JournalStorage persists
trials to a JSONL file with fs2 file locking for multi-process safety.

- Storage<V> trait with push(), trials_arc(), refresh() methods
- MemoryStorage<V> wraps Arc<RwLock<Vec<CompletedTrial<V>>>>
- JournalStorage<V> appends JSON lines with exclusive file locks
- Study::with_sampler_and_storage() general constructor
- Study::with_journal() convenience constructor (journal feature)
- Refresh from storage on create_trial() for multi-process discovery
- MSRV bumped to 1.89
This commit is contained in:
Manuel Raimann
2026-02-11 22:58:38 +01:00
parent 24a0bdd473
commit 0a6f2345a8
10 changed files with 657 additions and 66 deletions
+7 -1
View File
@@ -5,7 +5,7 @@ members = ["optimizer-derive"]
name = "optimizer"
version = "0.8.1"
edition = "2024"
rust-version = "1.88"
rust-version = "1.89"
license = "MIT"
authors = ["Manuel Raimann <raimannma@outlook.de"]
description = "A Rust library for optimization algorithms."
@@ -26,12 +26,14 @@ serde_json = { version = "1", optional = true }
tracing = { version = "0.1.29", optional = true }
sobol_burley = { version = "0.5", optional = true }
nalgebra = { version = "0.34", optional = true }
fs2 = { version = "0.4", optional = true }
[features]
default = []
async = ["dep:tokio"]
derive = ["dep:optimizer-derive"]
serde = ["dep:serde", "dep:serde_json"]
journal = ["dep:fs2", "serde"]
tracing = ["dep:tracing"]
sobol = ["dep:sobol_burley"]
cma-es = ["dep:nalgebra"]
@@ -71,3 +73,7 @@ required-features = ["derive"]
name = "visualization_demo"
path = "examples/visualization_demo.rs"
required-features = ["visualization"]
[[test]]
name = "journal_tests"
required-features = ["journal"]