schrodinger.application.matsci.cache module¶
Module with functions related to caching.
Copyright Schrodinger, LLC. All rights reserved.
- class schrodinger.application.matsci.cache.CacheInfo(hit, miss, maxsize, currsize)¶
Bases:
tuple
- __contains__(key, /)¶
Return key in self.
- __len__()¶
Return len(self).
- count(value, /)¶
Return number of occurrences of value.
- currsize¶
Alias for field number 3
- hit¶
Alias for field number 0
- index(value, start=0, stop=9223372036854775807, /)¶
Return first index of value.
Raises ValueError if the value is not present.
- maxsize¶
Alias for field number 2
- miss¶
Alias for field number 1
- class schrodinger.application.matsci.cache.readonly_cached_property(func)¶
Bases:
functools.cached_property
A cached property that cannot be set or deleted
- __init__(func)¶
- class schrodinger.application.matsci.cache.frozenset_cached_property(func)¶
Bases:
functools.cached_property
A cached property that automatically converts the property into a frozenset. Useful for ensuring that a
set
property is immutable.- __init__(func)¶
- schrodinger.application.matsci.cache.get_bound_cache(bound_func)¶
Gets the bound cache data associate with the bound method
- Parameters
bound_func (function) – The bound function
- Returns
Cache data associated with the bound method
- Return type
- class schrodinger.application.matsci.cache.BaseCacheData(maxsize=10000, *args, **kwargs)¶
Bases:
collections.OrderedDict
Base limited size dictionary used for storing data
- __init__(maxsize=10000, *args, **kwargs)¶
Constructs a new BaseCacheData
- Parameters
maxsize (int) – The maxsize for the dictionary. The base class does not enforce the maxsize. The subclass needs to implement the size-limiting behavior.
- property info¶
Get the cache data usage information
- Return type
- Returns
Information for cache data usage
- clear()¶
Clears the cache data
- __contains__(key, /)¶
True if the dictionary has the specified key, else False.
- __len__()¶
Return len(self).
- copy() a shallow copy of od ¶
- fromkeys(value=None)¶
Create a new ordered dictionary with keys from iterable and values set to value.
- get(key, default=None, /)¶
Return the value for key if key is in the dictionary, else default.
- items() a set-like object providing a view on D’s items ¶
- keys() a set-like object providing a view on D’s keys ¶
- move_to_end(key, last=True)¶
Move an existing element to the end (or beginning if last is false).
Raise KeyError if the element does not exist.
- pop(k[, d]) v, remove specified key and return the corresponding ¶
value. If key is not found, d is returned if given, otherwise KeyError is raised.
- popitem(last=True)¶
Remove and return a (key, value) pair from the dictionary.
Pairs are returned in LIFO order if last is true or FIFO order if false.
- setdefault(key, default=None)¶
Insert key with a value of default if key is not in the dictionary.
Return the value for key if key is in the dictionary, else default.
- update([E, ]**F) None. Update D from dict/iterable E and F. ¶
If E is present and has a .keys() method, then does: for k in E: D[k] = E[k] If E is present and lacks a .keys() method, then does: for k, v in E: D[k] = v In either case, this is followed by: for k in F: D[k] = F[k]
- values() an object providing a view on D’s values ¶
- class schrodinger.application.matsci.cache.LRUCacheData(maxsize=10000, *args, **kwargs)¶
Bases:
schrodinger.application.matsci.cache.BaseCacheData
Limited size dictionary where least-recently-accessed key in is removed first when the maxsize is reached
- __contains__(key, /)¶
True if the dictionary has the specified key, else False.
- __init__(maxsize=10000, *args, **kwargs)¶
Constructs a new BaseCacheData
- Parameters
maxsize (int) – The maxsize for the dictionary. The base class does not enforce the maxsize. The subclass needs to implement the size-limiting behavior.
- __len__()¶
Return len(self).
- clear()¶
Clears the cache data
- copy() a shallow copy of od ¶
- fromkeys(value=None)¶
Create a new ordered dictionary with keys from iterable and values set to value.
- get(key, default=None, /)¶
Return the value for key if key is in the dictionary, else default.
- property info¶
Get the cache data usage information
- Return type
- Returns
Information for cache data usage
- items() a set-like object providing a view on D’s items ¶
- keys() a set-like object providing a view on D’s keys ¶
- move_to_end(key, last=True)¶
Move an existing element to the end (or beginning if last is false).
Raise KeyError if the element does not exist.
- pop(k[, d]) v, remove specified key and return the corresponding ¶
value. If key is not found, d is returned if given, otherwise KeyError is raised.
- popitem(last=True)¶
Remove and return a (key, value) pair from the dictionary.
Pairs are returned in LIFO order if last is true or FIFO order if false.
- setdefault(key, default=None)¶
Insert key with a value of default if key is not in the dictionary.
Return the value for key if key is in the dictionary, else default.
- update([E, ]**F) None. Update D from dict/iterable E and F. ¶
If E is present and has a .keys() method, then does: for k in E: D[k] = E[k] If E is present and lacks a .keys() method, then does: for k, v in E: D[k] = v In either case, this is followed by: for k in F: D[k] = F[k]
- values() an object providing a view on D’s values ¶
- class schrodinger.application.matsci.cache.FIFOCacheData(maxsize=10000, *args, **kwargs)¶
Bases:
schrodinger.application.matsci.cache.BaseCacheData
Limited size dictionary where first key in is removed first when the maxsize is reached
- __contains__(key, /)¶
True if the dictionary has the specified key, else False.
- __init__(maxsize=10000, *args, **kwargs)¶
Constructs a new BaseCacheData
- Parameters
maxsize (int) – The maxsize for the dictionary. The base class does not enforce the maxsize. The subclass needs to implement the size-limiting behavior.
- __len__()¶
Return len(self).
- clear()¶
Clears the cache data
- copy() a shallow copy of od ¶
- fromkeys(value=None)¶
Create a new ordered dictionary with keys from iterable and values set to value.
- get(key, default=None, /)¶
Return the value for key if key is in the dictionary, else default.
- property info¶
Get the cache data usage information
- Return type
- Returns
Information for cache data usage
- items() a set-like object providing a view on D’s items ¶
- keys() a set-like object providing a view on D’s keys ¶
- move_to_end(key, last=True)¶
Move an existing element to the end (or beginning if last is false).
Raise KeyError if the element does not exist.
- pop(k[, d]) v, remove specified key and return the corresponding ¶
value. If key is not found, d is returned if given, otherwise KeyError is raised.
- popitem(last=True)¶
Remove and return a (key, value) pair from the dictionary.
Pairs are returned in LIFO order if last is true or FIFO order if false.
- setdefault(key, default=None)¶
Insert key with a value of default if key is not in the dictionary.
Return the value for key if key is in the dictionary, else default.
- update([E, ]**F) None. Update D from dict/iterable E and F. ¶
If E is present and has a .keys() method, then does: for k in E: D[k] = E[k] If E is present and lacks a .keys() method, then does: for k, v in E: D[k] = v In either case, this is followed by: for k in F: D[k] = F[k]
- values() an object providing a view on D’s values ¶
- schrodinger.application.matsci.cache.memoized_method(cache_type=<class 'schrodinger.application.matsci.cache.FIFOCacheData'>, maxsize=10000)¶
Decorator for class methods that have weak reference to the self. This is a replacement for functools.lru_cache that works for class methods but not functions. Note like functools.lru_cache the values for the arguments of the method should be hashable.
- Parameters
cache_type (BaseCacheData) – The cache data type
maxsize (int) – The maximum size of the cache