Skip to content

archaeo_super_prompt.utils.cache

source module archaeo_super_prompt.utils.cache

Cache feature management.

Attributes

  • CacheIngestorFunction : The name of the arguments is important the output argument must be exactly named 'output'

Functions

source get_cache_dir_for(cache_subpart: CacheSubpart, subpart: str)

Return a path object pointing to a subdir of the given "/data" directory.

source get_memory_for(cache_subpart: CacheSubpart)

Get the joblib cache memory related to a subpath of the "/data" directory.

source identity_function(input: Any, output_to_be_cached: Any | None)

Identity function.

source is_input_in_the_cache(identity_function: MemorizedFunc, input: Any)

Return if the input has already an output saved in the cache.

source manually_cache_result(identity_function: MemorizedFunc, input: Any, output: Any)

Manually save the input and its output in the joblib's cache.

Parameters

  • identity_function : MemorizedFunc a dummy cached function to carry out the joblib cache mechanism, built from a wrapping of the identity_function function given by the module. The funtion must ignore the output argument in the caching

  • input : Any a hashable input

  • output : Any the value to be saved in the cache

source escape_expensive_run_when_cached[Input, HashedT, Output](named_id_func: CacheIngestorFunction[HashedT, Output], memory: Memory, input_hash_function: Callable[[Input], HashedT], expensive_function: Callable[[Iterator[Input]], Iterator[Output]], input_iter: Iterator[Input])

TODO: comment.

Parameters

  • named_id_func : CacheIngestorFunction[HashedT, Output] a function defined like this (input, output) -> output output can be None

  • memory : Memory TODO

  • input_hash_function : Callable[[Input], HashedT] TODO

  • expensive_function : Callable[[Iterator[Input]], Iterator[Output]] TODO

  • input_iter : Iterator[Input] TODO

Raises

  • Exception

source manualy_cache_batch_processing[Input, Output](path_for_input: Callable[[Input], Path], cache_on_disk: Callable[[Output, Path], None], load_output_from_cache: Callable[[Path], Output], expensive_function: Callable[[Iterator[Input]], Iterator[Output]], input_iter: Iterator[Input])Iterator[tuple[Input, Output]]

Lazily execute an expensive function taking a batch of inputs with cache.

Execute an expensive function taking a batch of inputs, with escaping all the inputs of the batch whose the output is already saved in the cache.