Exemplo n.º 1
0
def IS_projector(G):
    global N
    rr = np.array([[1, 0, 0, 0], [0, 0, 0, 0], [0, 0, 0, 0], [0, 0, 0, 0]])
    C = np.identity(2**N)
    for i, j in G.edges:
        temp = tools.tensor_product([rr, tools.identity(N - 2)])
        temp = np.reshape(temp, 2 * np.ones(2 * N, dtype=int))
        temp = np.moveaxis(temp, [0, 1, N, N + 1], [i, j, N + i, N + j])
        temp = np.reshape(temp, (2**N, 2**N))
        C = C @ (np.identity(2**N) - temp)
    return C
def h4():
    ham = (tools.identity(5) + ham_term('z', 'z', 'i', 'i', 'i')) @ (
            ham_term('i', 'z', 'z', 'i', 'i') - tools.identity(5)) @ \
          ham_term('i', 'i', 'i', 'i', 'x') + (tools.identity(5) + ham_term('z', 'i', 'z', 'i', 'i')) @ (
                  ham_term('i', 'z', 'z', 'i', 'i') - tools.identity(5)) @ \
          ham_term('i', 'i', 'i', 'x', 'x') + (tools.identity(5) + ham_term('i', 'z', 'z', 'i', 'i')) @ (
                  ham_term('z', 'z', 'i', 'i', 'i') - tools.identity(5)) @ \
          ham_term('i', 'i', 'i', 'x', 'i')
    return ham + ham.conj().T
Exemplo n.º 3
0
def cost_function(G, penalty):
    global N
    sigma_plus = np.array([1, 0])
    rr = np.array([[1, 0, 0, 0], [0, 0, 0, 0], [0, 0, 0, 0], [0, 0, 0, 0]])
    C = np.zeros([2**N])
    myeye = lambda n: np.ones(np.asarray(sigma_plus.shape[0])**n)

    for i, j in G.edges:
        temp = tools.tensor_product([rr, tools.identity(N - 2)])
        temp = np.reshape(temp, 2 * np.ones(2 * N, dtype=int))
        temp = np.moveaxis(temp, [0, 1, N, N + 1], [i, j, N + i, N + j])
        temp = np.reshape(temp, (2**N, 2**N))
        C = C + np.diagonal(temp) * penalty * -1
    for c in G.nodes:
        C = C + tools.tensor_product([myeye(c), sigma_plus, myeye(N - c - 1)])
    return C
Exemplo n.º 4
0
    def __init__(self, graph: nx.Graph, rate):
        super().__init__(jump_operators=[
            np.array([[0, 0, 0, 0], [1, 0, 0, 0], [0, 0, 0, 0], [0, 0, 0, 0]]),
            np.array([[0, 0, 0, 0], [0, 0, 0, 0], [1, 0, 0, 0], [0, 0, 0, 0]]),
            np.array([[0, 0, 0, 0], [0, 0, 0, 0], [0, 0, 0, 0], [1, 0, 0, 0]])
        ],
                         weights=rate)
        # Construct the right jump_operators operators
        self.code = qubit
        self.graph = graph
        self.N = self.graph.number_of_nodes()
        jump_operators = []

        for (i, j) in graph.edges:
            for p in range(len(self.jump_operators)):
                temp = tools.tensor_product(
                    [self.jump_operators[p],
                     tools.identity(self.N - 2)])
                temp = np.reshape(temp, 2 * np.ones(2 * self.N, dtype=int))
                temp = np.moveaxis(temp, [0, 1, self.N, self.N + 1],
                                   [i, j, self.N + i, self.N + j])
                temp = np.reshape(temp, (2**self.N, 2**self.N))
                jump_operators.append(temp)
        self.jump_operators = jump_operators
Exemplo n.º 5
0
import numpy as np
from qsim import tools
from . import qubit
from scipy.linalg import expm
from qsim.codes.quantum_state import State
from typing import Union

__all__ = ['multiply', 'right_multiply', 'left_multiply', 'rotation']

logical_code = True

X = tools.tensor_product([tools.X(), tools.identity()])
Y = tools.tensor_product([tools.Y(), tools.Z()])
Z = tools.tensor_product([tools.Z(), tools.Z()])
n = 2
d = 2
logical_basis = np.array([[[1], [0], [0], [1]], [[0], [1], [1], [0]]]).astype(
    np.complex128) / np.sqrt(2)
