Skip to main content

compgraph2txt

Testing Codecov

A tiny library for visualizing computational graphs in the terminal.

│ │ │ ╭─────────╮
│ │ │ │    A    │
│ │ │ ├─────────┤
│ ╰───┼→ a   e ─┼─╮
│   │ │─ b   f ─┼──→
├─────┼→ c   g ─┼───╮
│   │ │─ d   h ─│ │ │
│   │ │      i ─┼────→
│   │ ╰─────────╯ │ │ 
│ ╭───────────────╯ │
│ │ │ ╭─────────────╯
│ │ │ │ ╭─────────╮
│ │ │ │ │    Z    │
│ │ │ │ ├─────────┤
│ ╰─────┼→ t   x ─┼→
│   │ ╰─┼→ u   y ─│
╰───────┼→ v   z ─┼→
    ╰───┼→ w      │
        ╰─────────╯
Source
from compgraph2txt import compgraph2txt
from networkx import MultiDiGraph

graph = MultiDiGraph()
graph.add_node(
    "A", inputs=["a", "b", "c", "d"], outputs=["e", "f", "g", "h", "i"]
)
graph.add_node("Z", inputs=["t", "u", "v", "w"], outputs=["x", "y", "z"])

# Add edges from external sources
graph.add_edge("ext1", "A", input="c")
graph.add_edge("ext1", "Z", input="v")
graph.add_edge("ext2", "A", input="a")
graph.add_edge("ext3", "Z", input="w")

# Add edges to external sinks
graph.add_edge("A", "ext", output="f")
graph.add_edge("A", "ext", output="i")
graph.add_edge("Z", "ext", output="x")
graph.add_edge("Z", "ext", output="z")
graph.add_edge("Z", "ext", output="x")
graph.add_edge("Z", "ext", output="z")

# Add edges between nodes
graph.add_edge("A", "Z", output="e", input="t")
graph.add_edge("A", "Z", output="g", input="u")

print(compgraph2txt(graph))

Example: Image Background Blur Pipeline

Source

from compgraph2txt import compgraph2txt
from networkx import MultiDiGraph

graph = MultiDiGraph()
graph.add_node("Camera", inputs=[], outputs=["Image"])
graph.add_node("Foreground Detection", inputs=["Image"], outputs=["Foreground", "Background"])
graph.add_node("Blur", inputs=["Image"], outputs=["Blurred Image"])
graph.add_node("Image Overlay", inputs=["Foreground", "Background"], outputs=["Image"])
graph.add_node("Application", inputs=["Image"], outputs=[])

graph.add_edge("Camera", "Foreground Detection", output="Image", input="Image")
graph.add_edge("Foreground Detection", "Blur", output="Background", input="Image")
graph.add_edge("Blur", "Image Overlay", output="Blurred Image", input="Background")
graph.add_edge("Foreground Detection", "Image Overlay", output="Foreground", input="Foreground")
graph.add_edge("Image Overlay", "Application", output="Image", input="Image")

print(compgraph2txt(graph))

Output

╭──────────╮
│  Camera  │
├──────────┤
│   Image ─┼─╮
╰──────────╯ │ 
╭────────────╯
│ ╭────────────────────────╮
│ │  Foreground Detection  │
│ ├────────────────────────┤
╰─┼→ Image     Foreground ─┼─╮
  │            Background ─┼───╮
  ╰────────────────────────╯ │ │ 
╭────────────────────────────╯ │
│ ╭────────────────────────────╯
│ │ ╭────────────────────────╮
│ │ │          Blur          │
│ │ ├────────────────────────┤
│ ╰─┼→ Image  Blurred Image ─┼─╮
│   ╰────────────────────────╯ │ 
│ ╭────────────────────────────╯
│ │ ╭─────────────────────╮
│ │ │    Image Overlay    │
│ │ ├─────────────────────┤
╰───┼→ Foreground  Image ─┼─╮
  ╰─┼→ Background         │ │
    ╰─────────────────────╯ │ 
╭───────────────────────────╯
│ ╭───────────────╮
│ │  Application  │
│ ├───────────────┤
╰─┼→ Image        │
  ╰───────────────╯

Metadata

Release files for compgraph2txt 1.0.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for compgraph2txt 1.0.0
File Size Uploaded
compgraph2txt-1.0.0.tar.gz 10.3 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for compgraph2txt 1.0.0
File Interpreter ABI Platform
compgraph2txt-1.0.0-py3-none-any.whl Python 3 none any Details

Total release size: 18.7 kB

Release files / compgraph2txt-1.0.0.tar.gz

Download URL compgraph2txt-1.0.0.tar.gz
Size 10.3 kB
Tags Source
SHA-256 checksum
How to use checksums
6ddc615f68f7dbe1c23ffa9fd57e98b264118409f732a32da715f69fa9884514
BLAKE2b-256 checksum
How to use checksums
464ac04644fe0fff140dc34fdee460d2218df6602f89c62fd786cb9628fb13d2
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via python-httpx/0.23.3

Release files / compgraph2txt-1.0.0-py3-none-any.whl

Download URL compgraph2txt-1.0.0-py3-none-any.whl
Size 8.4 kB
Tags Python 3
SHA-256 checksum
How to use checksums
ff62a16c930df4a612813a45a8c4ccc4432159059b2b5132b07b7652e42fac3d
BLAKE2b-256 checksum
How to use checksums
03c22f93d53312e8b1428ea0a6f72de3b215b0218c79e4a1fcfb7dd3e4ac7a0d
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via python-httpx/0.23.3

Release history Release notifications | RSS feed

This release

1.0.0 This release

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page