def setUp(self): random.seed(SEED) self.circuits = [] self.circuits.append(cliffordT(3,20,0.3)) self.circuits.append(cliffordT(3,10,0.1)) self.circuits.append(cliffordT(4,30,0.3)) self.circuits.append(cliffordT(5,50,0.08)) self.circuits.append(cliffordT(4,80,0.1))
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_cliffordT_preserves_graph_semantics(self): random.seed(SEED) g = cliffordT(4,20,0.2) c = Circuit.from_graph(g) g2 = c.to_graph() t = tensorfy(g) t2 = tensorfy(g2) 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, test_clifford_graph=True): 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) steps = [] circ = cliffordT(qubits,depth,p_t=0.2) t = circ.to_tensor() g = circ.copy() clifford_simp(g,quiet=True) steps.append("clifford_simp") if test_clifford_graph: compare(t, g) c = streaming_extract(g) steps.append("streaming_extract") compare(t, c) c = c.to_basic_gates() steps.append("to_basic_gates") compare(t, c) c2, blocks = circuit_phase_polynomial_blocks(c, optimize=False) steps.append("phase_polynomial") compare(t, c2) c2, blocks = circuit_phase_polynomial_blocks(c, optimize=True) steps[-1] = "phase_polynomial_optimized" compare(t, c2) steps = [] g = circ.copy() full_reduce(g, quiet=True) steps.append("full_reduce") if test_clifford_graph: compare(t, g) c = streaming_extract(g).to_basic_gates() steps.append("streaming_extract") compare(t, c) c2, blocks = circuit_phase_polynomial_blocks(c, optimize=True) steps[-1] = "phase_polynomial_optimized" compare(t, c2) steps = [] g = circ.copy() #to_gh(g) #id_simp(g,quiet=True) #spider_simp(g,quiet=True) g = teleport_reduce(g) steps.append("teleport_reduce") compare(t,g) #c1 = zx.Circuit.from_graph(g,split_phases=True).to_basic_gates() #c1 = zx.optimize.basic_optimization(c_opt).to_basic_gates() #self.c_opt = c_opt #c_id = c_orig.adjoint() #c_id.add_circuit(c_opt) #g = c_id.to_graph() #zx.simplify.full_reduce(g) 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")