Skip to content

Visualization Outputs

PyRapide provides multiple output formats for rendering causal computations. Each format serves a different use case, from interactive documentation to terminal debugging.


to_dot

Exports the computation as a Graphviz DOT string. Use this to generate publication-quality SVG or PNG diagrams of causal graphs.

to_dot.py python
from pyrapide import to_dot

dot_string = to_dot(computation)
print(dot_string)

# Output:
# digraph computation {
#   rankdir=LR;
#   node [shape=box, style=rounded];
#   evt_001 [label="Sensor.reading"];
#   evt_002 [label="Alerter.alert"];
#   evt_001 -> evt_002 [label="causes"];
# }
render_svg.py python
# Render to SVG with Graphviz
import subprocess

dot_string = to_dot(computation)
result = subprocess.run(
    ["dot", "-Tsvg"],
    input=dot_string,
    capture_output=True,
    text=True
)
with open("causal_graph.svg", "w") as f:
    f.write(result.stdout)

to_mermaid

Exports the computation as a Mermaid diagram string. Ideal for embedding in Markdown documentation, GitHub issues, or any platform that supports Mermaid rendering.

to_mermaid.py python
from pyrapide import to_mermaid

mermaid_string = to_mermaid(computation)
print(mermaid_string)

# Output:
# graph LR
#   evt_001["Sensor.reading"]
#   evt_002["Alerter.alert"]
#   evt_001 --> evt_002

to_json

Exports the computation as a structured JSON object. This is equivalent to serialize_computation but formatted for human readability.

to_json.py python
from pyrapide import to_json

json_string = to_json(computation, indent=2)
print(json_string)

to_ascii

Renders a compact ASCII representation of the causal graph, suitable for terminal output and log files.

to_ascii.py python
from pyrapide import to_ascii

print(to_ascii(computation))

# Output:
# Sensor.reading ──causes──> Alerter.alert
#       │
#       └──causes──> Logger.log_entry
💡 Tip
to_ascii is especially useful for quick debugging in the terminal or for including causal graphs in plain-text log files and CI output.

summary

Returns a human-readable text summary of the computation, including event counts, causal density, constraint results, and the critical path.

summary.py python
from pyrapide import summary

print(summary(computation))

# Output:
# Computation Summary
# ═══════════════════
# Events:          47
# Causal edges:    63
# Causal density:  0.058
# Critical path:   5 events
# Constraints:     3 satisfied, 0 violated
#
# Critical path:
#   1. UserRequest.submit
#   2. Database.query
#   3. Database.result
#   4. Renderer.format
#   5. Response.send

Next Steps