Skip to main content

Task-Graph

Build a dynamic task graph for your project with Task-Graph!

Introduction

When facing a complex task, it's often necessary to recalculate the entire task when user wants to get one of the intermediate results, or to adjust one of the parameters or methods, but once you have Task-Graph,

  1. If you need to get a result, Task-Graph will only compute all the upstream tasks of the result, and each task will cache for later use.

  2. If one of the task's parameters or method is adjusted, Task-Graph will automatically check all the downstream tasks and clear their cached results.

In short, Task-Graph will make the computer lazy and just fulfill your needs without doing repetitive tasks, no more or less.

Usage

No doc available now, here is an minimal example.

# import
from task_graph import TaskGraph

# init a TaskGraph
tg = TaskGraph()

# user task methods
def add(a, b):
    print("add", a, b)
    return a + b


def sub(a, b):
    print("sub", a, b)
    return a - b

# describe the task graph(much like dask.delayed)
ret1 = tg.add_task(add)(1, 2)
ret2 = tg.add_task(add)(3, ret1)
ret3 = tg.add_task(add)(4, ret2)
ret4 = tg.add_task(sub)(ret2, ret3)
final = tg.add_task('to_list')(ret1, ret2, ret3, ret4)

# trigger the computation and print
print(final.compute())

# when I want to update a task
tg.update_task(ret3)(add)(5, ret2)

# Because ret3 is change, rest3, rest4 and final will be recalculated
print(final.compute())

Or, a lazy way:

from task_graph import TaskGraph


tg = TaskGraph()

def add(a, b):
    print("add", a, b)
    return a + b


def sub(a, b):
    print("sub", a, b)
    return a - b

# omit add_task
ret1 = tg(add)(1, 2)
ret2 = tg(add)(3, ret1)
ret3 = tg(add)(4, ret2)
ret4 = tg(sub)(ret2, ret3)
final = tg('to_list')(ret1, ret2, ret3, ret4)

# auto compute and print
final.print()

# omit update_task
tg(ret3)(add)(5, ret2)

# auto compute and print
final.print()

TODO

Task-Graph is at the very beginning, so many todos in the codes. Here are a few general ones:

  • add parallel scheduler
  • add decorator that can auto transfer function to task
  • add graphviz-based visualization
  • add unit test
  • add doc
  • add examples

Zen

I am lazy, so I build this to let computer be also lazy.

One of the biggest differences in Python from other languages is that the methods (like all other objects) are mutable, Task-Graph is designed to accommodate that.

Task-Graph was designed to speed up python project, and want to make it the simplest solution to avoid any recalculation.

I have referred to the Dask.delayed API in many places. The difference between Task-Graph and Dask is to try to adapt to the dynamics of the python and python projects, and make computer not only delayed but also lazy.

Metadata

Release files for task-graph 0.0.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 task-graph 0.0.1
File Size Uploaded Provenance
task-graph-0.0.1.tar.gz 5.9 kB Without provenance Details

Built distribution (wheel)

Table of built distributions (wheels) for task-graph 0.0.1
File Interpreter ABI Platform
task_graph-0.0.1-py3-none-any.whl Python 3 none any Details

Total release size: 13.8 kB

Release files / task-graph-0.0.1.tar.gz

Download URL task-graph-0.0.1.tar.gz
Size 5.9 kB
Tags Source
SHA-256 checksum
How to use checksums
f1ca3404ff747e5804a75fbc9a17552ea5682b9c6f3ff5458ce25dddd31cf597
BLAKE2b-256 checksum
How to use checksums
9075f01f57f5b97ec0f43978510139fb7ed1a2c1bc8c2ac45c32967abba437f4
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.1.1 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.6.0 requests-toolbelt/0.9.1 tqdm/4.43.0 CPython/3.6.8

Release files / task_graph-0.0.1-py3-none-any.whl

Download URL task_graph-0.0.1-py3-none-any.whl
Size 7.8 kB
Tags Python 3
SHA-256 checksum
How to use checksums
eb981f8d2ff90724e097b55dae83a64d55a0f34213734cdd8bf24373d24adda2
BLAKE2b-256 checksum
How to use checksums
b4767d57a0b4a1ce83a0d4d30dd7faeddc6e25f3bc5b12b733c0443970a2c0e0
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.1.1 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.6.0 requests-toolbelt/0.9.1 tqdm/4.43.0 CPython/3.6.8

Security for task-graph 0.0.1

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.

Release history Release notifications | RSS feed

This release

0.0.1 This release

2 release files No provenance

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