A framework to keep track of dependencies in non-linear workflows
Project description
A framework to keep track of dependencies in nonlinear workflows. Source code
About
Create event-driven apps in Python with ease, without writing callback functions
Set up the functional relationship between your public (visible to user) as well as internal (hidden) variables, and let autocalc take care of keeping them in sync.
Example
In this example we will implement a quadratic equation solver. User can enter the a, b and c parameters of the
a*x*x + b*x +c = 0
quadratic equation and we will calculate the two solutions: x1 and x2 by the following formulas:
x1 = (-b-D)/(2a)
x2 = (-b+D)/(2a)
where D is defined as
D=sqrt(b*b - 4*a*c)
In this example we assume a Jupyter notebook environment and the use of ipywidgets. The library was designed with this setup in mind, but the core functionality is independent of any interactive environment.
First we declare and display our input variables
import ipywidgets as widgets
from autocalc.autocalc import Var
import math
a = Var('a', initial_value = 1, widget = widgets.FloatText())
b = Var('b', initial_value = -3, widget = widgets.FloatText())
c = Var('c', initial_value = 1, widget = widgets.FloatText())
display(a); display(b); display(c)
Then we implement the code which calculates the solution
def Dfun(a, b, c):
try:
return math.sqrt(b*b-4*a*c)
except ValueError:
return math.nan
def x1fun(a,b,D):
return (-b-D)/2/a
def x2fun(a,b,D):
return (-b+D)/2/a
We are now ready to define and display our internal variable: D=sqrt(b*b - 4*a*c) and output variables: x1 and x2
D = Var('D', fun=Dfun, inputs=[a, b, c])
x1 = Var('X1', fun=x1fun, inputs=[a, b, D], widget = widgets.FloatText(), read_only=True)
x2 = Var('X2', fun=x2fun, inputs=[a, b, D], widget = widgets.FloatText(), read_only=True)
display(x1)
display(x2)
That’s it. With just a few lines we set up the dependency graph from our input variables to our output ones. Any time the user upgrades any of the input variables, the output will be updated automatically.
Features
Ipywidgets integration + visual framework independent mode of operation.
Read-only variables
Lightweight, minimal library. Learn the basics in 10 minutes.
“Lazy” variables, which only get invalidated when their input(s) change, but are not actually recalculated until explicitly requested. Useful for functions which take a long time to evaluate.
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
Built Distribution
File details
Details for the file autocalc-0.2.1.tar.gz
.
File metadata
- Download URL: autocalc-0.2.1.tar.gz
- Upload date:
- Size: 24.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.7.1 importlib_metadata/4.10.1 pkginfo/1.8.2 requests/2.27.1 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.9.10
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 25f977649942345f28400f373c219264f35ab3b5a9888bc339ef77d53d80ea7b |
|
MD5 | 6b527109c7e7e2feae971bf68dd79fbf |
|
BLAKE2b-256 | 6a2c8331b7ced15b6aabf4b88acc7804af30af0bdb4f52d89878afa26d2e4104 |
File details
Details for the file autocalc-0.2.1-py3-none-any.whl
.
File metadata
- Download URL: autocalc-0.2.1-py3-none-any.whl
- Upload date:
- Size: 8.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.7.1 importlib_metadata/4.10.1 pkginfo/1.8.2 requests/2.27.1 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.9.10
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 1c98f42380a903826ccdf36906b1a7eec8e18188a00cea23dd018cd106d1ae7b |
|
MD5 | 20cb0b707a91942b9c41c0c1c9c8f5d2 |
|
BLAKE2b-256 | 33fa9bf641d4ee9b09802e1cf718ba2ee07d733b1d49975ef8cd624ab1e2a33c |