Principle:1kbgz Tributary Declarative Graph Construction
| Knowledge Sources | |
|---|---|
| Domains | Declarative_Programming, Lazy_Evaluation |
| Last Updated | 2026-10-14 00:00 GMT |
Overview
A design approach where computation graph dependencies are inferred automatically from source code structure (AST analysis), rather than being wired manually by the developer.
Description
Declarative graph construction eliminates boilerplate by automatically detecting dependencies between computation methods and input nodes. Instead of explicitly writing wiring code (e.g., node_a << node_b), the developer simply references self.xxx in a method body, and the framework infers the dependency.
This is achieved through AST (Abstract Syntax Tree) analysis: the framework parses each method's source code, walks the AST to find all self.attribute accesses, and records these as dependencies. At graph construction time, each detected attribute is resolved to its corresponding node and wired as an upstream dependency.
This solves the problem of manual dependency wiring, which is:
- Verbose: Every edge must be stated explicitly
- Error-prone: Missing a wiring causes runtime failures
- Brittle: Changing a method's dependencies requires updating the wiring code
Usage
Use this principle when building lazy computation graphs where you want clean, readable code with automatic dependency management. The developer declares what each computation does (referencing inputs by name), and the framework handles how dependencies are wired.
Theoretical Basis
The key insight is that Python method bodies contain implicit dependency information in the form of self.xxx attribute accesses. By parsing the method's AST, these accesses can be extracted without executing the code.
# Abstract AST-based dependency detection (NOT real implementation)
import ast
def detect_dependencies(method):
source = inspect.getsource(method)
tree = ast.parse(textwrap.dedent(source))
deps = set()
for node in ast.walk(tree):
if (isinstance(node, ast.Attribute)
and isinstance(node.value, ast.Name)
and node.value.id == "self"):
deps.add(node.attr)
return deps
The dependency wiring then follows:
The _either_type decorator pattern allows the decorator to be used both as @node and @node(dynamic=True), providing flexibility in evaluation strategy.