Skip to main content

autocalc

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.

Release files for autocalc 0.2.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for autocalc 0.2.1
File Size Uploaded
autocalc-0.2.1.tar.gz 24.2 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for autocalc 0.2.1
File Interpreter ABI Platform
autocalc-0.2.1-py3-none-any.whl Python 3 none any Details

Total release size: 33.1 kB

Release files / autocalc-0.2.1.tar.gz

Download URL autocalc-0.2.1.tar.gz
Size 24.2 kB
Tags Source
SHA-256 checksum
How to use checksums
25f977649942345f28400f373c219264f35ab3b5a9888bc339ef77d53d80ea7b
BLAKE2b-256 checksum
How to use checksums
6a2c8331b7ced15b6aabf4b88acc7804af30af0bdb4f52d89878afa26d2e4104
Upload date
Uploaded using Trusted Publishing?
What is 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

Release files / autocalc-0.2.1-py3-none-any.whl

Download URL autocalc-0.2.1-py3-none-any.whl
Size 8.9 kB
Tags Python 3
SHA-256 checksum
How to use checksums
1c98f42380a903826ccdf36906b1a7eec8e18188a00cea23dd018cd106d1ae7b
BLAKE2b-256 checksum
How to use checksums
33fa9bf641d4ee9b09802e1cf718ba2ee07d733b1d49975ef8cd624ab1e2a33c
Upload date
Uploaded using Trusted Publishing?
What is 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

Release history Release notifications | RSS feed

This release

0.2.1 This release

2 release files

0.1.1

2 release files

0.1.0

2 release files

0.0.1

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page