Skip to main content

Lazy computing tree cache library

Project description

EvalCache

Lazy tree evaluation cache library.

Brief

The library implements a cache of dependent lazy calculations for working with clean, time-consuming computational tasks, such as symbolic transformations, geometric, numerical algorithms.

The task of the library is to save the result of the computation once performed and, if necessary, load it, saving the computing resources. The algorithm for constructing the hashkey of the computed object uses the input data parameterizing this object, which makes it possible to track changes in the arguments of the lazy algorithm and to postpone the necessary calculations if the conditions have changed. If an lazy object is used as an argument or a generating function, its hashkey is used as its hash. This allows you to build a dependent computational tree. If the input data of an object changes, its hashkey and hashkeys of all objects computed on its basis change. And the subtree will be reevaluated.

Since the library saves every computed object in the cache, including intermediate objects, it can pick up changes in the calculation tree from any step. Thus, previously received data, if they can be applied to a new calculation tree, will be used. This allows you to not make heavy preliminary calculations in separate files, and load them transparently, and also compare results with small changes in input parameters without multiple results remaking.

Install

python3 -m pip install evalcache

Details

Base example

import evalcache

lazy = evalcache.Lazy(cache = evalcache.DirCache(".evalcache"))

@lazy
def func(a,b,c):
    return do_something(a,b,c)

lazyresult = func(1,2,3)
result = lazyresult.unlazy() #alternative: result = evalcache.unlazy(lazyresult)

In that example we can see based classes and objects: You should instance "evalcache.Lazy" for start work. "Lazy" get "cache" as parametr. Cache is a dict-like object those will store and load our evaluation's results. "Lazy" instance "lazy" can be used as decorator for create "LazyObjects". Decorated object "func" is a LazyObject. "func" can generate another lazyobject, as "lazyresult", for example with callable interface. For get evaluation result we use "unlazy" method.

Diagnostic

We can visualize cache operations:

lazy = evalcache.Lazy(cache = cache, diag = True)

in this mode, when you use unlazy, you will see console output:
endp - get endpoint object.
fget - get variable from local object store.
load - get early stored value from cache.
save - evaluation executed and value stored. eval - evaluated without storing

Hash algorithm

You can choose algorithm from hashlib or specify user's hashlib-like algorithm.

lazy = evalcache.Lazy(cache = cache, algo = hashlib.sha512)

DirCache

DirCache is a dict-like object that used pickle to store values in key-named files. It very simple cache and it can be changed to more progressive option if need.

lazy = evalcache.Lazy(cache = evalcache.DirCache(".evalcache"))

Articles

Дисковое кэширование деревьев ленивых вычислений

Contact

mirmik(mirmikns@yandex.ru)

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

evalcache-1.15.0.tar.gz (15.2 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

evalcache-1.15.0-py3-none-any.whl (15.5 kB view details)

Uploaded Python 3

File details

Details for the file evalcache-1.15.0.tar.gz.

File metadata

  • Download URL: evalcache-1.15.0.tar.gz
  • Upload date:
  • Size: 15.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.7

File hashes

Hashes for evalcache-1.15.0.tar.gz
Algorithm Hash digest
SHA256 665ecb75f04104e7c79a93e17658a8488ff3ac31f84aca02feb2c083634e103e
MD5 5750809a1ce24f15d3d54dcffbd53f01
BLAKE2b-256 6b25690407b3505bb027cb2264e983ff7343db6305b359b6794b6ebb5cf2b37a

See more details on using hashes here.

File details

Details for the file evalcache-1.15.0-py3-none-any.whl.

File metadata

  • Download URL: evalcache-1.15.0-py3-none-any.whl
  • Upload date:
  • Size: 15.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.7

File hashes

Hashes for evalcache-1.15.0-py3-none-any.whl
Algorithm Hash digest
SHA256 c4d448726eb910911ff94ff4cf19a15fbcd3102be9477e130eb4e689167b6511
MD5 7f22bd6e421c9cfde4d46b3ff7df070c
BLAKE2b-256 ecc3dd01bfd452d6daefdab38df18f8d1c9df63b28f56a916e56b84a1fdd1f09

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page