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 Graph Visualization

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

Overview

Concrete visualization methods for rendering lazy computation graphs as GraphViz diagrams or interactive DagreD3 widgets, provided by the Tributary library.

Description

The lazy graph visualization module provides four functions that are monkey-patched onto the lazy Node class:

  • Graph - Returns a nested dict representation of the graph (node → upstream nodes)
  • Print - Returns a text tree representation of the graph
  • GraphViz - Returns a graphviz.Digraph with color-coded nodes (red = dirty, teal = dynamic, default = clean)
  • Dagre - Returns an ipydagred3.DagreD3Widget for interactive Jupyter visualization with color-coded states

Node colors indicate state:

  • Red - Dirty (needs re-evaluation)
  • Teal - Dynamic (always re-evaluates)
  • White - Clean (cached)

Usage

Import these when you need to visualize a lazy computation graph. Use GraphViz for static diagrams (export to PNG/SVG), Dagre for interactive Jupyter widgets, and Graph/Print for programmatic inspection.

Code Reference

Source Location

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

Signature

def Graph(node):
    """Return nested dict: {node: [upstream.graph() for upstream in node.upstream()]}"""

def Print(node, level=0):
    """Return text tree representation of the graph."""

def GraphViz(node):
    """Return a graphviz.Digraph with color-coded dirty/dynamic states.

    Colors:
        red  = dirty node
        teal = dynamic node
        default = clean node
    """

def Dagre(node):
    """Return an ipydred3.DagreD3Widget with color-coded states.

    Styles:
        fill: #f00 = dirty
        fill: #0ff = dynamic
        fill: #fff = clean
    """

# Bindings applied at module load:
Node.graph = Graph
Node.print = Print
Node.graphviz = GraphViz
Node.dagre = Dagre

Import

# Methods are automatically available on Node when importing tributary.lazy
from tributary.lazy import Node
# Importing tributary.lazy.output.output binds visualization methods to Node

I/O Contract

Inputs

Name Type Required Description
node Node Yes The root node of the graph to visualize
level int No (Print) Indentation level for text output

Outputs

Name Type Description
Graph returns dict Nested dict of node → upstream nodes
Print returns str Formatted text tree
GraphViz returns graphviz.Digraph Renderable graph diagram
Dagre returns DagreD3Widget Interactive Jupyter widget

Usage Examples

GraphViz Visualization

from tributary.lazy import Node

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

# Render the graph as a Digraph
dot = z.graphviz()
dot.render("graph", format="png")  # Saves to graph.png

# After changing x, z becomes dirty (red in graphviz)
x.setValue(10)
dot = z.graphviz()  # z and downstream nodes shown in red

Graph Inspection

from tributary.lazy import Node

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

# Get nested dict representation
graph_dict = z.graph()
print(graph_dict)
# {z#xxx: [{x#xxx: []}, {y#xxx: []}]}

# Get text tree
print(z.print())

Dagre Interactive Widget

from tributary.lazy import Node, LazyGraph, node

# In a Jupyter notebook:
class MyGraph(LazyGraph):
    def __init__(self):
        self.node(name="a", value=5)
        self.node(name="b", value=3)
        super().__init__()

    @node
    def evaluate(self):
        return self.a * self.b + self.a

g = MyGraph()
widget = g.evaluate().dagre()
display(widget)  # Interactive graph in Jupyter

Related Pages

Implements Principle

Requires Environment

Page Connections

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