Esempio n. 1
0
def test_binary_symplectic_inner_product():
    a = np.array([1, 1, 0, 0])
    b = np.array([1, 1, 1, 1])
    c = np.array([1, 1, 1, 0])

    assert (binary_symplectic_inner_product(a, b) == 0)
    assert (binary_symplectic_inner_product(a, c) == 1)
    assert (binary_symplectic_inner_product(b, c) == 1)
Esempio n. 2
0
def test_binary_symplectic_orthogonalization():
    matrix = prepare_binary_matrix()

    x = np.array([1, 1, 0, 0, 0, 0])
    y = np.array([0, 0, 0, 1, 0, 0])

    binary_symplectic_orthogonalization(matrix, x, y)

    # if all elements are orthogonalized.
    for vec in matrix:
        assert (binary_symplectic_inner_product(vec, x) == 0)
        assert (binary_symplectic_inner_product(vec, y) == 0)
Esempio n. 3
0
def test_symplectic_gram_schmidt():
    matrix = prepare_binary_matrix()
    lagrangian_subspace = binary_symplectic_gram_schmidt(matrix)

    # if subspace is lagrangian
    assert (len(lagrangian_subspace) == len(matrix[0]) // 2)

    for ivec in lagrangian_subspace:
        for jvec in lagrangian_subspace:
            assert (binary_symplectic_inner_product(ivec, jvec) == 0)
Esempio n. 4
0
def test_pick_symplectic_pair():
    matrix = prepare_binary_matrix()
    original_length = len(matrix)

    x, y = pick_symplectic_pair(matrix)

    # if is symplectic pair
    assert (binary_symplectic_inner_product(x, y) == 1)
    # if the symplectic pairs are picked out from the matrix
    assert (len(matrix) == original_length - 2)
    for vec in matrix:
        assert (not all(vec == x))
        assert (not all(vec == y))
Esempio n. 5
0
    def commute(self, other):
        '''
        Determine whether the corresponding pauli-strings of 
        the two binary vectors commute. 
        '''
        inner_product = binary_symplectic_inner_product(
            self.binary, other.binary)

        if inner_product == 0:
            return True
        elif inner_product == 1:
            return False
        else:
            raise TequilaException('Computed unexpected inner product. Got ' +
                                   str(inner_product))
Esempio n. 6
0
    def find_single_qubit_pair(self, cur_basis, free_qub):
        '''
        Find the single qubit pair that anti-commute with cur_basis such that the single qubit is in free_qub 

        Return: Binary vectors representing the single qubit pair
        Modify: Pops the qubit used from free_qub
        '''
        dim = len(cur_basis) // 2
        for idx, qub in enumerate(free_qub):
            for term in range(3):
                pair = gen_single_qubit_term(dim, qub, term)
                # if anticommute
                if (binary_symplectic_inner_product(pair, cur_basis) == 1):
                    free_qub.pop(idx)
                    return pair
Esempio n. 7
0
def test_get_lagrangian_subspace():
    a = np.array([1, 1, 0, 0, 0, 0])
    b = np.array([1, 0, 0, 0, 0, 0])
    matrix = []
    matrix.append(a)
    matrix.append(b)
    lagrangian_subspace = get_lagrangian_subspace(matrix)

    # if lagrangian subspace spans given vectors
    assert (is_binary_basis(lagrangian_subspace, a))
    assert (is_binary_basis(lagrangian_subspace, b))

    # if subspace is lagrangian
    for ivec in matrix:
        for jvec in matrix:
            assert (binary_symplectic_inner_product(ivec, jvec) == 0)
Esempio n. 8
0
    def get_single_qubit_basis(self, lagrangian_basis):
        '''
        Find the single_qubit_basis such that single_qubit_basis[i] anti-commutes
        with lagrangian_basis[i], and commute for all other cases. 
        '''
        dim = len(lagrangian_basis)

        # Free Qubits
        free_qub = [qub for qub in range(dim)]
        pair = []

        for i in range(dim):
            cur_pair = self.find_single_qubit_pair(lagrangian_basis[i],
                                                   free_qub)
            for j in range(dim):
                if i != j:
                    if binary_symplectic_inner_product(
                            cur_pair, lagrangian_basis[j] == 1):
                        lagrangian_basis[j] = (lagrangian_basis[i] +
                                               lagrangian_basis[j]) % 2
            pair.append(cur_pair)
        return pair