Q = 1 / 2 * (np.identity(d**n) + Z)
P = 1 / 2 * (np.identity(d**n) - Z)

code_space_projector = tools.outer_product(
    logical_basis[0], logical_basis[0]) + tools.outer_product(
        logical_basis[1], logical_basis[1])


def rotation(state: State,
             apply_to: Union[int, list],
             angle: float,
             op,
             is_involutary=False,
Exemplo n.º 6
0
import numpy as np
from qsim import tools
from qsim.codes import qubit
from scipy.linalg import expm
from typing import Union
from qsim.codes.quantum_state import State
"""
:class:`JordanFarhiShor` is an error detecting code which detects phase flip (Z-type) and bit flip (X-type) errors.
These errors cannot be corrected unambiguously.
"""
__all__ = ['multiply', 'right_multiply', 'left_multiply', 'rotation']

logical_code = True

X = tools.tensor_product(
    [tools.Y(), tools.identity(),
     tools.Y(), tools.identity()])
Y = tools.tensor_product(
    [-1 * tools.identity(),
     tools.X(), tools.X(),
     tools.identity()])
Z = tools.tensor_product(
    [tools.Z(), tools.Z(),
     tools.identity(),
     tools.identity()])
n = 4
d = 2
logical_basis = np.array([[[1], [0], [0], [1j], [0], [0], [0], [0], [0], [0],
                           [0], [0], [1j], [0], [0], [1]],
                          [[0], [0], [0], [0], [0], [-1], [1j], [0], [0], [1j],
                           [-1], [0], [0], [0], [0], [0]]]) / 2
Exemplo n.º 7
0
import numpy as np
from qsim.codes import qubit
from qsim.codes.quantum_state import State
from qsim import tools
import time
from scipy.linalg import expm
from scipy.sparse.linalg import expm_multiply
from scipy.sparse import csr_matrix

n = 10
print('Timer test with', n, 'qubits')

Hb = np.zeros((2**n, 2**n), dtype=int)
for i in range(n):
    Hb = Hb + tools.tensor_product(
        [tools.identity(i), qubit.X,
         tools.identity(n - i - 1)])

# Make sparse matrix for Hb
Hb_sparse = csr_matrix(Hb)
psi0 = State(np.zeros((2**n, 1)))
psi0[-1, -1] = 1
t0 = time.perf_counter()
res = expm_multiply(Hb, psi0)
t1 = time.perf_counter()
print('scipy expm_multiply with non-sparse matrix: ', t1 - t0)
res = expm(Hb) @ psi0
t2 = time.perf_counter()
print('numpy expm with non-spares matrix: ', t2 - t1)
res = expm_multiply(Hb_sparse, psi0)
t3 = time.perf_counter()
Exemplo n.º 8
0
logical_code = True

X = tools.tensor_product([tools.X(), tools.X(), tools.X()])
Y = -1 * tools.tensor_product([tools.Y(), tools.Y(), tools.Y()])
Z = tools.tensor_product([tools.Z(), tools.Z(), tools.Z()])
n = 3
d = 2
logical_basis = np.array([[[1], [0], [0], [0], [0], [0], [0], [0]],
                          [[0], [0], [0], [0], [0], [0], [0], [1]]], dtype=np.complex128)
Q = 1/2*(np.identity(d**n)+Z)
P = 1/2*(np.identity(d**n)-Z)
code_space_projector = tools.outer_product(logical_basis[0], logical_basis[0]) + tools.outer_product(logical_basis[1],
                                                                                                     logical_basis[1])
stabilizers = np.array(
    [tools.tensor_product([tools.Z(2), tools.identity()]), tools.tensor_product([tools.identity(), tools.Z(2)])])


def rotation(state: State, apply_to: Union[int, list], angle: float, op, is_involutary=False, is_idempotent=False):
    """
    Apply a single qubit rotation :math:`e^{-i \\alpha A}` to the input ``codes``.

    :param apply_to:
    :param is_idempotent:
    :param is_involutary:
    :param state: input wavefunction or density matrix
    :type state: np.ndarray
    :param angle: The angle :math:`\\alpha`` to rotate by.
    :type angle: float
    :param op: Operator to act with.
    :type op: np.ndarray