Skip to content

Commit

Permalink
Add comments
Browse files Browse the repository at this point in the history
  • Loading branch information
lmondada committed Oct 4, 2023
1 parent dc699af commit 05c495f
Showing 1 changed file with 21 additions and 5 deletions.
26 changes: 21 additions & 5 deletions tests/taso_termination.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,24 +9,40 @@ mod require_portmatching {
};
use tket_json_rs::circuit_json::SerialCircuit;

/// A set of equivalence circuit classes (ECC)
///
/// This is the complete set of ECCs for 2-qubit circuits with up to
/// 4 gates, using the NAM gateset (CX, Rz, H).
#[fixture]
fn nam_4_2() -> DefaultTasoOptimiser {
// TasoOptimiser::default_with_rewriter_binary("test_files/nam_4_2.rwr").unwrap()
TasoOptimiser::default_with_eccs_json_file("test_files/Nam_4_2_complete_ECC_set.json")
.unwrap()
}

/// The following circuit
/// ┌──────────┐ ┌───────────┐
///q_0: ──■──┤ Rz(π/10) ├──■─────────────────────────■────■──┤ Rz(-π/10) ├
/// │ └──────────┘┌─┴─┐┌───┐┌─────────┐┌───┐┌─┴─┐ │ └───────────┘
///q_1: ──┼──────────────┤ X ├┤ H ├┤ Rz(π/5) ├┤ H ├┤ X ├──┼───────────────
/// ┌─┴─┐ └───┘└───┘└─────────┘└───┘└───┘┌─┴─┐
///q_2: ┤ X ├───────────────────────────────────────────┤ X ├─────────────
/// └───┘ └───┘
#[fixture]
fn simple_circ() -> Hugr {
let json = r#"
{"bits": [], "commands": [{"args": [["q", [0]], ["q", [2]]], "op": {"type": "CX"}}, {"args": [["q", [0]]], "op": {"params": ["0.1"], "type": "Rz"}}, {"args": [["q", [0]], ["q", [1]]], "op": {"type": "CX"}}, {"args": [["q", [1]]], "op": {"type": "H"}}, {"args": [["q", [1]]], "op": {"params": ["0.2"], "type": "Rz"}}, {"args": [["q", [1]]], "op": {"type": "H"}}, {"args": [["q", [0]], ["q", [1]]], "op": {"type": "CX"}}, {"args": [["q", [0]], ["q", [2]]], "op": {"type": "CX"}}, {"args": [["q", [0]]], "op": {"params": ["-0.1"], "type": "Rz"}}], "created_qubits": [], "discarded_qubits": [], "implicit_permutation": [[["q", [0]], ["q", [0]]], [["q", [1]], ["q", [1]]], [["q", [2]], ["q", [2]]]], "phase": "0.0", "qubits": [["q", [0]], ["q", [1]], ["q", [2]]]}
"#;
// The TK1 json of the circuit
let json = r#"{
"bits": [],
"commands": [{"args": [["q", [0]], ["q", [2]]], "op": {"type": "CX"}}, {"args": [["q", [0]]], "op": {"params": ["0.1"], "type": "Rz"}}, {"args": [["q", [0]], ["q", [1]]], "op": {"type": "CX"}}, {"args": [["q", [1]]], "op": {"type": "H"}}, {"args": [["q", [1]]], "op": {"params": ["0.2"], "type": "Rz"}}, {"args": [["q", [1]]], "op": {"type": "H"}}, {"args": [["q", [0]], ["q", [1]]], "op": {"type": "CX"}}, {"args": [["q", [0]], ["q", [2]]], "op": {"type": "CX"}}, {"args": [["q", [0]]], "op": {"params": ["-0.1"], "type": "Rz"}}],
"created_qubits": [],
"discarded_qubits": [],
"implicit_permutation": [[["q", [0]], ["q", [0]]], [["q", [1]], ["q", [1]]], [["q", [2]], ["q", [2]]]], "phase": "0.0", "qubits": [["q", [0]], ["q", [1]], ["q", [2]]]
}"#;
let ser: SerialCircuit = serde_json::from_str(json).unwrap();
ser.decode().unwrap()
}

#[rstest]
#[ignore = "Takes 800ms"]
// #[ignore = "Takes 800ms"]
fn taso_termination(simple_circ: Hugr, nam_4_2: DefaultTasoOptimiser) {
let opt_circ = nam_4_2.optimise(&simple_circ, None, 1.try_into().unwrap());
assert_eq!(opt_circ.commands().count(), 11);
Expand Down

0 comments on commit 05c495f

Please sign in to comment.