def test_supplementarity_simp(self):
     g = Graph()
     v = g.add_vertex(1,0,0,phase=Fraction(1,4))
     w = g.add_vertex(1,1,0,phase=Fraction(7,4))
     g.add_edge((v,w),2)
     vs = []
     for i in range(3):
         h = g.add_vertex(1,i,2,Fraction(1))
         vs.append(h)
         g.add_edges([(v,h),(w,h)],2)
     t = g.to_tensor()
     i = supplementarity_simp(g,quiet=True)
     self.assertEqual(i,1)
     self.assertTrue(compare_tensors(t,g.to_tensor()))
Exemple #2
0
 def test_inequality_id_and_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]
     g2 = g.copy()
     g.add_edges([(i1, o2), (i2, o1)])
     g2.add_edges([(i1, o1), (i2, o2)])
     id_id = tensorfy(g2)
     swap = tensorfy(g)
     self.assertFalse(compare_tensors(id_id, swap))
Exemple #3
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))