Skip to content

Commit

Permalink
test: Add small parallel badger test (#237)
Browse files Browse the repository at this point in the history
Timeout=0, so runtime impact is minimal, and it's kept deterministic;
the loop quits immediately and no rewrites are applied.
  • Loading branch information
aborgna-q authored Nov 10, 2023
1 parent 581350e commit d8a7bd5
Showing 1 changed file with 17 additions and 13 deletions.
30 changes: 17 additions & 13 deletions tket2/src/optimiser/badger.rs
Original file line number Diff line number Diff line change
Expand Up @@ -440,6 +440,13 @@ mod tests {

use super::{BadgerOptimiser, DefaultBadgerOptimiser};

/// Simplified description of the circuit's commands.
fn gates(circ: &Hugr) -> Vec<T2Op> {
circ.commands()
.map(|cmd| cmd.optype().try_into().unwrap())
.collect()
}

#[fixture]
fn rz_rz() -> Hugr {
let input_t = vec![QB_T, FLOAT64_TYPE, FLOAT64_TYPE];
Expand All @@ -466,18 +473,15 @@ mod tests {

#[rstest]
fn rz_rz_cancellation(rz_rz: Hugr, badger_opt: DefaultBadgerOptimiser) {
let opt_rz = badger_opt.optimise(&rz_rz, None, 1.try_into().unwrap(), false, 100);
let cmds = opt_rz
.commands()
.map(|cmd| {
(
cmd.optype().try_into().unwrap(),
cmd.inputs().count(),
cmd.outputs().count(),
)
})
.collect::<Vec<(T2Op, _, _)>>();
let exp_cmds = vec![(T2Op::AngleAdd, 2, 1), (T2Op::RzF64, 2, 1)];
assert_eq!(cmds, exp_cmds);
let opt_rz = badger_opt.optimise(&rz_rz, None, 1.try_into().unwrap(), false, 4);
// Rzs combined into a single one.
assert_eq!(gates(&opt_rz), vec![T2Op::AngleAdd, T2Op::RzF64]);
}

#[rstest]
fn rz_rz_cancellation_parallel(rz_rz: Hugr, badger_opt: DefaultBadgerOptimiser) {
let opt_rz = badger_opt.optimise(&rz_rz, Some(0), 2.try_into().unwrap(), false, 4);
// No optimization done due to the zero timeout.
assert_eq!(gates(&opt_rz), vec![T2Op::RzF64, T2Op::RzF64]);
}
}

0 comments on commit d8a7bd5

Please sign in to comment.