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_dir for filename. Optionally, enable match_hash to compare expected_hash with 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_hash

  • match_hash (bool) – flag whether the expected hash should be compared with the cached hash

Raises:
  • FileNotFoundError – if cache_dir doesn’t exist, or filename doesn’t exist within cache_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 data as filename in cache_dir. Attach an expected_hash that 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 ndarray data.

Returns: