예제 #1
0
    def test_n_equals_9(self):
        n = 9
        # Obtain a random antisymmetric matrix
        rand_mat = numpy.random.randn(2 * n, 2 * n)
        antisymmetric_matrix = rand_mat - rand_mat.T

        # Get the diagonalizing fermionic unitary
        ferm_unitary = diagonalizing_fermionic_unitary(antisymmetric_matrix)
        lower_unitary = ferm_unitary[n:]

        # Get fermionic Gaussian decomposition of lower_unitary
        left_unitary, decomposition, diagonal = (
            fermionic_gaussian_decomposition(lower_unitary))

        # Check that left_unitary zeroes out the correct entries of
        # lower_unitary
        product = left_unitary.dot(lower_unitary)
        for i in range(n - 1):
            for j in range(n - 1 - i):
                self.assertAlmostEqual(product[i, j], 0.)

        # Compute right_unitary
        right_unitary = numpy.eye(2 * n, dtype=complex)
        for parallel_set in decomposition:
            combined_op = numpy.eye(2 * n, dtype=complex)
            for op in parallel_set:
                if op == 'pht':
                    swap_rows(combined_op, n - 1, 2 * n - 1)
                else:
                    i, j, theta, phi = op
                    c = numpy.cos(theta)
                    s = numpy.sin(theta)
                    phase = numpy.exp(1.j * phi)
                    givens_rotation = numpy.array(
                        [[c, -phase * s], [s, phase * c]], dtype=complex)
                    double_givens_rotate(combined_op, givens_rotation, i, j)
            right_unitary = combined_op.dot(right_unitary)

        # Compute left_unitary * lower_unitary * right_unitary^\dagger
        product = left_unitary.dot(lower_unitary.dot(right_unitary.T.conj()))

        # Construct the diagonal matrix
        diag = numpy.zeros((n, 2 * n), dtype=complex)
        diag[range(n), range(n, 2 * n)] = diagonal

        # Assert that W and D are the same
        for i in numpy.ndindex((n, 2 * n)):
            self.assertAlmostEqual(diag[i], product[i])
예제 #2
0
 def test_bad_constraints(self):
     n = 3
     ones_mat = numpy.ones((n, 2 * n))
     with self.assertRaises(ValueError):
         left_unitary, decomposition, antidiagonal = (
             fermionic_gaussian_decomposition(ones_mat))
예제 #3
0
 def test_bad_dimensions(self):
     n, p = (3, 7)
     rand_mat = numpy.random.randn(n, p)
     with self.assertRaises(ValueError):
         left_unitary, decomposition, antidiagonal = (
             fermionic_gaussian_decomposition(rand_mat))