Skip to content

Conversation

@cqc-alec
Copy link
Collaborator

@cqc-alec cqc-alec commented Jul 30, 2025

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

@codecov
Copy link

codecov bot commented Jul 30, 2025

Codecov Report

❌ Patch coverage is 92.30769% with 2 lines in your changes missing coverage. Please review.
✅ Project coverage is 82.67%. Comparing base (9dd4af8) to head (b06c35b).
⚠️ Report is 1 commits behind head on main.

Files with missing lines Patch % Lines
hugr-py/src/hugr/hugr/base.py 66.66% 1 Missing ⚠️
hugr-py/src/hugr/hugr/render.py 95.65% 1 Missing ⚠️
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           
Flag Coverage Δ
python 91.38% <92.30%> (+0.03%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ 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.

@cqc-alec cqc-alec marked this pull request as ready for review July 30, 2025 12:28
@cqc-alec cqc-alec requested a review from a team as a code owner July 30, 2025 12:28
@cqc-alec cqc-alec requested a review from mark-koch July 30, 2025 12:28
Copy link
Contributor

@mark-koch mark-koch left a 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:
image
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)

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)
Copy link
Contributor

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?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Done.

Copy link
Contributor

@mark-koch mark-koch left a comment

Choose a reason for hiding this comment

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

Thanks!

@cqc-alec
Copy link
Collaborator Author

Could you add those nodes manually and use self._format_html_label to get a matching style?

Done: now looks like this (and we also avoid warnings from graphviz which is nice):

h_10.pdf

Also, would be good to add a snapshot test (e.g. see test_html_labels in hugr-py/tests/test_hugr_build.py)

Done.

@cqc-alec cqc-alec added this pull request to the merge queue Jul 30, 2025
Merged via the queue into main with commit c3370fe Jul 30, 2025
25 checks passed
@cqc-alec cqc-alec deleted the ae/order branch July 30, 2025 16:06
github-merge-queue bot pushed a commit that referenced this pull request Aug 18, 2025
🤖 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).
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