Skip to main content

Visualize computational graphs in the terminal.

Project description

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        │
  ╰───────────────╯

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

compgraph2txt-1.0.0.tar.gz (10.3 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

compgraph2txt-1.0.0-py3-none-any.whl (8.4 kB view details)

Uploaded Python 3

File details

Details for the file compgraph2txt-1.0.0.tar.gz.

File metadata

  • Download URL: compgraph2txt-1.0.0.tar.gz
  • Upload date:
  • Size: 10.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: python-httpx/0.23.3

File hashes

Hashes for compgraph2txt-1.0.0.tar.gz
Algorithm Hash digest
SHA256 6ddc615f68f7dbe1c23ffa9fd57e98b264118409f732a32da715f69fa9884514
MD5 a40c7b0c0529db9a579eef4b408b921f
BLAKE2b-256 464ac04644fe0fff140dc34fdee460d2218df6602f89c62fd786cb9628fb13d2

See more details on using hashes here.

File details

Details for the file compgraph2txt-1.0.0-py3-none-any.whl.

File metadata

File hashes

Hashes for compgraph2txt-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 ff62a16c930df4a612813a45a8c4ccc4432159059b2b5132b07b7652e42fac3d
MD5 5a972ad118e5ab7d7604c069482a9378
BLAKE2b-256 03c22f93d53312e8b1428ea0a6f72de3b215b0218c79e4a1fcfb7dd3e4ac7a0d

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page