Exemplo n.º 1
0
def run_with_noise(circuit: Program, noise: float, shots: int) -> float:
    """Returns the expectation value of a circuit run several times with noise.

    Args:
        circuit: Quantum circuit as :class:`~pyquil.quil.Program`.
        noise: Noise constant for depolarizing channel.
        shots: Number of shots the circuit is run.

    Returns:
        expval: Expectation value.
    """
    # apply depolarizing noise to all gates
    kraus_ops = [
        np.sqrt(1 - noise) * npI,
        np.sqrt(noise / 3) * npX,
        np.sqrt(noise / 3) * npY,
        np.sqrt(noise / 3) * npZ,
    ]
    circuit.define_noisy_gate("X", [0], append_kraus_to_gate(kraus_ops, npX))
    circuit.define_noisy_gate("Y", [0], append_kraus_to_gate(kraus_ops, npY))
    circuit.define_noisy_gate("Z", [0], append_kraus_to_gate(kraus_ops, npZ))

    # set number of shots
    circuit.wrap_in_numshots_loop(shots)

    # we want to simulate noise, so we run without compiling
    results = QVM.run(circuit)
    expval = (results == [0]).sum() / shots
    return expval
Exemplo n.º 2
0
def dephased_rx_gate(phi, p=.1):
    corrupted_rx = append_kraus_to_gate(
        dephasing_kraus_map(p),
        np.array([[np.cos(phi / 2), -1j * np.sin(phi / 2)],
                  [-1j * np.sin(phi / 2),
                   np.cos(phi / 2)]]))
    return corrupted_rx
Exemplo n.º 3
0
def amp_damp_i_gate(p=.1):
    """
    Create amplitude damped Identity gate
    """
    corrupted_i = append_kraus_to_gate(damping_kraus_map(p),
                                       np.array([[1, 0], [0, 1]]))
    return corrupted_i
Exemplo n.º 4
0
def define_noisy_cliffords(p):
    # We only use some of the clifford for this 
    noisy_clifford_gates = []

    corrupted_H = append_kraus_to_gate(dephasing_kraus_map(p), 1/np.sqrt(2)*np.array([ [1, 1],[1, -1] ]) )
    corrupted_X = append_kraus_to_gate(dephasing_kraus_map(p), np.array([[0, 1], [1, 0]]) )
    corrupted_Y = append_kraus_to_gate(dephasing_kraus_map(p), np.array([[0, -1j], [1j, 0]]) )
    corrupted_Z = append_kraus_to_gate(dephasing_kraus_map(p), np.array([[1, 0], [0, -1]]) )

    noisy_clifford_gates.append(corrupted_H)
    noisy_clifford_gates.append(corrupted_X)
    noisy_clifford_gates.append(corrupted_Y)
    noisy_clifford_gates.append(corrupted_Z)


    return noisy_clifford_gates
Exemplo n.º 5
0
def add_depolarizing_noise(pq: Program, noise: float) -> Program:
    """Returns a quantum program with depolarizing channel noise.

    Args:
        pq: Quantum program as :class:`~pyquil.quil.Program`.
        noise: Noise constant for depolarizing channel.

    Returns:
        pq: Quantum program with added noise.
    """
    pq = pq.copy()
    # apply depolarizing noise to all gates
    kraus_ops = [
        np.sqrt(1 - noise) * npI,
        np.sqrt(noise / 3) * npX,
        np.sqrt(noise / 3) * npY,
        np.sqrt(noise / 3) * npZ,
    ]
    pq.define_noisy_gate("X", [0], append_kraus_to_gate(kraus_ops, npX))
    pq.define_noisy_gate("Y", [0], append_kraus_to_gate(kraus_ops, npY))
    pq.define_noisy_gate("Z", [0], append_kraus_to_gate(kraus_ops, npZ))
    return pq
Exemplo n.º 6
0
def pauli_noise_z_gate(p_I=.7, p_x=0.1, p_y=0.1, p_z=0.1):
    corrupted_Z = append_kraus_to_gate(pauli_kraus_map([p_I, p_x, p_y, p_z]),
                                       np.array([[1, 0], [0, -1]]))
    return corrupted_Z
Exemplo n.º 7
0
def dephased_i_gate(p=.1):
    corrupted_iden = append_kraus_to_gate(dephasing_kraus_map(p),
                                          np.array([[1, 0], [0, 1]]))
    return corrupted_iden
Exemplo n.º 8
0
def dephased_rz_gate(phi, p=.1):
    corrupted_rz = append_kraus_to_gate(
        dephasing_kraus_map(p),
        np.array([[quil_cos(phi / 2) - 1j * np.sin(phi / 2), 0],
                  [0, np.cos(phi / 2) + 1j * np.sin(phi / 2)]]))
    return corrupted_rz