Ejemplo n.º 1
0
 def test_magic_state_decomposition_is_correct(self):
     c = Circuit(6)
     for i in range(6):
         c.add_gate("T", i)
     g = c.to_graph()
     gsum = replace_magic_states(g)
     self.assertTrue(np.allclose(g.to_tensor(), gsum.to_tensor()))
Ejemplo n.º 2
0
 def test_three_cnots_is_swap(self):
     g = Graph()
     i1 = g.add_vertex(0, 0, 0)
     i2 = g.add_vertex(0, 1, 0)
     o1 = g.add_vertex(0, 0, 1)
     o2 = g.add_vertex(0, 1, 1)
     g.inputs = [i1, i2]
     g.outputs = [o1, o2]
     g.add_edges([(i1, o2), (i2, o1)])
     swap = tensorfy(g)
     c = Circuit(2)
     c.add_gate("CNOT", 0, 1)
     c.add_gate("CNOT", 1, 0)
     c.add_gate("CNOT", 0, 1)
     three_cnots = tensorfy(c.to_graph())
     self.assertTrue(compare_tensors(swap, three_cnots))
Ejemplo n.º 3
0
    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))