Skip to content
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file modified test_files/guppy_optimization/angles/angles.flat.hugr
Binary file not shown.
2 changes: 1 addition & 1 deletion test_files/guppy_optimization/angles/angles.flat.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# /// script
# requires-python = ">=3.13"
# dependencies = [
# "guppylang >=0.21.3",
# "guppylang >=0.21.6",
# ]
# ///

Expand Down
Binary file modified test_files/guppy_optimization/angles/angles.hugr
Binary file not shown.
Binary file modified test_files/guppy_optimization/angles/angles.opt.hugr
Binary file not shown.
2 changes: 1 addition & 1 deletion test_files/guppy_optimization/angles/angles.opt.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# /// script
# requires-python = ">=3.13"
# dependencies = [
# "guppylang >=0.21.3",
# "guppylang >=0.21.6",
# ]
# ///

Expand Down
2 changes: 1 addition & 1 deletion test_files/guppy_optimization/angles/angles.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# /// script
# requires-python = ">=3.13"
# dependencies = [
# "guppylang >=0.21.3",
# "guppylang >=0.21.6",
# ]
# ///

Expand Down
Binary file modified test_files/guppy_optimization/false_branch/false_branch.hugr
Binary file not shown.
Binary file modified test_files/guppy_optimization/false_branch/false_branch.opt.hugr
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# /// script
# requires-python = ">=3.13"
# dependencies = [
# "guppylang >=0.21.3",
# "guppylang >=0.21.6",
# ]
# ///

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# /// script
# requires-python = ">=3.13"
# dependencies = [
# "guppylang >=0.21.3",
# "guppylang >=0.21.6",
# ]
# ///

Expand Down
Binary file modified test_files/guppy_optimization/nested/nested.flat.hugr
Binary file not shown.
2 changes: 1 addition & 1 deletion test_files/guppy_optimization/nested/nested.flat.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# /// script
# requires-python = ">=3.13"
# dependencies = [
# "guppylang >=0.21.3",
# "guppylang >=0.21.6",
# ]
# ///

Expand Down
Binary file modified test_files/guppy_optimization/nested/nested.hugr
Binary file not shown.
Binary file modified test_files/guppy_optimization/nested/nested.opt.hugr
Binary file not shown.
2 changes: 1 addition & 1 deletion test_files/guppy_optimization/nested/nested.opt.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# /// script
# requires-python = ">=3.13"
# dependencies = [
# "guppylang >=0.21.3",
# "guppylang >=0.21.6",
# ]
# ///

Expand Down
2 changes: 1 addition & 1 deletion test_files/guppy_optimization/nested/nested.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# /// script
# requires-python = ">=3.13"
# dependencies = [
# "guppylang >=0.21.3",
# "guppylang >=0.21.6",
# ]
# ///

Expand Down
Binary file modified test_files/guppy_optimization/ranges/ranges.flat.hugr
Binary file not shown.
2 changes: 1 addition & 1 deletion test_files/guppy_optimization/ranges/ranges.flat.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# /// script
# requires-python = ">=3.13"
# dependencies = [
# "guppylang >=0.21.3",
# "guppylang >=0.21.6",
# ]
# ///

Expand Down
Binary file modified test_files/guppy_optimization/ranges/ranges.hugr
Binary file not shown.
Binary file modified test_files/guppy_optimization/ranges/ranges.opt.hugr
Binary file not shown.
2 changes: 1 addition & 1 deletion test_files/guppy_optimization/ranges/ranges.opt.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# /// script
# requires-python = ">=3.13"
# dependencies = [
# "guppylang >=0.21.3",
# "guppylang >=0.21.6",
# ]
# ///

Expand Down
2 changes: 1 addition & 1 deletion test_files/guppy_optimization/ranges/ranges.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# /// script
# requires-python = ">=3.13"
# dependencies = [
# "guppylang >=0.21.3",
# "guppylang >=0.21.6",
# ]
# ///

Expand Down
Binary file modified test_files/guppy_optimization/simple_cx/simple_cx.hugr
Binary file not shown.
Binary file modified test_files/guppy_optimization/simple_cx/simple_cx.opt.hugr
Binary file not shown.
2 changes: 1 addition & 1 deletion test_files/guppy_optimization/simple_cx/simple_cx.opt.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# /// script
# requires-python = ">=3.13"
# dependencies = [
# "guppylang >=0.21.3",
# "guppylang >=0.21.6",
# ]
# ///

Expand Down
2 changes: 1 addition & 1 deletion test_files/guppy_optimization/simple_cx/simple_cx.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# /// script
# requires-python = ">=3.13"
# dependencies = [
# "guppylang >=0.21.3",
# "guppylang >=0.21.6",
# ]
# ///

Expand Down
33 changes: 27 additions & 6 deletions tket-qsystem/tests/guppy_opt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};
Expand Down Expand Up @@ -44,19 +45,39 @@ fn guppy_simple_cx() -> Hugr {
load_guppy_circuit("simple_cx")
}

fn count_gates(h: &impl HugrView) -> (usize, usize) {
Copy link
Contributor

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

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))]
Copy link
Collaborator

Choose a reason for hiding this comment

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

👍

#[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)) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Try to document the tuple values?

It could be two parameters, or a helper Counts struct instead

Suggested change
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)) {

NormalizeGuppy::default().run(&mut hugr).unwrap();
assert_eq!(count_gates(&hugr), before);

// TODO: Run pytket passes here, and check that the circuit is as optimized as possible at this point.
//
Expand Down
Loading