EvaluatorCache#
- class pymc_marketing.mmm.evaluator_cache.EvaluatorCache(max_entries=4)[source]#
Bounded LRU cache of compiled counterfactual evaluators.
A fitted MMM keeps one so its
Incrementalityobjects reuse compiled evaluators, keyed by graph shape and dataset, so repeated questions pay one compile. The cache is bounded so a model cannot pin an unbounded number of compiled functions, and it is never serialized because compiled functions only make sense in-process. A request leases an evaluator for its duration:lease()takes the entry out of the cache and the request returns it in afinally. Concurrent requests on one model never share the shared draws an evaluator is rebound to – one of them misses the cache and compiles or leases its own – and no request waits on another. A lock guards only the dictionary bookkeeping, never an evaluation. An entry whose evaluator reads a source input replaced after its build is rebuilt rather than leased.- Parameters:
max_entries (
int) – Number of evaluators kept before the least recently used is evicted.
Methods
EvaluatorCache.__init__([max_entries])EvaluatorCache.get(key)Return the evaluator cached under
key, marking it most recent.EvaluatorCache.lease(key, factory)Take the evaluator cached under
key, building one on a miss.EvaluatorCache.put(key, evaluator)Store
evaluatorunderkey, evicting the least recent entry.