2.27.2.5. pycsamt.pipeline._cache#
Content-addressed disk cache for pipeline step outputs.
A cache hit for step i requires the exact same fingerprint of the sites
flowing into it, the exact same step code, and the exact same params as a
previous run — a Make/Docker-layer-style chain hash. This is what makes a
crashed-and-rerun Pipeline.run(..., cache=True) call “resume”: every
already-completed step replays from cache instead of recomputing, and only
the step that was interrupted (and anything after it) actually runs.
Deliberately simpler than pycsamt.forward.maxwell.cache.MaxwellResultCache
— no cross-process locking, no size-based eviction. This is a disposable,
regeneratable local cache, not scientifically load-bearing output, so that
extra complexity isn’t worth it here. See Caching And Resume
for the caveats this implies (non-deterministic steps are not safe to cache).
Functions
|
sha256 of (upstream fingerprint, step code, normalized params). |
|
|
|
Deterministic content hash of a Sites-like collection. |
Classes
|
Sharded, content-addressed disk cache for pipeline step outputs. |
- class pycsamt.pipeline._cache.StepCache(root=None)[source]
Bases:
objectSharded, content-addressed disk cache for pipeline step outputs.
Layout:
root/<key[:2]>/<key>.joblib. Writes are atomic (temp file in the same directory, thenos.replace), so a killed process never leaves a half-written entry visible. A corrupt or unreadable entry is treated as a miss — warns, never crashes the run — the same “one bad entry must not break everything else” principlepycsamt.pipeline.discover_plugins()already established.- Parameters:
root (str | Path | None)
- get(key)[source]
Return the cached value for key, or the
_MISSsentinel.
- put(key, value)[source]
Atomically store value under key.
- clear()[source]
Remove every entry (and the root directory itself) from disk.
- Return type:
None
- pycsamt.pipeline._cache.fingerprint_sites(sites)[source]
Deterministic content hash of a Sites-like collection.
Tries the real
Sitesshape first — iterates stations, hashing each one’s name plus itsfreq/zarrays, in iteration order. Order is part of the fingerprint on purpose: under-caching on a harmless reorder is a safer failure mode than treating two differently-ordered (and potentially differently-behaving) inputs as identical.Falls back to hashing the pickled object for anything that doesn’t match that shape (plain test doubles, custom plugin-defined sites-like objects) — this keeps the cache usable without special-casing every possible “sites” representation.
- pycsamt.pipeline._cache.chain_key(upstream_fp, code, params)[source]
sha256 of (upstream fingerprint, step code, normalized params).
default=strin the JSON dump means an unhashable/odd param type (a callable, a numpy array) never raises — it just gets stringified, which is deterministic even if imperfect (two different objects with identicalreprwould collide). Documented, not silently hidden.