GPU-accelerated differentiable graph layout engine built on PyTorch
Project description
dagua
GPU-accelerated differentiable graph layout engine built on PyTorch.
DAG + agua. Directed acyclic graphs + water. Named after the Dagua River in Colombia — a river flows downhill (like a DAG), never cycles back (acyclic), and finds its own path through the landscape (like gradient descent finding optimal node positions).
Why?
Graphviz has dominated graph visualization for 30 years but has hard scaling limits. No existing Python package provides pip-installable, hierarchical (Sugiyama-style) graph layout. Dagua fills this gap: pip install dagua, pure Python + PyTorch, GPU-accelerated, hierarchical layout with composable constraints.
Status
Pre-alpha. Under active development.
Fast status references:
CLI
The package now ships with a small CLI:
dagua benchmark-status --output-dir eval_output --suite standard
dagua benchmark-watch --output-dir eval_output --suite standard --follow --interval 15
dagua benchmark-list --output-dir eval_output --suite standard
dagua benchmark-show residual_block --output-dir eval_output --suite standard --competitor dagua
dagua benchmark-report --output-dir eval_output --no-pdf
dagua benchmark-deltas --output-dir eval_output
dagua benchmark-freeze baseline-a --output-dir eval_output --suite standard
dagua benchmark-compare-runs 2026-03-12T00:00:00+00:00 2026-03-12T01:00:00+00:00 --output-dir eval_output
For cinematic exports:
dagua poster graph.yaml poster.png --scene powers_of_ten --device cuda
dagua tour graph.yaml trailer.mp4 --scene zoom_pan --device cuda
For the exhaustive reference manual:
python scripts/build_glossary.py --output-dir docs/glossary
That command regenerates the LaTeX source, explanatory visuals, manifest, and PDF
when pdflatex is available.
You can also render directly from saved benchmark positions, which is useful for large graphs where you do not want to relayout just to produce a poster or tour:
dagua poster graph.yaml /tmp/residual.png \
--benchmark-graph residual_block \
--benchmark-suite standard \
--competitor dagua \
--output-dir eval_output
Serialization Defaults
For human-authored graph and theme specs, use YAML by default.
For generated artifacts and machine-facing outputs, use JSON by default.
In other words:
- YAML for humans
- JSON for machines
Agent Guide
This repo includes a public, user-facing guide for LLMs and coding agents using Dagua:
It is separate from CLAUDE.md / AGENTS.md, which are for developing the repo itself.
The LLM tutorial is the short, task-oriented entrypoint for agents that want to build,
layout, render, and export graphs efficiently.
Image To Graph / Theme
Dagua can also turn a graph screenshot or reference visualization into:
- a
DaguaGraph - a raw graph/theme dict
- best-practice Dagua code
- a
Theme
Canonical setup:
import dagua
dagua.configure_image_ai(provider="openai", api_key_env="OPENAI_API_KEY")
Then use whichever return mode you want:
graph = dagua.from_image("diagram.png")
graph_dict = dagua.graph_dict_from_image("diagram.png")
graph_code = dagua.graph_code_from_image("diagram.png")
graph_script = dagua.graph_code_from_image("diagram.png", include_demo_script=True)
theme = dagua.theme_from_image("diagram.png")
theme_dict = dagua.theme_dict_from_image("diagram.png")
theme_code = dagua.theme_code_from_image("diagram.png")
Supported common formats include:
- PNG
- JPEG
- GIF
- WebP
- BMP
- TIFF
- SVG
The code-return helpers intentionally emit the cleaner Dagua style:
- default: reusable builder code with explicit
add_node/add_edge/add_cluster - optional: a polished ready-to-run demo script with layout and export already wired in
FAQ
What is Dagua different from?
Dagua is most directly comparable to:
- Graphviz
dot - ELK layered
- dagre
- other hierarchical / Sugiyama-style layout tools
It is less like:
- force-directed tools such as NetworkX spring layout or Graphviz
sfdp
What is different about Dagua vs Graphviz, ELK, or dagre?
The main difference is architectural.
Those tools are largely heuristic rule-based layout engines. Dagua treats layout as continuous optimization:
- node positions are optimized with PyTorch
- aesthetics are loss terms
- GPU acceleration is available naturally
- constraints like pins, alignment, spacing preferences, and cluster behavior fit into the same framework
So the point of Dagua is not just “another graph drawer.” The point is:
- hierarchical layout
- Python-native workflow
- inspectable optimization behavior
- composable constraints
- scaling paths that can exploit modern accelerators
When should I use Dagua instead of Graphviz?
Use Dagua when you want:
- a Python-native hierarchical layout tool
- GPU acceleration
- cinematic exports, optimization animations, or large-graph tours
- constraint-style control over layout behavior
- one library that covers graph creation, optimization, and visualization together
Use Graphviz when you want:
- a mature external tool with decades of ecosystem history
- quick static output and you are already happy with its workflow
Is Dagua a force-directed layout library?
No. It uses optimization internally, but the intended visual language is hierarchical / layered DAG layout, not generic force-directed blob layout.
Do I have to call layout() manually?
No for the basic case.
fig, ax = dagua.draw(g)
draw() is the convenience path and will lay out the graph for you.
Use layout() explicitly when you want to:
- inspect positions
- render multiple times from the same layout
- intervene between layout and rendering
- route edges or place labels manually
What happens if I change the graph after layout?
Dagua now tracks layout lifecycle state.
If you mutate the graph structure or relevant styles:
- cached layout-derived artifacts are invalidated
draw()will naturally relayout- explicit stale usage is easier to detect and reason about
This is intentional: the basic path should feel automatic, but not magical in a way you cannot inspect.
Can I inspect what the optimizer did?
Yes.
Useful surfaces include:
dagua.layout(...)for direct positions- optimization animations via
dagua.animate(...) - cinematic stills and tours via
dagua.poster(...)anddagua.tour(...) - graph lifecycle state such as cached layout freshness
Does Dagua support clusters and nested clusters?
Yes.
Recommended hand-authored pattern:
- add nodes first
- then add clusters by node id
Declarative hierarchy is also supported, but for handwritten Python code the bottom-up pattern is usually clearer.
Can Dagua handle large graphs?
Yes. Large-scale support is a core part of the project.
That said, there are different regimes:
- small and medium graphs: normal interactive/programmatic usage
- large graphs: multilevel layout and benchmark/scaling tooling
- huge graphs: dedicated poster/tour workflows and large-graph rendering strategies
If your goal is “show off a giant graph,” use:
dagua.poster(...)dagua.tour(...)
instead of trying to treat a giant graph like a tiny static diagram.
Is Dagua only for machine learning graphs?
No.
ML systems are an important use case, but the same API is meant for:
- workflow graphs
- business processes
- dependency graphs
- architecture diagrams
- logistics / operations flows
- any structured directed graph where layered layout is useful
Is there documentation for humans and agents separately?
Yes.
For humans:
- docs index: docs/README.md
- developer overview: docs/DEVELOPER_OVERVIEW.md
- tutorial notebook: docs/tutorial_walkthrough.ipynb
- interactive tuning playground: docs/interactive_playground.ipynb
- glossary/reference: docs/glossary/dagua_glossary.pdf
- how Dagua works: docs/how_dagua_works.md
- showcase gallery: docs/gallery/README.md
- video resources: docs/video/README.md
For agents using Dagua:
For agents developing the repo itself:
CLAUDE.md/AGENTS.md
License
MIT
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
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file dagua-0.1.0.tar.gz.
File metadata
- Download URL: dagua-0.1.0.tar.gz
- Upload date:
- Size: 277.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
953e707aaa2ac2322495b87cbf89ce67d548eaa279ef957c31210cddd124c27c
|
|
| MD5 |
3458fc864eebb6ba0f2a858d60056798
|
|
| BLAKE2b-256 |
e2d26c7c643af0b8bb50cab9be62e635235380ba838215dd8548c9aa27bee0ae
|
File details
Details for the file dagua-0.1.0-py3-none-any.whl.
File metadata
- Download URL: dagua-0.1.0-py3-none-any.whl
- Upload date:
- Size: 262.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
435cd0c700a3eb7c920fddcf3d917646655d12411fdc15a238e04cbbb936dda2
|
|
| MD5 |
0389f239be6031be57a796f79a707689
|
|
| BLAKE2b-256 |
db57a06e2ee0fd81cad223f399caa4c518ebf83d0df2545434786fd8c70f3934
|