qdk_chemistry.remote.cache.tiered module
Tiered (layered) cache backend for QDK/Chemistry.
Chains multiple cache backends in priority order so that reads hit the fastest / closest tier first and writes propagate to every tier.
Typical setup pairs a fast local cache with a shared network cache:
cache = TieredCache([
FolderCache("./cache"), # L1 — fast local
FolderCache("/shared/team_cache"), # L2 — shared
])
- Read path
Each tier is checked in order. On a hit in a slower tier the result is backfilled into all faster tiers so subsequent reads are local.
- Write path
Data is written to every tier (write-through).
- class qdk_chemistry.remote.cache.tiered.CacheBackend(*, is_shared=False)
Bases:
ABCAbstract base class for result caches.
Implementations must provide these operations:
get_jobandput_jobpersistJobmetadata by run hash.get_dataandput_datastore supported values by content hash.delete_jobanddelete_dataremove cached metadata or blobs.clearremoves all cache entries.
- Parameters:
is_shared (
bool) – Set toTruewhen the backing store is reachable from multiple machines (e.g. a network-mounted folder). Defaults toFalse.
- __init__(*, is_shared=False)
Initialise the cache backend.
- Parameters:
is_shared (bool)
- Return type:
None
- abstractmethod get_job(run_hash)
Retrieve job metadata by run_hash, or
Noneon miss.
- abstractmethod put_job(run_hash, job)
Store (or update) job metadata keyed by run_hash.
- abstractmethod get_data(content_hash)
Retrieve cached data by its content hash, or
None.
- abstractmethod put_data(content_hash, data, *, shared_only=False)
Store data by content hash, optionally requiring shared storage.
- abstractmethod delete_job(run_hash)
Remove job metadata by run_hash. Returns
Trueif it existed.
- abstractmethod delete_data(content_hash)
Remove a DataClass blob by content hash. Returns
Trueif it existed.
Whether this cache is reachable from both local and remote.
- has_data(content_hash, *, shared_only=False)
Check whether a DataClass blob exists without deserializing it.
The default implementation calls
get_data()and checks forNone. Backends that can answer this more cheaply (e.g. aHEADrequest or aglob) should override. When shared_only is true, non-shared backends always returnFalse.
- to_config()
Return constructor kwargs sufficient to recreate this backend.
Subclasses should override this if they accept configuration (paths, URLs, credentials, etc.). The default returns an empty dict, which is only valid for backends that need no arguments.
- Return type:
- for_remote()
Return the cache view reachable from a remote compute node.
- Return type:
- class qdk_chemistry.remote.cache.tiered.TieredCache(tiers, **_kwargs)[source]
Bases:
CacheBackendComposite cache that layers multiple backends.
- Parameters:
tiers (
list[CacheBackend|dict[str,Any]]) – Ordered list of cache backends, fastest first._kwargs (Any)
- Raises:
ValueError – If tiers is empty.
Example:
from qdk_chemistry.remote.cache import FolderCache, TieredCache cache = TieredCache([ FolderCache("./local_cache"), FolderCache("/shared/team_cache"), ]) energy, wfn = scf.run(mol, 0, 1, "cc-pvdz", cache=cache)
A tiered cache is shared if any of its tiers is shared.
- property tiers: list[CacheBackend][source]
Return a copy of the tier list.
- for_remote()[source]
Return a cache containing only tiers reachable from remote nodes.
- Return type:
- has_data(content_hash, *, shared_only=False)[source]
Return
Trueif any eligible tier contains the blob.