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.14.0.tar.gz (15.3 kB view details)

Uploaded Source

Built Distribution

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

Uploaded Python 3

File details

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

File metadata

  • Download URL: evalcache-1.14.0.tar.gz
  • Upload date:
  • Size: 15.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.3.0 pkginfo/1.7.0 requests/2.23.0 setuptools/49.3.1 requests-toolbelt/0.9.1 tqdm/4.56.2 CPython/3.8.6

File hashes

Hashes for evalcache-1.14.0.tar.gz
Algorithm Hash digest
SHA256 f6763ced4ab11e6afdd86cc86813ff91a006c804aa68e03fdfa857b7c68e48a3
MD5 0046f97ae836343fc6afa7a5d04c8d37
BLAKE2b-256 2bee344c0b238cefd76f25bddf7ba72fa13e43d895621e57cde4453f3a4ad854

See more details on using hashes here.

File details

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

File metadata

  • Download URL: evalcache-1.14.0-py3-none-any.whl
  • Upload date:
  • Size: 15.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.3.0 pkginfo/1.7.0 requests/2.23.0 setuptools/49.3.1 requests-toolbelt/0.9.1 tqdm/4.56.2 CPython/3.8.6

File hashes

Hashes for evalcache-1.14.0-py3-none-any.whl
Algorithm Hash digest
SHA256 b6b30b0df3f3983952835854ad9c3331f1e4c496e3c0bcc420716ed4903c3da3
MD5 f248b530e3f2117807beacda77a9696c
BLAKE2b-256 159579c567dd21caec28bbeecad786d2985f0fd66406d1886c6396e4df613435

See more details on using hashes here.

Supported by

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