-
Notifications
You must be signed in to change notification settings - Fork 8
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: Mermaid renderer for hugrs #852
Conversation
Here's a render for a CFG: graph LR
subgraph 0 ["(0) CFG"]
direction LR
subgraph 2 ["(2) DataflowBlock"]
direction LR
3["(3) Input"]
3--0:0-->5
4["(4) Output"]
5["(5) MakeTuple"]
5--0:0-->6
6["(6) Tag"]
6--0:0-->4
end
2--0:0-->7
2--1:0-->1
1["(1) ExitBlock"]
subgraph 7 ["(7) DataflowBlock"]
direction LR
8["(8) Input"]
8--0:1-->9
9["(9) Output"]
10["(10) const:sum:{tag:0, val:const:seq:{}}"]
10--0:0-->11
11["(11) LoadConstant"]
11--0:0-->9
end
7--0:0-->1
end
I also tried adding the type to the edge labels. It's a bit more noisy, but probably more useful too. graph LR
subgraph 0 ["(0) CFG"]
direction LR
subgraph 2 ["(2) DataflowBlock"]
direction LR
3["(3) Input"]
3--"0:0<br>usize"-->5
4["(4) Output"]
5["(5) MakeTuple"]
5--"0:0<br>Tuple([usize])"-->6
6["(6) Tag"]
6--"0:0<br>Sum([Tuple([usize]), Tuple([usize])])"-->4
end
2--"0:0"-->7
2--"1:0"-->1
1["(1) ExitBlock"]
subgraph 7 ["(7) DataflowBlock"]
direction LR
8["(8) Input"]
8--"0:1<br>usize"-->9
9["(9) Output"]
10["(10) const:sum:{tag:0, val:const:seq:{}}"]
10--"0:0<br>Sum(UnitSum(1))"-->11
11["(11) LoadConstant"]
11--"0:0<br>Sum(UnitSum(1))"-->9
end
7--"0:0"-->1
end
And this is now the first example, with type info: graph LR
subgraph 0 ["(0) DFG"]
direction LR
1["(1) Input"]
1--"0:0<br>qubit([])"-->3
1--"1:1<br>qubit([])"-->3
2["(2) Output"]
3["(3) test.quantum.CX"]
3--"0:1<br>qubit([])"-->4
3--"1:0<br>qubit([])"-->4
3-."2:2".->4
4["(4) test.quantum.CX"]
4--"0:0<br>qubit([])"-->2
4--"1:1<br>qubit([])"-->2
end
|
drive-by: Flatten TOML section (my linter was complaining...)
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #852 +/- ##
==========================================
+ Coverage 84.04% 84.13% +0.09%
==========================================
Files 77 78 +1
Lines 14234 14261 +27
Branches 14234 14261 +27
==========================================
+ Hits 11963 11999 +36
+ Misses 1435 1427 -8
+ Partials 836 835 -1 ☔ View full report in Codecov by Sentry. |
src/hugr/views/snapshots/hugr__hugr__views__tests__mermaid_string.snap
Outdated
Show resolved
Hide resolved
Here's the CFG rendered in the new test: graph LR
subgraph 0 ["(0) CFG"]
direction LR
subgraph 2 ["(2) DataflowBlock"]
direction LR
3["(3) Input"]
3--"0:0<br>usize"-->5
4["(4) Output"]
5["(5) MakeTuple"]
5--"0:0<br>Tuple([usize])"-->6
6["(6) Tag"]
6--"0:0<br>Sum([Tuple([usize]), Tuple([usize])])"-->4
end
2-."0:0".->7
2-."1:0".->1
1["(1) ExitBlock"]
subgraph 7 ["(7) DataflowBlock"]
direction LR
8["(8) Input"]
8--"0:1<br>usize"-->9
9["(9) Output"]
10["(10) const:sum:{tag:0, val:const:seq:{}}"]
10--"0:0<br>Sum(UnitSum(1))"-->11
11["(11) LoadConstant"]
11--"0:0<br>Sum(UnitSum(1))"-->9
end
7-."0:0".->1
end
you can optionally hide the node indices, types, and ports now; graph LR
subgraph 0 ["CFG"]
direction LR
subgraph 2 ["DataflowBlock"]
direction LR
3["Input"]
3-->5
4["Output"]
5["MakeTuple"]
5-->6
6["Tag"]
6-->4
end
2-.->7
2-.->1
1["ExitBlock"]
subgraph 7 ["DataflowBlock"]
direction LR
8["Input"]
8-->9
9["Output"]
10["const:sum:{tag:0, val:const:seq:{}}"]
10-->11
11["LoadConstant"]
11-->9
end
7-.->1
end
|
- Fixes the failing unsoundness check in `main` https://github.com/CQCL/hugr/actions/runs/8158956607/job/22302072598 The test change in #852 moved the miri ignore flag, and it seems it has to be placed after `rstest`'s cases. - Adds a concurrency group for the unsoundness check. The check currently takes around 15mins (and it will only grow as we add more tests). This makes it so old jobs get cancelled when pushing new changes to main, and a new check is started.
Adds a
HugrView::mermaid_string
which produces things likeNote that edges in mermaid are unordered, so I had to add the port indices explicitly.
The new code in
src/hugr/views/render.rs
is just moved fromsrc/hugr/views.rs
.Closes #696
Requires CQCL/portgraph#125