Exemplo n.º 1
0
 def test_qs_subtopoology_angle1(self):
     qtool = QSearchTool()
     qasm = qtool.synthesize(self.TOFFOLI, coupling_graph=[(0, 1), (0, 2)])
     utry = get_utry(QuantumCircuit.from_qasm_str(qasm))
     self.assertTrue(hilbert_schmidt_distance(self.TOFFOLI, utry) <= 1e-15)
     self.assertTrue("cx q[0], q[1];" in qasm or "cx q[1], q[0]" in qasm)
     self.assertFalse("cx q[1], q[2];" in qasm or "cx q[2], q[1]" in qasm)
     self.assertTrue("cx q[0], q[2];" in qasm or "cx q[2], q[0]" in qasm)
Exemplo n.º 2
0
 def test_qs_basis_gates_cz(self):
     qtool = QSearchTool()
     qasm = qtool.synthesize(self.TOFFOLI, basis_gates=["cz"])
     utry = get_utry(QuantumCircuit.from_qasm_str(qasm))
     self.assertTrue(hilbert_schmidt_distance(self.TOFFOLI, utry) <= 1e-15)
     self.assertTrue("cx" not in qasm)
     self.assertTrue("cz" in qasm)
     self.assertTrue("iswap" not in qasm)
     self.assertTrue("rxx" not in qasm)
Exemplo n.º 3
0
    def test_qs_synthesize_invalid(self):
        qtool = QSearchTool()
        self.assertRaises(TypeError, qtool.synthesize, 1)
        self.assertRaises(TypeError, qtool.synthesize, np.array([0, 1]))
        self.assertRaises(TypeError, qtool.synthesize, np.array([[[0]]]))
        self.assertRaises(TypeError, qtool.synthesize, self.INVALID)

        invalid_utry_matrix = np.copy(self.TOFFOLI)
        invalid_utry_matrix[2][2] = 137. + 0.j

        self.assertRaises(TypeError, qtool.synthesize, invalid_utry_matrix)
        self.assertRaises(ValueError, qtool.synthesize, np.identity(16))
Exemplo n.º 4
0
 def test_qs_get_maximum_size(self):
     qtool = QSearchTool()
     block_size = qtool.get_maximum_size()
     self.assertEqual(block_size, 3)
Exemplo n.º 5
0
 def test_qs_synthesize_valid(self):
     qtool = QSearchTool()
     qasm = qtool.synthesize(self.TOFFOLI)
     utry = get_utry(QuantumCircuit.from_qasm_str(qasm))
     self.assertTrue(hilbert_schmidt_distance(self.TOFFOLI, utry) <= 1e-15)