-
Notifications
You must be signed in to change notification settings - Fork 13
feat: Add option to render a subgraph of a hugr. #2497
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
Conversation
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #2497 +/- ##
=======================================
Coverage 82.66% 82.67%
=======================================
Files 251 251
Lines 46644 46661 +17
Branches 42190 42190
=======================================
+ Hits 38559 38576 +17
Misses 6034 6034
Partials 2051 2051
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
mark-koch
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks, that's a very useful feature 👍
I'm not a big fan of the default dot rendering for external nodes:

Could you add those nodes manually and use self._format_html_label to get a matching style?
Also, would be good to add a snapshot test (e.g. see test_html_labels in hugr-py/tests/test_hugr_build.py)
hugr-py/src/hugr/hugr/render.py
Outdated
| self._viz_node(child, hugr, sub) | ||
| html_label = self._format_html_label(**label_config) | ||
| sub.node(f"{node.idx}", shape="plain", label=f"<{html_label}>") | ||
| self.nodes.add(node) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe hoist this out of the if statement since you're doing the same in both branches?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
mark-koch
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks!
Done: now looks like this (and we also avoid warnings from graphviz which is nice):
Done. |
🤖 I have created a release *beep* *boop* --- ## [0.13.1](hugr-py-v0.13.0...hugr-py-v0.13.1) (2025-08-18) ### Features * Add option to render a subgraph of a hugr. ([#2497](#2497)) ([c3370fe](c3370fe)) * **py:** implement `Sequence` protocol for qsys results/shots ([#2524](#2524)) ([b42e9df](b42e9df)) * Type of constants in `core` `Term`s. ([#2411](#2411)) ([2ba5764](2ba5764)) --- This PR was generated with [Release Please](https://github.com/googleapis/release-please). See [documentation](https://github.com/googleapis/release-please#release-please).
For moderately sized hugrs, rendering the whole hugr produces sprawling images that are difficult to analyse. This feature allows one to select a region to render.
Example output:
h_10.pdf