Skip to content

Add new visualization tools#479

Merged
matulni merged 26 commits into
TeamGraphix:masterfrom
matulni:vis-rf-2
Apr 22, 2026
Merged

Add new visualization tools#479
matulni merged 26 commits into
TeamGraphix:masterfrom
matulni:vis-rf-2

Conversation

@matulni
Copy link
Copy Markdown
Contributor

@matulni matulni commented Apr 10, 2026

This PR adds new visualization methods: OpenGraph.draw, PauliFlow.draw and XZCorrections.draw. Further, the method Pattern.draw_graph is replaced by Pattern.draw with an annotations parameter which allows to visualise the underlying open graph, flow or xz corrections.

This PR does not modify the core logic of the existing visualization tools. However, two stylistic modifications are made: input nodes are represented with squares instead of red-edge circles and it incorporates the layer visualisation introduced in #444.

TODO

Update README with new figure.

@codecov
Copy link
Copy Markdown

codecov Bot commented Apr 10, 2026

Codecov Report

❌ Patch coverage is 95.93496% with 20 lines in your changes missing coverage. Please review.
✅ Project coverage is 89.28%. Comparing base (633588f) to head (21ec4f8).
⚠️ Report is 2 commits behind head on master.

Files with missing lines Patch % Lines
graphix/visualization.py 95.70% 19 Missing ⚠️
graphix/pattern.py 97.36% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master     #479      +/-   ##
==========================================
+ Coverage   88.75%   89.28%   +0.53%     
==========================================
  Files          46       46              
  Lines        6749     6841      +92     
==========================================
+ Hits         5990     6108     +118     
+ Misses        759      733      -26     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Comment thread graphix/pattern.py Outdated
Comment thread graphix/visualization.py

g = flow.correction_function
# Draw horizontal arrow indicating measurement order with "Layer" label below
offset = mtransforms.ScaledTranslation(0, -27 / 72, fig.dpi_scale_trans)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe better to save for further work later, but I think shifting the layers arrow down a little would be nicer - further from the nodes, and leaving less white space before the border of the plot.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Mmm, yes, I'm not happy with this solution. It's not super robust: if you tweak the node distance, the arrow can appear outside the plot. I couldn't figure out how to make it work in all cases, but I think that the layer arrow is a nice addition regardless. Maybe we could fill an issue and leave this detail (together with your suggestion) for the backlog?

Comment thread docs/source/visualization.rst Outdated
Comment thread examples/visualization.py Outdated
Comment thread graphix/flow/core.py Outdated
Comment thread graphix/pattern.py Outdated
Comment thread graphix/visualization.py
Comment thread graphix/pattern.py Outdated
Comment thread graphix/pattern.py Outdated
Comment thread graphix/visualization.py Outdated
Comment on lines +245 to +257
# We can't use functools.singledispatch here.
# If we annotate the dispatch argument with CausalFlow[AbstractPlanarMeasurement]
# compilation will fail because generic types are only known statically.
# If we don't specify the generic type (we don't need to), mypy will complain.

# Circumvent import loop
from graphix.flow.core import CausalFlow # noqa: PLC0415

pos = (
_compute_positions_causal_flow(flow)
if isinstance(flow, CausalFlow)
else _compute_positions_partial_order(flow)
)
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am not particularly fond of singledispatch, but if we want to use it here, we can do as I did in this commit (by explicitly passing a type as an argument to register): thierry-martinez@179d683

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh very nice, I did't know register accepted arguments. Don't you think it's nicer with singledispatch? It avoids the import inside the function...

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have no strong opinion on this, but note that we still have import loops with singledispatch. from graphix.flow.core import CausalFlow should be moved to the top level indeed, but that forces GraphVisualizer to be imported inside the draw methods in flow/core.py to break the import loop (though, admittedly, this seems more logical this way). Additionally, I'm not sure what a good name would be for merging _compute_positions_causal_flow and _compute_positions_partial_order (and should we keep _compute_positions_opengraph separate?).

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we went this way, we could merge all three functions into a single one: _compute_positions. I think it makes sense since these three functions do the same thing (in different ways, suitable for different scenarios), but it may make the code less readable...

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done in ab396cb

Comment thread graphix/visualization.py Outdated
Copy link
Copy Markdown
Collaborator

@thierry-martinez thierry-martinez left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM! Thanks, the visualization API is much better that way!

Comment thread graphix/visualization.py Outdated
Co-authored-by: thierry-martinez <thierry.martinez@inria.fr>
Copy link
Copy Markdown
Contributor

@emlynsg emlynsg left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

@matulni matulni merged commit bc0b507 into TeamGraphix:master Apr 22, 2026
24 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants