Improved Pattern.draw_graph visualization#444
Improved Pattern.draw_graph visualization#444CodeMaverick2 wants to merge 18 commits intoTeamGraphix:masterfrom
Conversation
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #444 +/- ##
==========================================
+ Coverage 88.29% 88.38% +0.09%
==========================================
Files 44 44
Lines 6535 6596 +61
==========================================
+ Hits 5770 5830 +60
- Misses 765 766 +1 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
|
CI fails on Python 3.10–3.13 due to a pre-existing bug in the veriphix reverse dependency, unrelated to this PR. Passes on Python 3.14 because veriphix is excluded from that version. All graphix tests and other reverse dependencies pass. |
|
Veriphix CI is now fixed. It's all green now! |
|
Hey @thierry-martinez, could someone from the team please review my PR and let me know if any changes are required |
|
Hi @CodeMaverick2 can you please post a few example outputs here? It will make it easier for us to review the updates you have made to the visual style. |
|
@emlynsg here are a few examples using the pattern from the issue: With measurements + legend (show_measurements=True, show_legend=True): From pattern with X/Z corrections (flow_from_pattern=True, show_measurements=True, show_legend=True): |
|
@emlynsg Let me know if there's any changes required Happy to address them |
|
Hi @CodeMaverick2 , thanks for the continued good work. Appreciate your flexibility, visual PRs are definitely hard because of how much trial-and-error is involved.
Thanks! |
|
@emlynsg Thanks for the detailed feedback. Here are the changes addressing each point:
Example outputs: Basic graph (draw_graph(flow_from_pattern=False)):
With measurement labels (show_measurements=True):
Measurements + legend (show_measurements=True, show_legend=True):
From pattern with corrections (flow_from_pattern=True, show_measurements=True, show_legend=True):
With show_measurement_order=False:
|
|
Hi @CodeMaverick2 , some more comments for you:
At a higher level, it is important you are continuing to compare back to the existing plot design in Graphix and convincing yourself that your changes have improved the readability of the plots. Since we hope to start moving towards a PR we can accept this week, I would like you to choose a small and a larger graph (i.e. one with say <8 nodes, and another with ~20 nodes), and compare side-by-side with the existing Graphix plots in your PR updates. This will give you a chance to see where you might make some further improvements (for which you can update the PR), and will give us (the maintainer team) what we need to review. |
|
@emlynsg Thanks for the detailed feedback. Here are the changes addressing each point:
Side-by-side comparison with existing Graphix plots:Small graph (~7 nodes):Existing:
Updated:
Large graph (~20 nodes):Existing:
Updated:
With show_measurement_order=False:Small:
Large:
|
|
Hi @CodeMaverick2, thanks for the continued engagement. |
|
@emlynsg Thanks for the feedback. This time I explored multiple visual variants systematically testing different combinations of label positions, layer indicators, and edge styles side-by-side against the original to find the best approach. What changed in this update:
Side-by-side comparison: Small graph - Updated:
Large graph - Original:
Large graph -Updated:
On arrowhead placement: The arrow routing code is identical to master arrows behave exactly the same as the original. Modifying the pathfinding algorithm |
|
@emlynsg I think the plots are now much closer to publication quality rather than debugging-style visuals 😄 Would love your thoughts! |
|
Hi @CodeMaverick2 , looking better, well done! I think we're nearly there.
FYI Unitary are happy for us to finalise this by early next week so we have a few days to pull it into a final product. |
|
@emlynsg Thanks for the feedback! Here are the changes addressing each point: 1. Explicit measurement angles - Removed the zero-angle shorthand. All measurements now show their angle explicitly (e.g. 2. Label anchoring adjusted - Reduced the left/right label offset from 0.22 to 0.15 data units so labels sit closer to their nodes when placed to the side. The above-node offset (0.22) is unchanged since it was already a good distance. 3. Narrower layers - Reduced the per-layer figure width multiplier from 0.8 to 0.7, making layers more compact without being as tight as the original where labels overlapped layer lines. 4. Vertical fractions - Measurement angles now render as proper stacked fractions using matplotlib's mathtext (e.g. π over 3 instead of π/3), saving horizontal space. 5. Node number centering - Switched from 6. Arrowhead placement diagnosed - The root cause was a Side-by-side comparison : Small graph - Master:
Small graph - Updated:
Large graph - Master:
Large graph - Updated:
|
|
@emlynsg Small follow-up - noticed nodes 5-6 had overlapping measurement labels in the small graph from my previous comment. Fixed this by making the adaptive label placement also track already-placed labels as obstacles, so adjacent nodes no longer merge their labels together Updated image: Small graph - Updated (label overlap fixed):
|

























Before submitting, please check the following:
nox)ruffCONTRIBUTING.mdfor more detailsThen, please fill in below:
Context (if applicable):
Description of the change:
From issue -
Generated with PR changes -
The first image (before) is the example from the issue; the second (after) is the same pattern rendered with this PR.
Inputs (node 1) are now squares instead of red circles, measured nodes are filled black, Pauli-measured nodes (node 3) are blue, and outputs (2, 6, 7) are empty circles.
Dashed layer separators are replaced by a horizontal arrow with layer labels.
Measurement labels show plane and angle (e.g. XZ(π/10)).
Graph edges (light dashed) are visually distinct from correction arrows (solid). A legend explains all visual elements.
Related issue:
#387