dags#
dags is a Python library for creating executable directed acyclic graphs (DAGs) from interdependent functions. It automatically determines the execution order based on function signatures and enables efficient composition of complex computational pipelines.
Key Features#
Automatic dependency resolution: Functions are ordered based on their parameter names matching other functions’ names
Function composition: Combine multiple functions into a single callable
Tree structures: Work with nested dictionaries using qualified names
Signature manipulation: Rename arguments and manage function signatures
Quick Example#
import dags
def a(x):
return x ** 2
def b(a):
return a + 1
def c(a, b):
return a + b
# Combine functions into one
combined = dags.concatenate_functions(
functions={"a": a, "b": b, "c": c},
targets=["c"],
return_type="dict",
)
result = combined(x=5) # Returns {"c": 51}
The key is that you can build the combined function at runtime, which allows you to compose a computational pipeline in a way that you do not need to specify in advance, or in a multitude of ways. It has proven very helpful in a framework to solve life cycle models (pylcm) and to model the German taxes and transfers system (ttsim / gettsim).
Installation#
pip install dags
Or with conda:
conda install -c conda-forge dags
Table of Contents#
- Getting Started
- Usage Patterns
- Pattern 1: Building Computational Pipelines
- Pattern 2: Aggregating Multiple Functions
- Pattern 3: Generating Functions for Multiple Scenarios
- Pattern 4: Selective Computation
- Pattern 5: Dependency Analysis
- Pattern 6: Working with Nested Structures
- Pattern 7: Signature Inspection and Modification
- Best Practices
- Tree Structures
- API Reference