Progressive evaluation
Documentation | Installation | Examples | Related
This package lets the user define a computation such that:
- Depending on the requested output, only the required (partial) computations are executed.
- Intermediate quantities can be overriden by the user such that dependent values are recomputed.
The computational graph can either be defined as a class, or is constructed dynamically by registering nodes.
Installation
To use progeval, it can be installed with pip:
(.venv) $ pip install progeval
Examples
Consider the following toy computation:
alpha = x * y
beta = x + y
total = alpha + beta
We can define this computational graph in multiple ways, all via the computational graph class ProgEval.
The first is by dynamically adding nodes corresponding to the computable objects:
from progeval import ProgEval
graph = ProgEval()
graph.alpha = lambda x, y: x * y
graph.beta = lambda x, y: x + y
graph.total = lambda alpha, beta: alpha + beta
# we can then set inputs ...
graph.x, graph.y = 3, 6
# ... and evaluate any (intermediate) value
graph.total == 27
The above example relies on the fact that the inputs (x, alpha, etc.) can be read from the function signatures.
If we want to reuse some external function this is not possible.
The following syntax allows one to (optionally) specify the input arguments:
from progeval import ProgEval
def add(x, y):
return x + y
graph = ProgEval()
graph.register('alpha', lambda x, y: x * y)
graph.register('beta', add)
# here the inputs we want are different from the names
# in the function definition of `add`
graph.register('total', add, ['alpha', 'beta'])
Another way to define the computational graph is by collecting all parts of the computation as methods of a class:
from progeval import ProgEval
class Computation(ProgEval):
def __init__(self, x, y):
super().__init__(x=x, y=y)
@staticmethod
def alpha(x, y):
return x * y
@staticmethod
def beta(x, y):
return x + y
@staticmethod
def total(alpha, beta):
return alpha + beta
# The class then acts almost like a normal function
Computation(3, 8).total == 35
Related
A similar functionality of delayed evaluation of a computational graph is provided by Dask delayed.
However, the construction is slightly different.
There, the graph is built dynamically by replacing intermediate quantities with Delayed objects and wrapping functions.
The functionality of Dask, which is intended for computational parallelism, can even be combined with the structures here, as shown in the how-to section of the documentation.
Metadata
Release files for progeval 1.0.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| progeval-1.0.0.tar.gz | 7.3 kB | Without provenance | Details for progeval-1.0.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| progeval-1.0.0-py3-none-any.whl | Python 3 | none | any | Details for progeval-1.0.0-py3-none-any.whl |
Total release size: 15.2 kB
Release files / progeval-1.0.0.tar.gz
| Download URL | progeval-1.0.0.tar.gz |
|---|---|
| Size | 7.3 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
9e3a7b08af4194fe6a771156f7e35efeb3fd2ff462aed0432f175e966be8f886
|
|
BLAKE2b-256 checksum How to use checksums |
2c9fb694fc121af9d12632540be8817748217006fc973cbcf699e586f0d63a54
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/4.0.1 CPython/3.9.15
|
Release files / progeval-1.0.0-py3-none-any.whl
| Download URL | progeval-1.0.0-py3-none-any.whl |
|---|---|
| Size | 7.8 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
0576a65ae7016109ad5bc8e10f221fc731b691c55f01a3464096980343b5cc3e
|
|
BLAKE2b-256 checksum How to use checksums |
a849fe957cbb0100af93ccba3ed13a5c2531a9d4a91e2336de22f933d0067087
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/4.0.1 CPython/3.9.15
|
Security for progeval 1.0.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.