gds_viz.mermaid¶
Core Mermaid syntax generation — flowchart and subgraph building utilities.
Lightweight visualization utilities for GDS systems.
Generates Mermaid flowchart diagrams from SystemIR or Block compositions. Mermaid diagrams can be rendered in: - GitHub markdown - GitLab markdown - VS Code markdown preview - mermaid.live - Any tool with Mermaid support
The module provides two visualization strategies:
-
Flat diagrams (
system_to_mermaid()) — show the compiled block structure with automatic shape/arrow styling based on block roles and wiring types. -
Architecture-aware diagrams — domain-specific visualizations that encode semantic information (agent/environment boundaries, private/public data flow, stateful vs stateless components). See examples/prisoners_dilemma/visualize.py for a reference implementation.
system_to_mermaid(system, show_hierarchy=False, *, theme=None)
¶
Generate a Mermaid flowchart from a SystemIR.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
system
|
SystemIR
|
The compiled system to visualize. |
required |
show_hierarchy
|
bool
|
If True, uses the hierarchy tree to organize subgraphs. If False, renders a flat graph of all blocks. |
False
|
theme
|
MermaidTheme | None
|
Mermaid theme — one of 'default', 'neutral', 'dark', 'forest', 'base'. None uses the default ('neutral'). |
None
|
Returns:
| Type | Description |
|---|---|
str
|
Mermaid flowchart diagram as a string. |
Example
Source code in packages/gds-viz/gds_viz/mermaid.py
block_to_mermaid(block, *, theme=None)
¶
Generate a Mermaid flowchart from a Block composition tree.
This is a convenience wrapper that flattens the block and creates a minimal diagram showing the composition structure.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
block
|
Block
|
The root block (atomic or composite). |
required |
theme
|
MermaidTheme | None
|
Mermaid theme — one of 'default', 'neutral', 'dark', 'forest', 'base'. None uses the default ('neutral'). |
None
|
Returns:
| Type | Description |
|---|---|
str
|
Mermaid flowchart diagram as a string. |
Example
from gds.blocks.roles import BoundaryAction, Policy, Mechanism
from gds.types.interface import Interface, port
from gds_viz import block_to_mermaid
observe = BoundaryAction(
name="Observe",
interface=Interface(forward_out=(port("Signal"),))
)
decide = Policy(
name="Decide",
interface=Interface(
forward_in=(port("Signal"),),
forward_out=(port("Action"),)
)
)
update = Mechanism(
name="Update",
interface=Interface(forward_in=(port("Action"),)),
updates=[("Entity", "state")]
)
pipeline = observe >> decide >> update
print(block_to_mermaid(pipeline))