Exemple #1
0
    def test_pauli_expansion_valid_4(self):
        sigma = get_norder_paulis(4)

        for H in sigma:
            alpha = pauli_expansion(H)
            reH = np.sum([a * p for a, p in zip(alpha, sigma)], 0)
            self.assertTrue(hilbert_schmidt_distance(H, reH) <= 1e-16)
    def test_circuit_get_fun_loc_vals(self):
        circ = Circuit(self.TOFFOLI)
        circ.blocks = [
            Block(self.TOFFOLI, (1, 2, 3)),
            Block(self.TOFFOLI, (0, 1, 2))
        ]
        fun_loc_vals = circ.get_fun_loc_vals()

        self.assertTrue(isinstance(fun_loc_vals, tuple))
        self.assertEqual(len(fun_loc_vals), 2)

        fun_vals = fun_loc_vals[0]
        loc_vals = fun_loc_vals[1]

        self.assertTrue(isinstance(fun_vals, list))
        self.assertTrue(isinstance(loc_vals, list))

        self.assertEqual(len(fun_vals), 2)
        self.assertEqual(len(loc_vals), 2)

        toffoli_vals = pauli_expansion(unitary_log_no_i(self.TOFFOLI))
        self.assertTrue(np.array_equal(fun_vals[0], toffoli_vals))
        self.assertTrue(np.array_equal(fun_vals[1], toffoli_vals))

        self.assertTrue(np.array_equal(loc_vals[0], (1, 2, 3)))
        self.assertTrue(np.array_equal(loc_vals[1], (0, 1, 2)))
Exemple #3
0
    def test_pauli_expansion_valid_comb(self):
        sigma = get_norder_paulis(4)
        sqrt2 = np.sqrt(2) / 2

        for H1, H2 in zip(sigma, sigma[1:]):
            H = sqrt2 * H1 + sqrt2 * H2
            alpha = pauli_expansion(H)
            reH = np.sum([a * p for a, p in zip(alpha, sigma)], 0)
            self.assertTrue(hilbert_schmidt_distance(H, reH) <= 1e-16)
    def test_get_unitary_from_pauli_coefs_1 ( self ):
        sigma = get_norder_paulis( 1 )

        for U in sigma:
            pauli_coefs = pauli_expansion( unitary_log_no_i( U ) )
            reU = get_unitary_from_pauli_coefs( pauli_coefs )
            self.assertTrue( hilbert_schmidt_distance( U, reU ) <= 1e-16 )
            self.assertTrue( np.allclose( U.conj().T @ U, np.identity( len( U ) ),
                                          rtol = 0, atol = 1e-16 )
                             and
                             np.allclose( U @ U.conj().T, np.identity( len( U ) ),
                                          rtol = 0, atol = 1e-16 ) )
    def test_block_get_fun_vals ( self ):
        toffoli_vals = pauli_expansion( unitary_log_no_i( self.TOFFOLI ) )

        block = Block( self.TOFFOLI, (0, 1, 2) )
        self.assertTrue( np.array_equal( block.get_fun_vals(), toffoli_vals ) )