Skip to main content

Tools to create executable dags from interdependent functions.

Project description

dags

PyPI PyPI - Python Version Conda Version Conda Platform PyPI - License Documentation Status GitHub Workflow Status codecov pre-commit.ci status

About

dags provides tools to combine several interrelated functions into one function. The order in which the functions are called is determined by a topological sort on a dag that is constructed from the function signatures. You can specify which of the function results will be returned in the combined function.

dags is a tiny library, all the hard work is done by the great NetworkX.

Example

To understand what dags does, let's look at a very simple example of a few functions that do simple calculations.

def f(x, y):
    return x**2 + y**2


def g(y, z):
    return 0.5 * y * z


def h(f, g):
    return g / f

Assume that we are interested in a function that calculates h, given x, y and z.

We could hardcode this function as:

def hardcoded_combined(x, y, z):
    _f = f(x, y)
    _g = g(y, z)
    return h(_f, _g)


hardcoded_combined(x=1, y=2, z=3)
0.6

Instead, we can use dags to construct the same function:

from dags import concatenate_functions

combined = concatenate_functions([h, f, g], targets="h")

combined(x=1, y=2, z=3)
0.6

More examples can be found in the documentation

Notable features

  • The dag is constructed while the combined function is created and does not cause too much overhead when the function is called.
  • If all individual functions are jax compatible, the combined function is jax compatible.
  • When jitted or vmapped with jax, we have not seen any performance loss compared to hard coding the combined function.
  • When there is more than one target, you can determine whether the result is returned as tuple, list or dict or pass in an aggregator to combine the multiple outputs.
  • Since the relationships are discoverd from function signatures, dags provides decorators to rename arguments in order to make it easy to wrap functions you do not control yourself.

Installation

dags is available on PyPI and conda-forge. Install it with

$ pip install dags

# or

$ pixi add dags

# or

$ conda install -c conda-forge dags

Documentation

The documentation is hosted on Read the Docs.

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

dags-0.5.1.tar.gz (22.2 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

dags-0.5.1-py3-none-any.whl (25.9 kB view details)

Uploaded Python 3

File details

Details for the file dags-0.5.1.tar.gz.

File metadata

  • Download URL: dags-0.5.1.tar.gz
  • Upload date:
  • Size: 22.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for dags-0.5.1.tar.gz
Algorithm Hash digest
SHA256 21b870915d437f41e187b08c9c25503cbb87f90b2844ea13e74a59e9523b4b07
MD5 9f943f09c44234c6d62443a54c75a92c
BLAKE2b-256 1a6d143c37ac2b575551fb3ed405798e7a79087e9ef98b7dd7b085646e1fa548

See more details on using hashes here.

File details

Details for the file dags-0.5.1-py3-none-any.whl.

File metadata

  • Download URL: dags-0.5.1-py3-none-any.whl
  • Upload date:
  • Size: 25.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for dags-0.5.1-py3-none-any.whl
Algorithm Hash digest
SHA256 e9fd9fbe0536784fe8b8ce58ea194801b1de39d7364941d4a1f2d8240c14123d
MD5 680d5dd8e624aa4fafa3a4fc7fe597c8
BLAKE2b-256 2cc1a662f0a8f6e024fca239d493f278d9adf5de1c8408af46a53a76beb13534

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page