Пример #1
0
def clusterstate(n, noisy=False, kraus=None):
    """
    This creates a cluster state
    :param n: This is the number of qubits in the system
    :param string: This is the string that determines the state of the initial system. e.g
    '0000' produces 4 qubit state being all in the ground state while '01010' produces a five qubits with
    qubits being in ground and excited states alternately
    :param ar: This is a list of numbers that specifies the various control and target position
    e.g clusterstate(4, '0000', [1,3,2,4]) creates two control operations with first qubit being the control and the third qubit
    being the target and the second operation has second being the control with the fourth qubit being the target.
    :param noisy: If true decoherence is added between gate applications
    :param kraus: This will be a 3 dimensional array of kraus matrices
    :return: returns the state of the qubit after the controlled z operations. This should be a cluster state

    """
    string = '0'*n
    q = qubit.Qubit(string, n)
    q.state = np.dot(g.multi_hadamard(n), np.dot(q.state, g.multi_hadamard(n)))
    if noisy is False:
        for i in range(1, n+1):
            controlgate = g.c_u(g.z(), n, i, i+1)
            q.state = np.dot(controlgate, np.dot(q.state, op.ctranspose(controlgate)))
    else:
        for i in range(1, n+1):
            controlgate = g.c_u(g.z(), n, i, i+1)
            q.q_decohere(kraus, n)
            q.state = np.dot(controlgate, np.dot(q.state, op.ctranspose(controlgate)))
    return q
Пример #2
0
def ghz_state(n, noisy=False, kraus=None):
    """
    This creates an n qubit ghz state
    :param n:  The number of qubits in the state
    :param string: The string for the initial state of the density matrix e.g '000' produces a state where all
    the three qubits are in the ground state while '111' produces a state where all the qubits are the excited state
    :param ar: This is a list of numbers that specifies the various control and target position
    e.g ghz_state(4, '0000', [1,2,1,3,1,4]) creates two control operations with first qubit being the
    control and the second qubit being the target and the second operation has first being the control
    with the third qubit being the target third operation has the first qubit being the control and the
    fourth qubit being the target
     :param noisy: If true decoherence is added between gate applications
    :param kraus: This will be a 3 dimensional array of kraus matrices
    :return: returns the state of the qubit after the controlled x operations. This should be a ghz state.
    """
    string = '0'*n
    q = qubit.Qubit(string, n)
    h_gate = op.superkron(g.h(), np.eye(pow(2, n-1)))
    q.state = np.dot(h_gate, np.dot(q.state, h_gate))
    if noisy is False:
        for i in range(1, n+1):
            controlgate = g.c_u(g.x(), n, i, i + 1)
            q.state = np.dot(controlgate, np.dot(q.state, op.ctranspose(controlgate)))
    else:
        for i in range(1, n+1):
            controlgate = g.c_u(g.x(), n, i, i + 1)
            q.q_decohere(kraus, n)
            q.state = np.dot(controlgate, np.dot(q.state, op.ctranspose(controlgate)))

    return q
Пример #3
0
 def circuit_unitary(self):
     """
     :return: Returns the unitary for the circuit
     """
     out = np.eye(2**self.n, dtype='complex128')
     for i in self.bucket:
         out = np.dot(out, self.step_operator(i))
     out = op.ctranspose(out)
     return out
Пример #4
0
def bakersmap(n):
    """
    :param n: The number of qubits
    :return:
    """
    q = qft(n)
    q_1 = qft(n / 2)
    out = op.ctranspose(q) * kron(id(), q_1)

    return out
Пример #5
0
def apply_kraus(K, rho_s, n, non_ideal_qubits=0, partial_bath=False):
    """
    :param K: List of kraus operators
    :param rho: density matrix of system
    :param n: Number of qubits
    :return: Return evolved density matrix
    """
    out = np.zeros((pow(2, n), pow(2, n)), dtype=complex)
    if partial_bath:
        ideal_qubits_oper = {'0': g.id()}
        id_oper = op.superkron(ideal_qubits_oper, val=1, string='0' * (n - non_ideal_qubits))
        for kraus in K:
            new_kraus = op.superkron(kraus, id_oper)
            out += np.dot(new_kraus, np.dot(rho_s, op.ctranspose(new_kraus)))
        return out
    else:
        for kraus in K:
            out += np.dot(kraus, np.dot(rho_s, op.ctranspose(kraus)))
        return out
Пример #6
0
 def time_step_evolve(self, basis=''):
     """
     :param h: Hamiltonian by which to evolve the system
     :param dt: time step to evolve by could be small or large
     :param basis: Basis of measurement
     :return: returns the state of qubit after evolution
     """
     self.U = expm(-1j * self.hamiltonian * self.dt)
     self.state = np.dot(self.U, np.dot(self.state, op.ctranspose(self.U)))
     for state, projector in zip(self.classical_states, self.get_projectors(self.measurement_string)):
         # Possibly change basis of measurement before calculating probability history.
         self.measure_basis(pauli_string=basis)
         self.classical_states_history[state].append(np.trace(np.dot(self.state, projector)).real)
         self.measure_basis(pauli_string=basis, undo_basis=True)
Пример #7
0
def serial_decohere(K, rho_s, n_s):
    """
    :param K: List of kraus operators
    :param rho: density matrix of system
    :param n: Number of qubits
    :return: Return evolved density matrix
    """
    K = list(K)
    out = np.zeros((pow(2, n_s), pow(2, n_s)), dtype=complex)
    try:
        assert type(K) == list
        for i in range(len(K)):
            out += np.dot(K[i], np.dot(rho_s, op.ctranspose(K[i])))
    except:
        raise TypeError('The input K must be a list of numpy arrays')
    return out
Пример #8
0
 def operator(self, o):
     """
     :param o: The operator you want applied to the qubit
     :return:  Returns the transformed density matrix after the operation
     """
     self.state = np.dot(o, np.dot(self.state, op.ctranspose(o)))