Skip to main content

Persistent memoization by parameter identity for experiment scripts

Project description

stet

A Python library for making parameter sweeps safely resumable.

When a long-running experiment script is re-run — whether after a crash, a time limit, or deliberately to extend a sweep — stet automatically skips any parameter combinations that have already been completed.

import stet

@stet.once(store='markov_runs.csv', key=['alpha', 'n_states', 'seed'])
def solve_markov(alpha, n_states, seed, n_iter=10_000):
    # expensive computation
    ...

for alpha in alphas:
    for n_states in [10, 50, 100]:
        for seed in range(20):
            solve_markov(alpha=alpha, n_states=n_states, seed=seed)

On restart, any already-completed (alpha, n_states, seed) combinations are skipped:

[once] Skipping solve_markov(alpha=0.01, n_states=10, seed=0)
[once] Skipping solve_markov(alpha=0.01, n_states=10, seed=1)
...

Installation

uv add stet
# or: python -m pip install stet

With Parquet support:

uv add stet[parquet]
# or: python -m pip install stet[parquet]

Usage

Zero config — uses _stet_store.csv in the current directory, all parameters as the key:

@stet.once
def run_experiment(alpha, seed):
    ...

Named store — backend selected from file extension (.csv, .json, .sqlite, .parquet):

@stet.once(store='runs.sqlite')
def run_experiment(alpha, seed):
    ...

Key subset — only alpha and seed determine whether a run is skipped; n_iter is ignored:

@stet.once(store='runs.csv', key=['alpha', 'seed'])
def run_experiment(alpha, seed, n_iter=1000):
    ...

Utilities

stet.status()            # print a summary of completed runs
stet.reset()             # clear the store
stet.reset(key_dict={'alpha': '0.1', 'seed': '42'})  # remove one entry

Storage backends

Extension Backend Notes
.csv pandas CSV Default. Human-readable.
.json stdlib json No extra dependencies.
.sqlite stdlib sqlite3 Best for large stores and parallel workers.
.parquet pandas + pyarrow Requires stet[parquet].

Documentation

Full documentation including how-to guides, API reference, and explanation of design decisions:

uv run mkdocs serve

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

stet-0.0.1.tar.gz (144.6 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

stet-0.0.1-py3-none-any.whl (12.8 kB view details)

Uploaded Python 3

File details

Details for the file stet-0.0.1.tar.gz.

File metadata

  • Download URL: stet-0.0.1.tar.gz
  • Upload date:
  • Size: 144.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.7.13

File hashes

Hashes for stet-0.0.1.tar.gz
Algorithm Hash digest
SHA256 8596809940d563b16fc90202e0d7256a3e1df2ed0b9a9b2252381482c4a033d4
MD5 5ecd25467f477a197b454d94d877554e
BLAKE2b-256 a6dab4eb0e692533054501c6dae01433ef9a87e16ccebba4c7d7cc532c9f133d

See more details on using hashes here.

File details

Details for the file stet-0.0.1-py3-none-any.whl.

File metadata

  • Download URL: stet-0.0.1-py3-none-any.whl
  • Upload date:
  • Size: 12.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.7.13

File hashes

Hashes for stet-0.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 8dbfa09d314efb13135ba78e107569422a5e58467e67683414787f381cda6a2e
MD5 33799dff3d2402c509611ba2477caf90
BLAKE2b-256 4a142291fe633bcbb74d1df03ba0554433eb000bebbd09047d59d1486af5ff90

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page