Skip to content

Commit

Permalink
move test to rust and appply fix
Browse files Browse the repository at this point in the history
prev_nodes shouldn't have command itself in it

probably a leftover of a historic approach
  • Loading branch information
ss2165 committed Dec 15, 2023
1 parent a709e1a commit 4f1496f
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 14 deletions.
12 changes: 0 additions & 12 deletions tket2-py/test/test_pass.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
15 changes: 13 additions & 2 deletions tket2/src/passes/commutation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -145,8 +145,7 @@ fn commutes_at_slice(
circ: &impl HugrView,
) -> Option<HashMap<Qb, Rc<ComCommand>>> {
// map from qubit to node it is connected to immediately after the free slice.
let mut prev_nodes: HashMap<Qb, Rc<ComCommand>> =
HashMap::from_iter(command.qubits().map(|q| (q, command.clone())));
let mut prev_nodes: HashMap<Qb, Rc<ComCommand>> = HashMap::new();

for q in command.qubits() {
// if slot is empty, continue checking.
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down

0 comments on commit 4f1496f

Please sign in to comment.