示例#1
0
def reset_noise_model():
    """Return test reset noise model"""
    noise_model = NoiseModel()
    error1 = thermal_relaxation_error(50, 50, 0.1)
    noise_model.add_all_qubit_quantum_error(error1, ['u1', 'u2', 'u3'])
    error2 = error1.tensor(error1)
    noise_model.add_all_qubit_quantum_error(error2, ['cx'])
    return NoiseWithDescription(noise_model, "Reset Noise")
示例#2
0
def reset_noise_model():
    """Return test reset noise model"""
    noise_model = NoiseModel()
    error1 = thermal_relaxation_error(50, 50, 0.1)
    noise_model.add_all_qubit_quantum_error(error1, ['u1', 'u2', 'u3'])
    error2 = error1.kron(error1)
    noise_model.add_all_qubit_quantum_error(error2, ['cx'])
    return noise_model
def thermal_noise(n_qubits, mu1, mu2, sig):
    num = n_qubits
    # T1 and T2 values for qubits 0-3
    T1s = np.random.normal(
        mu1, sig, num)  # Sampled from normal distribution mean 50 microsec
    T2s = np.random.normal(
        mu2, sig, num)  # Sampled from normal distribution mean 50 microsec

    # Truncate random T2s <= T1s
    T2s = np.array([min(T2s[j], 2 * T1s[j]) for j in range(num)])

    # Instruction times (in nanoseconds)
    time_u1 = 0  # virtual gate
    time_u2 = 50  # (single X90 pulse)
    time_u3 = 100  # (two X90 pulses)
    time_cx = 300
    time_reset = 1000  # 1 microsecond
    time_measure = 1000  # 1 microsecond

    # QuantumError objects
    errors_reset = [
        thermal_relaxation_error(t1, t2, time_reset)
        for t1, t2 in zip(T1s, T2s)
    ]
    errors_measure = [
        thermal_relaxation_error(t1, t2, time_measure)
        for t1, t2 in zip(T1s, T2s)
    ]
    errors_u1 = [
        thermal_relaxation_error(t1, t2, time_u1) for t1, t2 in zip(T1s, T2s)
    ]
    errors_u2 = [
        thermal_relaxation_error(t1, t2, time_u2) for t1, t2 in zip(T1s, T2s)
    ]
    errors_u3 = [
        thermal_relaxation_error(t1, t2, time_u3) for t1, t2 in zip(T1s, T2s)
    ]
    errors_cx = [[
        thermal_relaxation_error(t1a, t2a, time_cx).expand(
            thermal_relaxation_error(t1b, t2b, time_cx))
        for t1a, t2a in zip(T1s, T2s)
    ] for t1b, t2b in zip(T1s, T2s)]

    # Add errors to noise model
    noise_thermal = NoiseModel()
    for j in range(num):
        noise_thermal.add_quantum_error(errors_reset[j], "reset", [j])
        noise_thermal.add_quantum_error(errors_measure[j], "measure", [j])
        noise_thermal.add_quantum_error(errors_u1[j], "u1", [j])
        noise_thermal.add_quantum_error(errors_u2[j], "u2", [j])
        noise_thermal.add_quantum_error(errors_u3[j], "u3", [j])
        for k in range(num):
            noise_thermal.add_quantum_error(errors_cx[j][k], "cx", [j, k])

    return noise_thermal
def thermalRelaxationChannel(backend, T1s, T2s, graph, gates):
    '''Method that returns the thermal relaxation error quantum channel.'''
    
    graph = [[0,1], [1,2], [2,3]] # The two-qubit gates that we are interested in
    names = [0, 1, 2, 3] # The single-qubit gates that we are interested in

    # Instruction times (in nanoseconds)
    time_u1 = 10 # virtual gate
    time_u2 = getSQGateExecutionTime('x', backend, gates) # Average of all u2 times
    time_u3 = getSQGateExecutionTime('x', backend, gates) # Average of all u3 times
    time_cx = getTQGateExecutionTime('cx', backend, graph) # Average of all cx times
    time_reset = 1000  # 1 microsecond
    time_measure = 1000 # 1 microsecond

    # QuantumError objects
    errors_reset = [thermal_relaxation_error(t1, t2, time_reset)
                    for t1, t2 in zip(T1s, T2s)]
    errors_measure = [thermal_relaxation_error(t1, t2, time_measure)
                      for t1, t2 in zip(T1s, T2s)]
    errors_u1  = [thermal_relaxation_error(t1, t2, time_u1)
                  for t1, t2 in zip(T1s, T2s)]
    errors_u2  = [thermal_relaxation_error(t1, t2, time_u2)
                  for t1, t2 in zip(T1s, T2s)]
    errors_u3  = [thermal_relaxation_error(t1, t2, time_u3)
                  for t1, t2 in zip(T1s, T2s)]
    errors_cx = [[thermal_relaxation_error(t1a, t2a, time_cx).expand(
                 thermal_relaxation_error(t1b, t2b, time_cx))
                  for t1a, t2a in zip(T1s, T2s)]
                   for t1b, t2b in zip(T1s, T2s)]

    # Add errors to noise model
    noise_thermal = NoiseModel()
    for j in range(len(T1s)):
        noise_thermal.add_quantum_error(errors_reset[j], "reset", [j])
        noise_thermal.add_quantum_error(errors_measure[j], "measure", [j])
        noise_thermal.add_quantum_error(errors_u1[j], "u1", [j])
        noise_thermal.add_quantum_error(errors_u2[j], "u2", [j])
        noise_thermal.add_quantum_error(errors_u3[j], "u3", [j])
        for k in range(len(T1s)):
            noise_thermal.add_quantum_error(errors_cx[j][k], "cx", [j, k])
            
    return noise_thermal
