def test_circuit_extract_produces_circuit(self): random.seed(SEED) g = cliffordT(6, 60, 0.15) clifford_simp(g, quiet=True) circuit_extract(g) # This should not result in an exception Circuit.from_graph(g)
def test_circuit_extract_preserves_semantics(self): random.seed(SEED) g = cliffordT(5, 70, 0.15) t = g.to_tensor() clifford_simp(g, quiet=True) circuit_extract(g) t2 = Circuit.from_graph(g).to_tensor() self.assertTrue(compare_tensors(t,t2))
def test_circuit_extract_preserves_semantics(self): random.seed(SEED) g = cliffordT(5, 70, 0.15) t = g.to_tensor(False) clifford_simp(g, quiet=True) c = extract_circuit(g) t2 = c.to_tensor(False) self.assertTrue(compare_tensors(t, t2, False))
def test_streaming_extract(self): random.seed(SEED) for i in range(5): circ = cliffordT(4,50,0.1) t = tensorfy(circ) clifford_simp(circ,quiet=True) with self.subTest(i=i): c = streaming_extract(circ) t2 = c.to_tensor() self.assertTrue(compare_tensors(t,t2))
def test_extract_circuit(self): random.seed(SEED) for i in range(5): circ = cliffordT(4, 50, 0.1) t = tensorfy(circ, False) clifford_simp(circ, quiet=True) with self.subTest(i=i): c = extract_circuit(circ) t2 = c.to_tensor(False) self.assertTrue(compare_tensors(t, t2, False))
def test_greedy_cut_extract(self): random.seed(SEED) for i in range(5): circ = cliffordT(4,50,0.1) clifford_simp(circ,quiet=True) circ.normalise() with self.subTest(i=i): t = tensorfy(circ) greedy_cut_extract(circ) t2 = tensorfy(circ) self.assertTrue(compare_tensors(t,t2))
def do_tests(qubits, depth, iterations): print( "Starting test with circuits of {:d} qubits and {:d} depth. {:d} iterations" .format(qubits, depth, iterations)) try: for i in range(1, iterations + 1): if i % 25 == 0: print(i, end='.', flush=True) seed = random.randint(100000, 500000) random.seed(seed) c = CNOT_HAD_PHASE_circuit(qubits, depth, p_had=0.1, p_t=0.3) g = c.to_graph() g.apply_state(''.join( random.choice('+-01') for _ in range(qubits))) g.apply_effect(''.join( random.choice('+-01') for _ in range(qubits))) t = g.to_tensor() g2 = g.copy() clifford_simp(g2, quiet=True) steps = ["clifford_simp"] compare(t, g2) g2 = g.copy() full_reduce(g2, quiet=True) steps = ["full_reduce"] compare(t, g2) val = calculate_path_sum(g2) steps.append("calculate_path_sum") compare(t, np.array([val])) g2 = g.copy() steps = ["clifford_simp", "reduce_scalar"] clifford_simp(g2, quiet=True) reduce_scalar(g2, quiet=True) compare(t, g2) except AssertionError: print( "Unequality for circuit with seed {:d}, qubits {:d} and depth {:d}" .format(seed, qubits, depth)) print("It went wrong at step {} with total sequence {}".format( steps[-1], str(steps))) except Exception as e: print( "An exception occured for circuit with seed {:d}, qubits {:d} and depth {:d}" .format(seed, qubits, depth)) print("It went wrong at step {} with total sequence {}".format( steps[-1], str(steps))) raise e else: print("\nTests finished successfully")
def test_cz_optimize_extract(self): qb_no = 8 c = Circuit(qb_no) for i in range(qb_no): for j in range(i + 1, qb_no): c.add_gate("CZ", i, j) g = c.to_graph() clifford_simp(g, quiet=True) c2 = extract_circuit(g) cnot_count = 0 for gate in c2.gates: if isinstance(gate, CNOT): cnot_count += 1 self.assertTrue(cnot_count == 4) self.assertTrue(c.verify_equality(c2))
def test_clifford_extract(self): random.seed(SEED) tests = 0 tries = 0 while True: tries += 1 circ = cliffords(5,70) clifford_simp(circ,quiet=True) circ.normalise() if circ.depth()>3: continue # It is not in normal form, so skip this one tests += 1 with self.subTest(test=tests,tries=tries): t = tensorfy(circ) clifford_extract(circ,1,2) t2 = tensorfy(circ) self.assertTrue(compare_tensors(t,t2)) if tests>5: break