-
Notifications
You must be signed in to change notification settings - Fork 11
test: regenerate guppy_opt examples, and count gates #1249
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
Merged
Merged
Changes from 4 commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
563fc40
Count gates in whole Hugr after guppy opts but before pytket
acl-cqc e388a8f
regenerate guppy_optimization test hugrs...used guppylang 0.21.6
acl-cqc 416ace1
Update guppylang requirement (regeneration did nothing)
acl-cqc c921347
Correct counts
acl-cqc 8974ab5
count_gates returns map
acl-cqc b46f5a0
Merge remote-tracking branch 'origin/main' into HEAD
acl-cqc cc91af4
tidies
acl-cqc File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Binary file not shown.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
Binary file not shown.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file modified
BIN
+872 Bytes
(120%)
test_files/guppy_optimization/false_branch/false_branch.hugr
Binary file not shown.
Binary file modified
BIN
+609 Bytes
(110%)
test_files/guppy_optimization/false_branch/false_branch.opt.hugr
Binary file not shown.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
Binary file not shown.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
Binary file not shown.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
Binary file modified
BIN
+1013 Bytes
(120%)
test_files/guppy_optimization/simple_cx/simple_cx.opt.hugr
Binary file not shown.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -3,6 +3,7 @@ | |||||
| use std::fs; | ||||||
| use std::io::BufReader; | ||||||
| use std::path::Path; | ||||||
| use tket::extension::{TKET1_EXTENSION_ID, TKET_EXTENSION_ID}; | ||||||
|
|
||||||
| use hugr::algorithms::ComposablePass; | ||||||
| use hugr::{Hugr, HugrView}; | ||||||
|
|
@@ -44,19 +45,39 @@ fn guppy_simple_cx() -> Hugr { | |||||
| load_guppy_circuit("simple_cx") | ||||||
| } | ||||||
|
|
||||||
| fn count_gates(h: &impl HugrView) -> (usize, usize) { | ||||||
| let mut non_alloc = 0; | ||||||
| let mut alloc = 0; | ||||||
| for n in h.nodes() { | ||||||
| if let Some(eop) = h.get_optype(n).as_extension_op() { | ||||||
| if [TKET_EXTENSION_ID, TKET1_EXTENSION_ID].contains(eop.extension_id()) { | ||||||
| if ["tket.quantum.QFree", "tket.quantum.QAlloc"] | ||||||
| .contains(&eop.qualified_id().as_str()) | ||||||
| { | ||||||
| alloc += 1; | ||||||
| } else { | ||||||
| non_alloc += 1; | ||||||
| } | ||||||
| } | ||||||
| } | ||||||
| } | ||||||
| (non_alloc, alloc) | ||||||
| } | ||||||
|
|
||||||
| /// Run some simple optimization passes on the guppy-generated HUGRs and validate the result. | ||||||
| /// | ||||||
| /// This test is intended to check the current status of the Guppy optimization passes. | ||||||
| /// | ||||||
| #[rstest] | ||||||
| #[case::angles(guppy_angles())] | ||||||
| #[case::false_branch(guppy_false_branch())] | ||||||
| #[case::nested(guppy_nested())] | ||||||
| #[case::ranges(guppy_ranges())] | ||||||
| #[case::simple_cx(guppy_simple_cx())] | ||||||
| #[case::angles(guppy_angles(), (5, 1))] | ||||||
| #[case::false_branch(guppy_false_branch(), (3, 1))] | ||||||
| #[case::nested(guppy_nested(), (6, 3))] | ||||||
| #[case::ranges(guppy_ranges(), (8, 4))] | ||||||
| #[case::simple_cx(guppy_simple_cx(), (4, 2))] | ||||||
|
||||||
| #[cfg_attr(miri, ignore)] // Opening files is not supported in (isolated) miri | ||||||
| fn optimise_guppy(#[case] mut hugr: Hugr) { | ||||||
| fn optimise_guppy(#[case] mut hugr: Hugr, #[case] before: (usize, usize)) { | ||||||
|
||||||
| fn optimise_guppy(#[case] mut hugr: Hugr, #[case] before: (usize, usize)) { | |
| fn optimise_guppy(#[case] mut hugr: Hugr, #[case] before @ (_non_alloc, _alloc): (usize, usize)) { |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Could be nice to have a comment explaining what this is counting and why.
As we dicussed in person it could be nice to have a map with keys as OpType and number of instances of the optypes values