Jump to content

Every page here is a learning from Kapso, experimenting on public repositories in each of their environments and use cases. Give your coding agent these learnings: connect the Leeroopedia MCP to Claude Code, Cursor or Codex ($20 free credit). Powered by Leeroo · founders@leeroo.com

Implementation:1kbgz Tributary Lazy Node

From Leeroopedia
Knowledge Sources
Domains Lazy_Evaluation, Graph_Architecture
Last Updated 2026-10-14 00:00 GMT

Overview

Core lazy evaluation node class with dirty propagation, parameter extraction, tweaks, and dual-number autodiff support, provided by the Tributary library.

Description

The lazy Node class is the fundamental building block of Tributary's lazy evaluation subsystem. It wraps a static value or a callable, extracts the callable's parameters, and wires upstream dependencies as child Node instances. Nodes are evaluated only when called (__call__) and only if they are dirty or dynamic. Cached values are returned otherwise.

Key features include:

  • Dirty propagation: When a node's value changes, all downstream nodes are marked dirty and re-evaluate on next access.
  • Tweaks: Temporary argument overrides can be passed to __call__ without mutating node state.
  • Dual-number arithmetic: Setting use_dual=True enables forward-mode automatic differentiation.
  • Parameter extraction: Automatically inspects the callable's signature and wraps each parameter as a child node.
  • Comparison tolerance: Values are compared with a numeric threshold to avoid unnecessary re-evaluation.

Usage

Import this class when you need to construct lazy computation graphs, wrap callables for deferred evaluation, observe dirty propagation, or enable dual-number autodiff on lazy graphs.

Code Reference

Source Location

  • Repository: Tributary
  • File: tributary/lazy/node.py

Signature

class Node(_DagreD3Mixin):
    def __init__(
        self,
        value=None,
        name="",
        dynamic=False,
        use_dual=False,
        args=None,
        kwargs=None,
        graphvizshape="box",
    ):
        ...

    def __call__(self, *argTweaks, **kwargTweaks):
        """Evaluate the node, optionally with temporary argument tweaks."""

    def value(self):
        """Return the last computed value."""

    def setValue(self, value):
        """Set a new value and trigger dirty propagation if changed."""

    def set(self, **kwargs):
        """Set upstream dependency values by keyword."""

    def isDirty(self):
        """Return True if the node needs re-evaluation."""

    def isDynamic(self):
        """Return True if the node always re-evaluates."""

    def setDirty(self, myself=True):
        """Mark this node and all downstream nodes as dirty."""

    def __lshift__(self, other):
        """Wire other as upstream of self (self << other)."""

    def __rshift__(self, other):
        """Wire self as upstream of other (self >> other)."""

    def _call(self, *argTweaks, **kwargTweaks):
        """Internal: compute arg state, execute if dirty/dynamic/tweaking."""

    def _computeArgState(self, *argsTweaks, **kwargTweaks):
        """Build ArgState namedtuple from upstream values and tweaks."""

    def _execute(self, args_state):
        """Execute the wrapped callable with the given arg state."""

Import

from tributary.lazy import Node
# or:
from tributary.lazy.node import Node

I/O Contract

Inputs

Name Type Required Description
value any/callable No Static value or callable to wrap
name str No Display name
dynamic bool No Always re-evaluate (not lazy)
use_dual bool No Enable dual-number autodiff
args tuple No Positional arguments for callable
kwargs dict No Keyword arguments for callable

Outputs

Name Type Description
__call__ returns any The computed (or cached) value
value() returns any The last computed value
isDirty() returns bool Whether the node needs re-evaluation

Usage Examples

Basic Lazy Node

from tributary.lazy import Node

# Create a leaf node with a static value
x = Node(value=5, name="x")
y = Node(value=3, name="y")

# Create a computation node
z = x + y  # z is a new Node whose value = x + y = 8

print(z())     # 8 (evaluated on demand)
print(z.value())  # 8 (cached)

# Change an input and observe dirty propagation
x.setValue(10)
print(z.isDirty())  # True
print(z())          # 13 (re-evaluated)

Tweaks (Temporary Overrides)

from tributary.lazy import Node

x = Node(value=5, name="x")
y = Node(value=3, name="y")
z = x + y

print(z())           # 8 (normal evaluation)
print(z(20))         # 23 (x temporarily set to 20, y unchanged)
print(z())           # 8 (original state preserved)

Dual-Number Autodiff

from tributary.lazy import Node

# Create dual-number input: (value, derivative_seed)
x = Node(value=(3.0, 1.0), name="x", use_dual=True)

# Compose: f(x) = x^2
f = x * x

result = f()
print(result[0])  # 9.0  (function value)
print(result[1])  # 6.0  (derivative: f'(x) = 2x = 6)

Related Pages

Implements Principle

Requires Environment

Uses Heuristics

Page Connections

Double-click a node to navigate. Hold to expand connections.
Principle
Implementation
Heuristic
Environment