Cache#
- simulation.cache.query_npz_from_cache(cache_dir: str, filename: str, expected_hash: str | None = None, match_hash: bool = True) Dict[str, ndarray][source]#
Query a NumPy Archive (.npz) from the cache, looking in
cache_dirforfilename. Optionally, enablematch_hashto compareexpected_hashwith the cached hash.- Parameters:
cache_dir (str) – the cache directory to be queried
filename (str) – the cached filename, should not include file extension “.npz”.
expected_hash (str) – the hash that will be matched with the cached hash to confirm data validity if
match_hashmatch_hash (bool) – flag whether the expected hash should be compared with the cached hash
- Raises:
FileNotFoundError – if
cache_dirdoesn’t exist, orfilenamedoesn’t exist withincache_dir.OSError – if the cache could not be loaded, indicating possible corruption
ValueError – if
match_hash, and the hashes do not match.
- Returns:
the cached data, as a dictionary of keys to ndarray.
- simulation.cache.store_npz_to_cache(cache_dir: str, filename: str, data: Dict[str, ndarray], hash: str)[source]#
Store
dataasfilenameincache_dir. Attach anexpected_hashthat can be used to ensure data validity.- Parameters:
cache_dir (str) – the cache directory for the data to be stored
filename (str) – the filename for the cache, should not include file extension “.npz”.
hash (str) – the hash that will be stored with the data
data (Dict[str, np.ndarray]) – dictionary of array names to the
ndarraydata.
- Returns: