コード例 #1
0
def get_data_point(circ, theta, phi, lam, readout_params, depol_param, thermal_params, shots):
    """Generate a dict datapoint with the given circuit and noise parameters"""
    U3_gate_length = 7.111111111111112e-08

    # extract parameters
    (p0_0, p1_0), (p0_1, p1_1) = readout_params
    depol_prob = depol_param
    t1, t2, population = thermal_params

    # Add Readout and Quantum Errors
    noise_model = NoiseModel()
    noise_model.add_all_qubit_readout_error(ReadoutError(readout_params))
    noise_model.add_all_qubit_quantum_error(depolarizing_error(depol_param, 1), 'u3', warnings=False)
    noise_model.add_all_qubit_quantum_error(
        thermal_relaxation_error(t1, t2, U3_gate_length, excited_state_population=population), 'u3',
        warnings=False)
    job = execute(circ, QasmSimulator(), shots=shots, noise_model=noise_model)
    result = job.result()

    # add data point to DataFrame
    data_point = {'theta': theta,
                  'phi': phi,
                  'lam': lam,
                  'p0_0': p0_0,
                  'p1_0': p1_0,
                  'p0_1': p0_1,
                  'p1_1': p1_1,
                  'depol_prob': depol_prob,
                  't1': t1,
                  't2': t2,
                  'population': population,
                  'E': result.get_counts(0).get('1', 0) / shots}

    return data_point
コード例 #2
0
def make_noise_model(dep_err_rate, ro_err_rate, qubits):
    # Define a noise model that applies uniformly to the given qubits
    model = NoiseModel()
    dep_err = depolarizing_error(dep_err_rate, 2)
    ro_err = ReadoutError(
        [[1 - ro_err_rate, ro_err_rate], [ro_err_rate, 1 - ro_err_rate]]
    )
    # Add depolarising error to CX gates between any qubits (implying full connectivity)
    for i, j in product(qubits, repeat=2):
        model.add_quantum_error(dep_err, ["cx"], [i, j])
    # Add readout error for each qubit
    for i in qubits:
        model.add_readout_error(ro_err, qubits=[i])
    return model
コード例 #3
0
def get_data_point(theta, phi, lam, readout_params, depol_param,
                   thermal_params, shots):
    """Generate a dict datapoint with the given circuit and noise parameters"""
    U3_gate_length = 7.111111111111112e-08

    circ = QuantumCircuit(1, 1)
    circ.append(U3Gate(theta, phi, lam), [0])
    circ.measure(0, 0)
    new_circ = qiskit.compiler.transpile(circ,
                                         basis_gates=['u3'],
                                         optimization_level=0)

    # extract parameters
    (p0_0, p1_0), (p0_1, p1_1) = readout_params
    depol_prob = depol_param
    t1, t2, population = thermal_params

    noise_model = NoiseModel()

    # Add Readout and Quantum Errors
    noise_model.add_all_qubit_readout_error(ReadoutError(readout_params))
    noise_model.add_all_qubit_quantum_error(depolarizing_error(depol_param, 1),
                                            'u3',
                                            warnings=False)
    noise_model.add_all_qubit_quantum_error(thermal_relaxation_error(
        t1, t2, U3_gate_length, population),
                                            'u3',
                                            warnings=False)
    job = execute(circ, QasmSimulator(), shots=shots, noise_model=noise_model)
    result = job.result()

    # add data point to DataFrame
    data_point = {
        'theta': theta,
        'phi': phi,
        'lam': lam,
        'p0_0': p0_0,
        'p1_0': p1_0,
        'p0_1': p0_1,
        'p1_1': p1_1,
        'depol_prob': depol_prob,
        't1': t1,
        't2': t2,
        'population': population,
        'E': result.get_counts(0).get('0', 0) / shots
    }

    return data_point
コード例 #4
0
 def out_readout_error(op, qubits):
     return ReadoutError([[1, 0], [0, 1]])
コード例 #5
0
ファイル: NoiseModel.py プロジェクト: QML-UY1/VQE_Research
def generateNoiseModel(machine,
                       coherent=True,
                       incoherent=False,
                       readout=False,
                       custom_t=False,
                       t1=None,
                       t2=None,
                       reverse=False):
    """
    Returns a realistic copy of london noise model with custom t1, t2 times
    """

    #initializing noise model
    noise_thermal = NoiseModel()
    amp = 1

    #for every qubit (5 qubit london machine)
    for q in range(5):
        #types of erroneous gates
        gates = ['u3', 'u2', 'u1', 'id']

        for gate in gates:
            dep_error = None
            if (coherent):
                dep_error = generateDepolarizingError(machine, gate, [q])
            rel_error = None
            if (incoherent):
                generateRelaxationError(machine,
                                        gate, [q],
                                        t1,
                                        t2,
                                        amp=amp,
                                        custom_t=custom_t)

            if (dep_error == None and rel_error != None):
                error_obj = rel_error
                noise_thermal.add_quantum_error(error_obj, gate, [q])

            elif (dep_error != None and rel_error == None):
                error_obj = dep_error
                noise_thermal.add_quantum_error(error_obj, gate, [q])

            elif (dep_error != None and rel_error != None):
                error_obj = dep_error.compose(rel_error)
                noise_thermal.add_quantum_error(error_obj, gate, [q])

        #2 qubit gate errors
        qubits = [i for i in range(5)]
        qubits.remove(q)
        for j in qubits:
            dep_error = None
            if (coherent):
                dep_error = generateDepolarizingError(machine, 'cx', [q, j])
            rel_error = None
            if (incoherent):
                rel_error = generateRelaxationError(machine,
                                                    'cx', [q, j],
                                                    t1,
                                                    t2,
                                                    amp=amp,
                                                    custom_t=custom_t)

            if (dep_error == None and rel_error != None):
                error_obj = rel_error
                noise_thermal.add_quantum_error(error_obj, 'cx', [q, j])

            elif (dep_error != None and rel_error == None):
                error_obj = dep_error
                noise_thermal.add_quantum_error(error_obj, 'cx', [q, j])

            elif (dep_error != None and rel_error != None):
                error_obj = dep_error.compose(rel_error)
                noise_thermal.add_quantum_error(error_obj, 'cx', [q, j])
        if (readout):
            #adding the readout error
            p1_0 = machine.properties().qubit_property(q,
                                                       'prob_meas1_prep0')[0]
            p0_1 = machine.properties().qubit_property(q,
                                                       'prob_meas0_prep1')[0]

            print('Original: ' + str(p1_0) + ' ' + str(p0_1))

            if (reverse):
                temp = p1_0
                p1_0 = p0_1
                p0_1 = temp
            print('Reverse: ' + str(p1_0) + ' ' + str(p0_1))

            matrix = [[1 - p1_0, p1_0], [p0_1, 1 - p0_1]]
            error = ReadoutError(matrix)

            noise_thermal.add_readout_error(error, [q])

    return noise_thermal