evalcache


Nameevalcache JSON
Version 1.14.0 PyPI version JSON
download
home_pagehttps://github.com/mirmik/evalcache
SummaryLazy computing tree cache library
upload_time2021-02-16 18:11:27
maintainer
docs_urlNone
authormirmik
requires_python
licenseMIT
keywords caching lazy
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI
coveralls test coverage No coveralls.
            # EvalCache
Lazy tree evaluation cache library.

![](https://travis-ci.com/mirmik/evalcache.svg?branch=master)

## 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
```sh
python3 -m pip install evalcache
```

## Details
### Base example
```python
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:
```python
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.
```python
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. 
```python
lazy = evalcache.Lazy(cache = evalcache.DirCache(".evalcache"))
```  
### Articles
[Дисковое кэширование деревьев ленивых вычислений](https://habr.com/post/422937/)

### Contact
mirmik(mirmikns@yandex.ru)



            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/mirmik/evalcache",
    "name": "evalcache",
    "maintainer": "",
    "docs_url": null,
    "requires_python": "",
    "maintainer_email": "",
    "keywords": "caching,lazy",
    "author": "mirmik",
    "author_email": "mirmikns@yandex.ru",
    "download_url": "https://files.pythonhosted.org/packages/2b/ee/344c0b238cefd76f25bddf7ba72fa13e43d895621e57cde4453f3a4ad854/evalcache-1.14.0.tar.gz",
    "platform": "",
    "description": "# EvalCache\nLazy tree evaluation cache library.\n\n![](https://travis-ci.com/mirmik/evalcache.svg?branch=master)\n\n## Brief\nThe library implements a cache of dependent lazy calculations for working with clean, time-consuming computational tasks, such as symbolic transformations, geometric, numerical algorithms.\n\nThe 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.\n\nSince 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.\n\n## Install\n```sh\npython3 -m pip install evalcache\n```\n\n## Details\n### Base example\n```python\nimport evalcache\n\nlazy = evalcache.Lazy(cache = evalcache.DirCache(\".evalcache\"))\n\n@lazy\ndef func(a,b,c):\n    return do_something(a,b,c)\n\nlazyresult = func(1,2,3)\nresult = lazyresult.unlazy() #alternative: result = evalcache.unlazy(lazyresult)\n```\n\nIn that example we can see based classes and objects:\nYou 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.\n\n### Diagnostic  \nWe can visualize cache operations:\n```python\nlazy = evalcache.Lazy(cache = cache, diag = True)\n```\nin this mode, when you use unlazy, you will see console output:  \nendp - get endpoint object.  \nfget - get variable from local object store.  \nload - get early stored value from cache.  \nsave - evaluation executed and value stored.\neval - evaluated without storing\n\n### Hash algorithm  \nYou can choose algorithm from hashlib or specify user's hashlib-like algorithm.\n```python\nlazy = evalcache.Lazy(cache = cache, algo = hashlib.sha512)\n```\n\n### DirCache\nDirCache is a dict-like object that used pickle to store values in key-named files.\nIt very simple cache and it can be changed to more progressive option if need. \n```python\nlazy = evalcache.Lazy(cache = evalcache.DirCache(\".evalcache\"))\n```  \n### Articles\n[\u0414\u0438\u0441\u043a\u043e\u0432\u043e\u0435 \u043a\u044d\u0448\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0435 \u0434\u0435\u0440\u0435\u0432\u044c\u0435\u0432 \u043b\u0435\u043d\u0438\u0432\u044b\u0445 \u0432\u044b\u0447\u0438\u0441\u043b\u0435\u043d\u0438\u0439](https://habr.com/post/422937/)\n\n### Contact\nmirmik(mirmikns@yandex.ru)\n\n\n",
    "bugtrack_url": null,
    "license": "MIT",
    "summary": "Lazy computing tree cache library",
    "version": "1.14.0",
    "project_urls": {
        "Homepage": "https://github.com/mirmik/evalcache"
    },
    "split_keywords": [
        "caching",
        "lazy"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "159579c567dd21caec28bbeecad786d2985f0fd66406d1886c6396e4df613435",
                "md5": "f248b530e3f2117807beacda77a9696c",
                "sha256": "b6b30b0df3f3983952835854ad9c3331f1e4c496e3c0bcc420716ed4903c3da3"
            },
            "downloads": -1,
            "filename": "evalcache-1.14.0-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "f248b530e3f2117807beacda77a9696c",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": null,
            "size": 15473,
            "upload_time": "2021-02-16T18:11:26",
            "upload_time_iso_8601": "2021-02-16T18:11:26.522917Z",
            "url": "https://files.pythonhosted.org/packages/15/95/79c567dd21caec28bbeecad786d2985f0fd66406d1886c6396e4df613435/evalcache-1.14.0-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "2bee344c0b238cefd76f25bddf7ba72fa13e43d895621e57cde4453f3a4ad854",
                "md5": "0046f97ae836343fc6afa7a5d04c8d37",
                "sha256": "f6763ced4ab11e6afdd86cc86813ff91a006c804aa68e03fdfa857b7c68e48a3"
            },
            "downloads": -1,
            "filename": "evalcache-1.14.0.tar.gz",
            "has_sig": false,
            "md5_digest": "0046f97ae836343fc6afa7a5d04c8d37",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": null,
            "size": 15251,
            "upload_time": "2021-02-16T18:11:27",
            "upload_time_iso_8601": "2021-02-16T18:11:27.778523Z",
            "url": "https://files.pythonhosted.org/packages/2b/ee/344c0b238cefd76f25bddf7ba72fa13e43d895621e57cde4453f3a4ad854/evalcache-1.14.0.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2021-02-16 18:11:27",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "mirmik",
    "github_project": "evalcache",
    "travis_ci": true,
    "coveralls": false,
    "github_actions": false,
    "lcname": "evalcache"
}
        
Elapsed time: 0.22697s