pygsti.baseobjs.smartcache.SmartCache#
- class SmartCache(decorating=(None, None))#
Bases:
objectCache object that profiles itself
- Parameters:
decorating (tuple) – module and function being decorated by the smart cache
- StaticCacheList#
A list of all
SmartCacheinstances.- Type:
list
Construct a smart cache object
- Parameters:
decorating (tuple) – module and function being decorated by the smart cache
Methods
__init__([decorating])Construct a smart cache object
add_digest(custom)Add a "custom" digest function, used for hashing otherwise un-hashable types.
avg_timedict(d)Given a dictionary of lists of times (d), returns a dict of the summed times.
cached_compute(fn, arg_vals[, kwargs])Shows effectiveness of a cache
global_status(printer)Show the statuses of all Cache objects
low_overhead_cached_compute(fn, arg_vals[, ...])Cached compute with less profiling.
status(printer)Show the status of a cache object instance
Attributes
- add_digest(custom)#
Add a “custom” digest function, used for hashing otherwise un-hashable types.
- Parameters:
custom (function) – A hashing function, which takes two arguments: md5 (a running MD5 hash) and val (the value to be hashed). It should call md5.update to add to the running hash, and needn’t return anything.
- Return type:
None
- avg_timedict(d)#
Given a dictionary of lists of times (d), returns a dict of the summed times.
- Parameters:
d (dict) – A dictionary whose values are lists of times.
- Return type:
dict
- cached_compute(fn, arg_vals, kwargs=None)#
Shows effectiveness of a cache
- Parameters:
fn (function) – Cached function
arg_vals (tuple or list) – Arguments to cached function
kwargs (dictionary) – Keyword arguments to cached function
- Returns:
key (the key used to hash the function call)
result (result of fn called with arg_vals and kwargs)
- static global_status(printer)#
Show the statuses of all Cache objects
- Parameters:
printer (VerbosityPrinter) – The printer to use for output.
- Return type:
None
- low_overhead_cached_compute(fn, arg_vals, kwargs=None)#
Cached compute with less profiling. See
cached_compute()docstring.- Parameters:
fn (function) – Cached function
arg_vals (tuple or list) – Arguments to cached function
kwargs (dictionary) – Keyword arguments to cached function
- Returns:
key (the key used to hash the function call)
result (result of fn called with arg_vals and kwargs)
- status(printer)#
Show the status of a cache object instance
- Parameters:
printer (VerbosityPrinter) – The printer to use for output.
- Return type:
None