ledgr_sweep_save() persists a compact saved-sweep artifact in the
snapshot's experiment store. Saved sweeps are candidate evidence, not
committed runs: they store scalar candidate rows and retained return rows
when present, but not ledgers, fills, trades, or per-instrument artifacts.
Promotion from a reopened saved sweep re-executes the selected candidate from
its reproduction key against the sealed snapshot.
Usage
ledgr_sweep_save(sweep, snapshot, sweep_id = NULL, note = NULL)
ledgr_sweep_open(snapshot, sweep_id)
ledgr_sweep_list(snapshot)
ledgr_sweep_info(x)Value
The saved sweep_id, invisibly.
ledgr_sweep_open() returns a ledgr_sweep_results-compatible
tibble.
ledgr_sweep_list() returns a tibble with one row per saved sweep.
ledgr_sweep_info() returns a classed named list.
Functions
ledgr_sweep_open(): Reopen a compact saved sweep from the snapshot experiment store.ledgr_sweep_list(): List saved sweeps in a snapshot experiment store.ledgr_sweep_info(): Inspect in-memory or reopened sweep metadata.
Examples
bars <- data.frame(
instrument_id = "AAA",
ts_utc = as.POSIXct("2020-01-01", tz = "UTC") + 86400 * 0:4,
open = c(10, 11, 12, 11, 13),
high = c(11, 12, 13, 12, 14),
low = c(9, 10, 11, 10, 12),
close = c(10, 11, 12, 11, 13),
volume = 1000
)
snapshot <- ledgr_snapshot_from_df(bars, db_path = tempfile(fileext = ".duckdb"))
strategy <- function(ctx, params) {
targets <- ctx$flat()
targets["AAA"] <- params$qty
targets
}
exp <- ledgr_experiment(snapshot, strategy, cost_model = ledgr_cost_zero())
grid <- ledgr_param_grid(flat = list(qty = 0), long = list(qty = 1))
sweep <- ledgr_sweep(exp, grid, retain = ledgr_sweep_retention("completed"))
saved_id <- ledgr_sweep_save(sweep, snapshot, sweep_id = "example_sweep")
ledgr_sweep_list(snapshot)
#> # ledgr saved sweep list
#> # A tibble: 1 × 7
#> sweep_id created_at_utc sweep_schema_version n_candidates n_completed
#> <chr> <dttm> <int> <int> <int>
#> 1 example_swe… 2026-06-16 14:49:09 2 2 2
#> # ℹ 2 more variables: retention_returns <chr>, note <chr>
#>
#> # i Open one saved sweep with ledgr_sweep_open(snapshot, sweep_id).
reopened <- ledgr_sweep_open(snapshot, saved_id)
ledgr_sweep_info(reopened)
#> ledgr Sweep Info
#> ================
#>
#> Sweep ID: example_sweep
#> Snapshot: snapshot_20260616_144908_6750
#> Snapshot Hash: cd3b984aa8c195bc4fabebe73a474c45290ab34e244abd97f8bd25b98d4082b0
#> Candidates: 2
#> Completed: 2
#> Failed: 0
#> Retention returns: completed
#> Cost Model Hash: 4011132b5979fc370e524ebbc525ac7f4158b4de43639ec985f4c90969b4b9d0
#> Metric Hash: 794b69bd7f9c704447d4b0208b8420cdf132ec7bd6582eaa037bf1066133c1bb
#> Feature Union: 0a88f6f723b5489a2ceb2496a0031cb4bc8ddb15be59bb362c4c13f72e81d5d4
#>
#> Saved artifact
#> Created At: 2026-06-16 14:49:09.292216
#> Schema Version: 2
#> Engine Version: 0.1.9.6
#> Note: NA
ledgr_sweep_returns(reopened)
#> # A tibble: 10 × 5
#> sweep_id candidate_id ts_utc equity period_return
#> <chr> <chr> <dttm> <dbl> <dbl>
#> 1 example_sweep flat 2020-01-01 00:00:00 100000 NA
#> 2 example_sweep flat 2020-01-02 00:00:00 100000 0
#> 3 example_sweep flat 2020-01-03 00:00:00 100000 0
#> 4 example_sweep flat 2020-01-04 00:00:00 100000 0
#> 5 example_sweep flat 2020-01-05 00:00:00 100000 0
#> 6 example_sweep long 2020-01-01 00:00:00 100000 NA
#> 7 example_sweep long 2020-01-02 00:00:00 100000 0
#> 8 example_sweep long 2020-01-03 00:00:00 100001 0.0000100
#> 9 example_sweep long 2020-01-04 00:00:00 100000 -0.00001000
#> 10 example_sweep long 2020-01-05 00:00:00 100002 0.0000200
ledgr_snapshot_close(snapshot)