def test_pauli_dot_product_1(self): alpha = [1, 0, 0, 0] sigma = get_norder_paulis(1) self.assertTrue(np.allclose(pauli_dot_product(alpha, sigma), I)) alpha = [0, 1, 0, 0] self.assertTrue(np.allclose(pauli_dot_product(alpha, sigma), X)) alpha = [0, 0, 1, 0] self.assertTrue(np.allclose(pauli_dot_product(alpha, sigma), Y)) alpha = [0, 0, 0, 1] self.assertTrue(np.allclose(pauli_dot_product(alpha, sigma), Z))
def test_fixedgate_get_unitary(self): reset_tensor_cache() fg = FixedGate("Test", 4, 2, (0, 1)) with tf.Session() as sess: sess.run(tf.global_variables_initializer()) gate = fg.get_unitary(sess) paulis = get_pauli_n_qubit_projection(4, (0, 1)) H = pauli_dot_product([0.25] * 16, paulis) U = la.expm(1j * H) self.assertTrue(hilbert_schmidt_distance(gate, U) <= 1e-16)
def test_fixedgate_get_herm ( self ): reset_tensor_cache() fg = FixedGate( "Test", 4, 2, (0, 1) ) herm = fg.get_herm() with tf.Session() as sess: sess.run( tf.global_variables_initializer() ) herm = herm.eval() paulis = get_pauli_n_qubit_projection( 4, (0, 1) ) H = pauli_dot_product( [ 0.25 ] * 16, paulis ) self.assertTrue( np.array_equal( herm, H ) )
def test_genericgate_get_unitary(self): reset_tensor_cache() lm = LocationModel(4, 2) gg = GenericGate("Test", 4, 2, lm, loc_vals=[1, 0, 0, 0, 0, 0]) with tf.Session() as sess: sess.run(tf.global_variables_initializer()) gate = gg.get_unitary(sess) paulis = get_pauli_n_qubit_projection(4, (0, 1)) H = pauli_dot_product([0.25] * 16, paulis) U = la.expm(1j * H) self.assertTrue(hilbert_schmidt_distance(gate, U) <= 1e-16)
def test_genericgate_get_herm(self): reset_tensor_cache() lm = LocationModel(4, 2) gg = GenericGate("Test", 4, 2, lm, loc_vals=[1, 0, 0, 0, 0, 0]) herm = gg.get_herm() with tf.Session() as sess: sess.run(tf.global_variables_initializer()) herm = herm.eval() paulis = get_pauli_n_qubit_projection(4, list(lm.locations)[0]) H = pauli_dot_product([0.25] * 16, paulis) self.assertTrue(np.allclose(herm, H, rtol=0, atol=1e-15))
def test_pauli_dot_product_2(self): alpha = [1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0] sigma = get_norder_paulis(2) self.assertTrue( np.allclose(pauli_dot_product(alpha, sigma), np.kron(I, I))) alpha = [0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0] self.assertTrue( np.allclose(pauli_dot_product(alpha, sigma), np.kron(I, X))) alpha = [0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0] self.assertTrue( np.allclose(pauli_dot_product(alpha, sigma), np.kron(I, Y))) alpha = [0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0] self.assertTrue( np.allclose(pauli_dot_product(alpha, sigma), np.kron(I, Z))) alpha = [0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0] self.assertTrue( np.allclose(pauli_dot_product(alpha, sigma), np.kron(X, I))) alpha = [0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0] self.assertTrue( np.allclose(pauli_dot_product(alpha, sigma), np.kron(X, X))) alpha = [0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0] self.assertTrue( np.allclose(pauli_dot_product(alpha, sigma), np.kron(X, Y))) alpha = [0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0] self.assertTrue( np.allclose(pauli_dot_product(alpha, sigma), np.kron(X, Z))) alpha = [0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0] self.assertTrue( np.allclose(pauli_dot_product(alpha, sigma), np.kron(Y, I))) alpha = [0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0] self.assertTrue( np.allclose(pauli_dot_product(alpha, sigma), np.kron(Y, X))) alpha = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0] self.assertTrue( np.allclose(pauli_dot_product(alpha, sigma), np.kron(Y, Y))) alpha = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0] self.assertTrue( np.allclose(pauli_dot_product(alpha, sigma), np.kron(Y, Z))) alpha = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0] self.assertTrue( np.allclose(pauli_dot_product(alpha, sigma), np.kron(Z, I))) alpha = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0] self.assertTrue( np.allclose(pauli_dot_product(alpha, sigma), np.kron(Z, X))) alpha = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0] self.assertTrue( np.allclose(pauli_dot_product(alpha, sigma), np.kron(Z, Y))) alpha = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1] self.assertTrue( np.allclose(pauli_dot_product(alpha, sigma), np.kron(Z, Z)))