Skip to content
19 changes: 9 additions & 10 deletions tket-qsystem/tests/guppy_opt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -74,30 +74,29 @@ fn count_gates(h: &impl HugrView) -> HashMap<SmolStr, usize> {
///

#[rstest]
#[should_panic = "xfail"]
#[should_panic = "PytketDecodeError { inner: NoMatchingParameter"]
#[case::angles("angles", Some(vec![
("tket.quantum.Rz", 2), ("tket.quantum.MeasureFree", 1), ("tket.quantum.H", 2), ("tket.quantum.QAlloc", 1)
]))]
#[should_panic = "xfail"]
#[case::simple_cx("simple_cx", Some(vec![
("tket.quantum.QAlloc", 2), ("tket.quantum.MeasureFree", 2),
]))]
#[should_panic = "xfail"]
#[case::nested("nested", Some(vec![
("tket.quantum.CZ", 6), ("tket.quantum.QAlloc", 3), ("tket.quantum.MeasureFree", 3), ("tket.quantum.H", 6)
]))]
#[should_panic = "xfail"]
#[case::ranges("ranges", Some(vec![
("tket.quantum.H", 8), ("tket.quantum.MeasureFree", 4), ("tket.quantum.QAlloc", 4), ("tket.quantum.CX", 6)
]))]
//#[should_panic = "xfail"]
#[case::nested("nested", None)]
//#[should_panic = "xfail"]
#[case::ranges("ranges", None)]
#[should_panic = "xfail"]
#[case::false_branch("false_branch", Some(vec![
("TKET1.tk1op", 2), ("tket.quantum.QAlloc", 1), ("tket.quantum.MeasureFree", 1)
("TKET1.tk1op", 1), ("tket.quantum.H", 1), ("tket.quantum.QAlloc", 1), ("tket.quantum.MeasureFree", 1)
]))]
#[cfg_attr(miri, ignore)] // Opening files is not supported in (isolated) miri
fn optimise_guppy_pytket(#[case] name: &str, #[case] xfail: Option<Vec<(&str, usize)>>) {
let mut hugr = load_guppy_circuit(name, HugrFileType::Flat)
.unwrap_or_else(|_| load_guppy_circuit(name, HugrFileType::Original).unwrap());
// We don't need NormalizeGuppy to "flatten" control flow here, but we still want
// to get rid of other guppy artifacts.
NormalizeGuppy::default().run(&mut hugr).unwrap();
run_pytket(&mut hugr);
let should_xfail = xfail.is_some();
let expected_counts = match xfail {
Expand Down
8 changes: 7 additions & 1 deletion tket/src/passes/guppy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@ use hugr::algorithms::const_fold::{ConstFoldError, ConstantFoldPass};
use hugr::algorithms::inline_dfgs::InlineDFGsPass;
use hugr::algorithms::normalize_cfgs::{NormalizeCFGError, NormalizeCFGPass};
use hugr::algorithms::untuple::{UntupleError, UntupleRecursive};
use hugr::algorithms::{ComposablePass, RemoveDeadFuncsError, RemoveDeadFuncsPass, UntuplePass};
use hugr::algorithms::{
inline_acyclic, ComposablePass, RemoveDeadFuncsError, RemoveDeadFuncsPass, UntuplePass,
};
use hugr::hugr::hugrmut::HugrMut;
use hugr::hugr::patch::inline_dfg::InlineDFGError;
use hugr::Node;
Expand Down Expand Up @@ -70,6 +72,10 @@ impl<H: HugrMut<Node = Node> + 'static> ComposablePass<H> for NormalizeGuppy {
type Error = NormalizeGuppyErrors;
type Result = ();
fn run(&self, hugr: &mut H) -> Result<Self::Result, Self::Error> {
// We probably shouldn't inline quite as aggressively as this, but
// the results demonstrate how much we need to do at least some of it:
inline_acyclic(hugr, |_, _| true).unwrap();

if self.simplify_cfgs {
NormalizeCFGPass::default().run(hugr)?;
}
Expand Down
Loading