cleverly.assessment.AssessmentCache#

class cleverly.assessment.AssessmentCache(*args: Any, **kwargs: Any)[source]#

The assessment answers a result keeps, with an optional byte budget.

A plain mapping from a key (the operation and its normalized arguments) to the answer. With no budget, the default, every answer is kept for the life of the result and saved with it, as a mapping without this class would.

Some answers can be computed again exactly from the result’s stored artifacts: the support, nuisance and score diagnostics, the stored-artifact validation, the omitted-confounder elements and bounds, the E-value and the combined reports that hold them. Only those are evictable. An answer that refits nuisance models, draws a fresh random seed, fits a learner or runs a parallel section is pinned, because computing it again could give different numbers; neither a budget nor evict() removes it. A dropped answer is computed again, bit for bit the same, the next time it is asked for.

Parameters:
*argsAny

Passed to dict: a mapping or an iterable of key and answer pairs.

**kwargsAny

Passed to dict: answers by key.

Attributes:
max_bytesint or None

The budget on the whole cache, in bytes, or None for no budget (the default).

nbytesint

The bytes the filed answers are counted at.

pinned_nbytesint

The part of nbytes in answers that are never dropped.

Notes

The byte count walks each answer: arrays by their buffers, Python objects by their sizes. It stops at fitted learners, estimators, data containers and results, and counts an array an answer shares with the fitted result, so it can exceed what dropping the answer frees; the budget then drops answers early rather than keep more than it says. clear(), del and pop remove pinned answers too: a repeated unseeded refit then draws a new seed, as it always has after its answer is removed.

Methods#

AssessmentCache.clear() → None[source]#

Remove every answer, pinned ones included; the budget stays.

AssessmentCache.copy() → AssessmentCache[source]#

Return a copy with the same entries, budget and evictable keys.

Returns:
AssessmentCache

The copy, sharing the answers and no bookkeeping.

AssessmentCache.evict() → int[source]#

Drop every evictable answer, whatever the budget.

Returns:
int

The counted bytes of the dropped answers.

AssessmentCache.info() → tuple[CacheEntry, ...][source]#

Describe each filed answer, in the order the answers were filed.

Returns:
tuple of CacheEntry

One record per answer: its key, operation, counted bytes and whether a budget may drop it.

AssessmentCache.pop(key: str, *default: Any) → Any[source]#

Remove key and return its answer, as dict.pop() does.

Parameters:
keystr

The key to remove.

*defaultobject

The value to return when key is absent.

Returns:
object

The removed answer, or the default.

AssessmentCache.popitem() → tuple[str, Any][source]#

Remove and return the last filed answer, as dict.popitem() does.

Returns:
tuple

The key and its answer.

Attributes#

AssessmentCache.max_bytes#

The budget on the whole cache, in bytes, or None for no budget (the default).

A positive integer bounds nbytes, pinned answers included: after each filing, and at once when it is set, evictable answers are dropped, least recently used first, until the total fits or no evictable answer is left. Pinned answers alone can exceed it. It is not a memory guard: None means no budget, not the memory available now.

AssessmentCache.nbytes#

The bytes the filed answers are counted at.

AssessmentCache.pinned_nbytes#

The part of nbytes in answers that are never dropped.