def test_genericgate_get_fun_vals(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())
            fun_vals = gg.get_fun_vals(sess)

        self.assertTrue(np.array_equal(fun_vals, [0.25] * 16))
コード例 #2
0
    def test_genericgate_get_location ( 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() )
            location = gg.get_location( sess )

        self.assertTrue( np.array_equal( location, list( lm.locations )[0] ) )
    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))
コード例 #5
0
    def test_genericgate_constructor_valid(self):
        reset_tensor_cache()
        lm = LocationModel(4, 2)
        gg = GenericGate("Test", 4, 2, lm)
        self.assertEqual(gg.name, "Test")
        self.assertEqual(gg.num_qubits, 4)
        self.assertEqual(gg.gate_size, 2)
        self.assertTrue(np.array_equal(gg.loc_vals, [0] * 6))
        self.assertTrue(np.array_equal(gg.fun_vals, [0.25] * 16))
        self.assertTrue(np.array_equal(list(lm.locations), gg.topology))

        gg = GenericGate("Test", 4, 2, lm, parity=0)
        self.assertEqual(gg.name, "Test")
        self.assertEqual(gg.num_qubits, 4)
        self.assertEqual(gg.gate_size, 2)
        self.assertTrue(np.array_equal(gg.fun_vals, [0.25] * 16))
        self.assertTrue(np.array_equal(lm.buckets[0], gg.topology))