Lazily evaluate function dependency graph
Project description
lazydep
Evaluates some set of functions, according to tome dependency graph structure
There's pretty much 1 function that is worth noting:
lazydep.resolve(graph, state, functions, request=None)
Arguments
- graph: dictionary, mapping function names to the names of parameters required for their execution
- state: dictionary, initial input to functions. the remainder of intermediary parameters will be bootstrapped
- functions: list of functions in any order, or dictionary mapping function names to functions
- request: name of desired function evaluation. If request is specified, only the desired function call will be returned. If left empty, all functions specified will be returned, in the same form as state object.
Returns
dictionary, or result of 'request' function
Example
# Each key here corresponds to a function name
# Once evaluated, a function's return value is stored as a key as its name
depGraph = {
# Once we specify seed, all else will be inferred
'f1': 'seed',
'f2': 'f1',
'f3': ['f1','f2'],
# Function unused. If we only request 'f3', these will never be evaluated
'f4': 'f3',
'f5': 'f6',
'f6': 'seed'
}
# Functions will receive parameters according to the dependency graph
# Keyword args only, positional args not supported
def f1(seed):
return seed % 10
def f2(f1):
return [f1]*f1
def f3(f1, f2):
return (f1,sum(f2))
# The initial information, some set of named parameters.
istate = {'seed': 42}
res = lazydep.resolve(
# How are inputs and outputs reordered?
graph = depGraph,
# What information are we working with?
state = istate,
# What functions are allowed?
functions = [f1,f2,f3],
# Which function output are we requesting?
# If request == None, we will return the aggregate state, after running all functions
request = 'f3',
)
assert( res == (2,4) )
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
lazydep-1.1.tar.gz
(4.3 kB
view details)
Built Distribution
File details
Details for the file lazydep-1.1.tar.gz
.
File metadata
- Download URL: lazydep-1.1.tar.gz
- Upload date:
- Size: 4.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.2.0 pkginfo/1.6.1 requests/2.22.0 setuptools/45.2.0 requests-toolbelt/0.9.1 tqdm/4.51.0 CPython/3.8.5
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 0bc3a74adc221011a3a7670c59813eb309ff50c34a97255cafdb802c9142e367 |
|
MD5 | 096cc0b7a1ba229372848e2e5620f531 |
|
BLAKE2b-256 | 4d860db3adf08136cfd222007aa70006649987bdad89211d0ad03aa5e6a06777 |
File details
Details for the file lazydep-1.1-py2.py3-none-any.whl
.
File metadata
- Download URL: lazydep-1.1-py2.py3-none-any.whl
- Upload date:
- Size: 3.1 kB
- Tags: Python 2, Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.2.0 pkginfo/1.6.1 requests/2.22.0 setuptools/45.2.0 requests-toolbelt/0.9.1 tqdm/4.51.0 CPython/3.8.5
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 45de234a3dbce193a6fa1f3cae19947271736af379c00c28b2a26a8273bcadb6 |
|
MD5 | c8db6978f9f8a2742cf3e120410e7d7d |
|
BLAKE2b-256 | ba6ef5bfbde470bc3cf54a480d3ae7475466765ef9ddfb7fbb707003a45dea56 |