def thermal_noise(mu1, mu2, sigma, p, t):
    num = 2 + (2 * t - 1) * p

    # T1 and T2 values for qubits 0-num
    T1s = np.random.normal(
        mu1, sigma, num
    )  # Sampled from normal distribution mean mu1 microsec, sigma = 10e3
    T2s = np.random.normal(
        mu2, sigma, num)  # Sampled from normal distribution mean mu2 microsec

    # Truncate random T2s <= T1s
    T2s = np.array([min(T2s[j], 2 * T1s[j]) for j in range(num)])

    # Instruction times (in nanoseconds)
    time_u1 = 0  # virtual gate
    time_u2 = 50  # (single X90 pulse)
    time_u3 = 100  # (two X90 pulses)
    time_cx = 300

    #Time to implement controlled/controlled-controlled evolution unitary
    #Done this way to save on computational cost of simulating noise.
    time_cu = 2 * (2 * time_u1 + 2 * time_cx + 2 * time_u3
                   )  #time is 2* cu3(1).
    time_ccu = 3 * (
        2 * time_u1 + 2 * time_cx + 2 * time_u3
    ) + 2 * time_cx  #ccu(2) can be decomposed into 2 ccu(1) which can be decomposed to 3 cu3(1) and 2 cx gates

    # QuantumError objects
    errors_u1 = [
        thermal_relaxation_error(t1, t2, time_u1) for t1, t2 in zip(T1s, T2s)
    ]
    errors_u2 = [
        thermal_relaxation_error(t1, t2, time_u2) for t1, t2 in zip(T1s, T2s)
    ]
    errors_u3 = [
        thermal_relaxation_error(t1, t2, time_u3) for t1, t2 in zip(T1s, T2s)
    ]
    errors_cx = [[
        thermal_relaxation_error(t1a, t2a, time_cx).expand(
            thermal_relaxation_error(t1b, t2b, time_cx))
        for t1a, t2a in zip(T1s, T2s)
    ] for t1b, t2b in zip(T1s, T2s)]
    errors_cu = [[[
        thermal_relaxation_error(t1a, t2a, time_cu).expand(
            thermal_relaxation_error(t1b, t2b, time_cu).expand(
                thermal_relaxation_error(t1c, t2c, time_cu)))
        for t1a, t2a in zip(T1s, T2s)
    ] for t1b, t2b in zip(T1s, T2s)] for t1c, t2c in zip(T1s, T2s)]

    if num > 5:  #i.e. more than 1 iteration of PEA

        errors_ccu = [[[[
            thermal_relaxation_error(t1a, t2a, time_ccu).expand(
                thermal_relaxation_error(t1b, t2b, time_ccu).expand(
                    thermal_relaxation_error(t1c, t2c, time_ccu).expand(
                        thermal_relaxation_error(t1d, t2d, time_ccu))))
            for t1a, t2a in zip(T1s, T2s)
        ] for t1b, t2b in zip(T1s, T2s)] for t1c, t2c in zip(T1s, T2s)]
                      for t1d, t2d in zip(T1s, T2s)]

    # Add errors to noise model
    noise_thermal = NoiseModel()

    for j in range(num):
        noise_thermal.add_quantum_error(errors_u1[j], "u1", [j])
        noise_thermal.add_quantum_error(errors_u2[j], "u2", [j])
        noise_thermal.add_quantum_error(errors_u3[j], "u3", [j])
        for k in range(num):
            noise_thermal.add_quantum_error(errors_cx[j][k], "cx", [j, k])

    #Only Need CU and CCU gate noise between qubits that actually implement this gate!

    state_qubit_0 = num - 2
    state_qubit_1 = num - 1

    for q in range(
            t
    ):  #CU only acts on state qubits and register from first round (in this order)
        noise_thermal.add_quantum_error(
            errors_cu[state_qubit_1][state_qubit_0][q], "cu",
            [state_qubit_1, state_qubit_0, q])

    if num > 5:
        for j in range(
                1, p
        ):  #CCU acts on state qubits, or qubit from previous round and fresh register qubits (in this order)
            for q in range(t * j, t * (j + 1)):
                noise_thermal.add_quantum_error(
                    errors_ccu[state_qubit_1][state_qubit_0][p * t +
                                                             (j - 1)][q],
                    "ccu", [state_qubit_1, state_qubit_0, p * t + (j - 1), q])

    noise_thermal.add_basis_gates(['unitary'])
    return noise_thermal
                       4)  # Sampled from normal distribution mean 50 microsec

# Truncate random T2s <= T1s
T2s = np.array([min(T2s[j], 2 * T1s[j]) for j in range(4)])

# Instruction times (in nanoseconds)
time_u1 = 0  # virtual gate
time_u2 = 50  # (single X90 pulse)
time_u3 = 100  # (two X90 pulses)
time_cx = 300
time_reset = 1000  # 1 microsecond
time_measure = 1000  # 1 microsecond

# QuantumError objects
errors_reset = [
    thermal_relaxation_error(t1, t2, time_reset) for t1, t2 in zip(T1s, T2s)
]
errors_measure = [
    thermal_relaxation_error(t1, t2, time_measure) for t1, t2 in zip(T1s, T2s)
]
errors_u1 = [
    thermal_relaxation_error(t1, t2, time_u1) for t1, t2 in zip(T1s, T2s)
]
errors_u2 = [
    thermal_relaxation_error(t1, t2, time_u2) for t1, t2 in zip(T1s, T2s)
]
errors_u3 = [
    thermal_relaxation_error(t1, t2, time_u3) for t1, t2 in zip(T1s, T2s)
]
errors_cx = [[
    thermal_relaxation_error(t1a, t2a, time_cx).expand(