Skip to main content

pymc-cache

Safe, model-aware caching of native PyMC sampling results. Python 3.11+, PyMC 5.28–6 and ArviZ 0.x–1.x. No cloud account, monitoring service or Modal dependency.

pip install 'pymc-cache @ git+https://github.com/justmytwospence/pymc-cache.git@<commit-sha>'
import pymc as pm
import pymc_cache as pc

with pm.Model() as model:
    mu = pm.Normal("mu", 0, 1)
    options = dict(draws=10, tune=10, chains=1, cores=1, random_seed=42,
                   progressbar=False, model=model, cache="disk")
    trace = pc.sample(**options)
    # The next call loads the result from .pymc-cache/ without sampling:
    again = pc.sample(**options)

pc.sample_smc(model=model, draws=100, cache="disk") uses the native SMC sampler with an independent key. cache=True (default) uses an 8-entry in-memory LRU. cache=False runs the native sampler without hashing the model. Pass a directory/Path for a custom disk location; overwrite=True skips reads and atomically replaces an existing entry. Both backends copy results on read; memory copies on write too. Disk files are one NetCDF file per full SHA-256 key, with the key embedded in its metadata. Corruption is treated as a miss. pc.cleanup_cache() removes only entries owned by this package; pymc-cache list|prune|clear --dir PATH inspects/manages the same entries without following symlinks.

Preflight and integrations

session = pc.CacheSession(cache="disk", model=model)
lookup = session.lookup({"draws": 10, "tune": 10, "chains": 1,
                         "cores": 1, "random_seed": 42, "progressbar": False})
if lookup.hit:
    trace = lookup.result
else:
    trace = pm.sample(model=model, **lookup.normalized_kwargs)
    session.store(lookup, trace, status="complete")

A runner used with pc.sample(..., sample_fn=runner) must implement runner.__pymc_cache_normalize__(model, call_kwargs) and return exactly call_kwargs, key_kwargs, sampler_identity, and versions. The call arguments passed to the runner and the canonical key arguments must be explicit. The runner returns an inference result; only complete results, or adaptive results with an attested met convergence report, are stored. Stopped, futile, capped and incomplete results are returned but never stored. Cache identity includes the complete model graph, constants, mutable shared data, deterministics, coordinates, sampling kwargs, RNG states, operation, sampler and software versions. Unknown/custom Ops fail closed rather than risk a wrong hit. Unsafe steps/callbacks/callables require an explicit sampler_key identifying their implementation and configuration; the caller is responsible for changing this key when the callable changes. No code is executed from cache metadata.

Caching may hold sensitive posterior data. Treat .pymc-cache/ as private, and use cache=False for confidential models when persistent data is not allowed. Cache files are not authenticated against a malicious writer; do not use a shared untrusted directory.

See getting started, caching walkthrough, identity guide, storage guide, monitor composition, legacy migration, troubleshooting, runnable examples, and API reference. This package does not patch pm.sample, intercept model contexts, cache posterior predictive calls or provide cloud execution.

Metadata

Release files for pymc-cache 0.1.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for pymc-cache 0.1.0
File Size Uploaded Provenance Actions
pymc_cache-0.1.0.tar.gz 39.5 kB With provenance Details for pymc_cache-0.1.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for pymc-cache 0.1.0
File Interpreter ABI Platform Actions
pymc_cache-0.1.0-py3-none-any.whl Python 3 none any Details for pymc_cache-0.1.0-py3-none-any.whl

Total release size: 61.3 kB

Release files / pymc_cache-0.1.0.tar.gz

Download URL pymc_cache-0.1.0.tar.gz
Size 39.5 kB
Tags Source
SHA-256 checksum
How to use checksums
ad896da1195f7c48fc0af2e8b117dfffe0f5ad91a2fc51158a38937aa53f5552
BLAKE2b-256 checksum
How to use checksums
35d17691ffbaa495b10713e467030aa7cbbb60c360da007b30f57953683af49f
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 3, 2026.

Transparency log

Release files / pymc_cache-0.1.0-py3-none-any.whl

Download URL pymc_cache-0.1.0-py3-none-any.whl
Size 21.8 kB
Tags Python 3
SHA-256 checksum
How to use checksums
616ec44e69462e705f1a1c0e1e17589e1cbbe9ee9b227271175eeff9be66d3fb
BLAKE2b-256 checksum
How to use checksums
4d137b7ede3036ae0f1709786fd298319f8869b762e1d169f9a597c7ea23ea17
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 3, 2026.

Transparency log

Security for pymc-cache 0.1.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

Full provenance

All 2 files in this release have been uploaded with provenance metadata.

Select from 2 files

Attestation for pymc_cache-0.1.0.tar.gz

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 3, 2026.

Transparency log

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

0.1.0 This release

2 release files Full provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page