From 3d409e01f3cb43f3add5c415c39fd75b88a70dbf Mon Sep 17 00:00:00 2001 From: Seyon Sivarajah Date: Fri, 15 Dec 2023 14:57:01 +0000 Subject: [PATCH] move test to rust and appply fix prev_nodes shouldn't have command itself in it probably a leftover of a historic approach --- tket2-py/test/test_pass.py | 12 ------------ tket2/src/passes/commutation.rs | 15 +++++++++++++-- 2 files changed, 13 insertions(+), 14 deletions(-) diff --git a/tket2-py/test/test_pass.py b/tket2-py/test/test_pass.py index 84b55c52c..cb3a8369c 100644 --- a/tket2-py/test/test_pass.py +++ b/tket2-py/test/test_pass.py @@ -64,18 +64,6 @@ def test_depth_optimise(): assert c.depth() == 2 -def test_depth_optimise_buggy(): - # bug https://github.com/CQCL/tket2/issues/253 - c = Circuit(3).H(2).CX(2, 1).CX(0, 2).CX(0, 1) - - assert c.depth() == 4 - - c, moves = greedy_depth_reduce(c) - assert moves == 1 - assert c == Circuit(3).H(2).CX(0, 1).CX(2, 1).CX(0, 2) - assert c.depth() == 3 - - @given(circ=circuits()) @settings(print_blob=True, deadline=30) def test_depth_hyp(circ: Circuit) -> None: diff --git a/tket2/src/passes/commutation.rs b/tket2/src/passes/commutation.rs index d5ae446f0..1182100f9 100644 --- a/tket2/src/passes/commutation.rs +++ b/tket2/src/passes/commutation.rs @@ -145,8 +145,7 @@ fn commutes_at_slice( circ: &impl HugrView, ) -> Option>> { // map from qubit to node it is connected to immediately after the free slice. - let mut prev_nodes: HashMap> = - HashMap::from_iter(command.qubits().map(|q| (q, command.clone()))); + let mut prev_nodes: HashMap> = HashMap::new(); for q in command.qubits() { // if slot is empty, continue checking. @@ -480,6 +479,17 @@ mod test { build().unwrap() } + // bug https://github.com/CQCL/tket2/issues/253 + fn cx_commute_bug() -> Hugr { + build_simple_circuit(3, |circ| { + circ.append(Tk2Op::H, [2])?; + circ.append(Tk2Op::CX, [2, 1])?; + circ.append(Tk2Op::CX, [0, 2])?; + circ.append(Tk2Op::CX, [0, 1])?; + Ok(()) + }) + .unwrap() + } fn slice_from_command( commands: &[ComCommand], n_qbs: usize, @@ -584,6 +594,7 @@ mod test { #[case(commutes_but_same_depth(), false, 1)] #[case(non_linear_inputs(), true, 1)] #[case(non_linear_outputs(), true, 1)] + #[case(cx_commute_bug(), true, 1)] fn commutation_example( #[case] mut case: Hugr, #[case] should_reduce: bool,