Beispiel #1
0
circuit.x(2)
circuit.barrier()
circuit.h(0)
circuit.h(1)
circuit.h(2)

# measurement
# circuit.measure(range(num_qubits),range(num_qubits))

# End of Deutsch-Josza Algorithm - mod 2 =0

# Start Noise Configuration
noise_model = NoiseModel()
p1Q = 0.002
p2Q = 0.01
noise_model.add_all_qubit_quantum_error(depolarizing_error(p1Q, 1), 'u2')
noise_model.add_all_qubit_quantum_error(depolarizing_error(2 * p1Q, 1), 'u3')
noise_model.add_all_qubit_quantum_error(depolarizing_error(p2Q, 2), 'cx')
# End Noise configuration

# Start of Simulation with noise (thermal_relaxation_error)

# Start Noise Configuration

noise_model2 = NoiseModel()

#Add T1/T2 noise to the simulation
t1 = 100.
t2 = 80.
gate1Q = 0.1
gate2Q = 0.5
Beispiel #2
0
 def dummy_noise_model(self):
     """Return dummy noise model for dummy circuit"""
     noise_model = NoiseModel()
     error = pauli_error([('X', 0.25), ('I', 0.75)])
     noise_model.add_all_qubit_quantum_error(error, 'x')
     return noise_model
Beispiel #3
0
	
#______________________________________________________________________________________

# The Unitary is an identity (with a global phase)
backend = qiskit.Aer.get_backend('unitary_simulator')
basis_gates = ['u1','u2','u3','cx'] # use U,CX for now
job = qiskit.execute(qc, backend=backend, basis_gates=basis_gates)
print(np.around(job.result().get_unitary(),3))

#______________________________________________________________________________________

# Run on a noisy simulator
noise_model = NoiseModel()
# Depolarizing_error
dp = 0.005 
noise_model.add_all_qubit_quantum_error(depolarizing_error(dp, 1), ['u1', 'u2', 'u3'])
noise_model.add_all_qubit_quantum_error(depolarizing_error(2*dp, 2), 'cx')

backend = qiskit.Aer.get_backend('qasm_simulator')
#______________________________________________________________________________________

# Create the RB fitter
backend = qiskit.Aer.get_backend('qasm_simulator')
basis_gates = ['u1','u2','u3','cx'] 
shots = 200
qobj_list = []
rb_fit = rb.RBFitter(None, xdata, rb_opts['rb_pattern'])
for rb_seed,rb_circ_seed in enumerate(rb_circs):
    print('Compiling seed %d'%rb_seed)
    new_rb_circ_seed = qiskit.compiler.transpile(rb_circ_seed, basis_gates=basis_gates)
    qobj = qiskit.compiler.assemble(new_rb_circ_seed, shots=shots)
Beispiel #4
0
def get_noise(p):
    error_1 = depolarizing_error(p, 1)
    noise_model = NoiseModel()
    noise_model.add_all_qubit_quantum_error(error_1, ['x', 'u3']) 
    return noise_model
Beispiel #5
0
def get_noise(p):
    error_meas = pauli_error([('X', p), ('I', 1 - p)])
    noise_model = NoiseModel()
    noise_model.add_all_qubit_quantum_error(
        error_meas, "measure")  # measurement error is applied to measurements
    return noise_model
Beispiel #6
0
def main():
    # Noise

    device_backend = FakeVigo()
    coupling_map = device_backend.configuration().coupling_map
    simulator = Aer.get_backend('qasm_simulator')

    noise_model = NoiseModel()
    basis_gates = noise_model.basis_gates
    error = amplitude_damping_error(0.5)
    # error = depolarizing_error(0.5, 1)
    noise_model.add_all_qubit_quantum_error(error, ['id', 'u1', 'u2', 'u3'])

    # Circuit
    circ = QuantumCircuit(1, 1)
    circ.h(0)
    circ.measure([0], [0])
    print("*" * 25 + " Circuit " + "*" * 25)
    print(circ.draw())

    model1 = {'name': 'noisy', 'model': noise_model}
    model2 = {'name': 'ideal', 'model': None}
    noise_models = [model1, model2]
    print()
    print("*" * 25 + " Noise Models " + "*" * 25)
    pprint(noise_models)

    # Execution
    Dataset = [(run_circuit(circ, simulator, nm['model'], coupling_map,
                            basis_gates), nm) for nm in noise_models]

    # Data Prep
    for counts, nm in Dataset:
        counts.setdefault('0', 0)
        counts.setdefault('1', 0)

    X = [[x[1] for x in sorted(counts.items())] for counts, nm in Dataset]
    Y_raw = [nm['name'] for counts, nm in Dataset]
    zeros = [x[0] for x in X]
    le = preprocessing.LabelEncoder()
    le.fit(Y_raw)
    Y = le.transform(Y_raw)
    print()
    print("*" * 25 + " Dataset " + "*" * 25)
    print("Features: ", X)
    print("Labels: ", Y_raw)
    print("Encoded Labels: ", Y)

    # Training Classifier
    clf = RandomForestClassifier(random_state=0)
    clf.fit(X, Y)

    print()
    print("*" * 25 + " Predictions " + "*" * 25)

    # Predict labels on original data
    print("Prediction on training set: ",
          list(le.inverse_transform(clf.predict(X))))

    # Predict labels on new data
    Xtest = []
    Ytest = []
    for i in range(max(0, min(zeros) - 50), min(max(zeros) + 51, 1001)):
        feature = [[i, 1000 - i]]
        prediction = list(le.inverse_transform(clf.predict(feature)))
        # print("Prediction on {}: {}".format(feature, prediction))
        Xtest.append(i)
        Ytest.append(prediction[0])

    # Plot Diagrams

    fig = plt.figure()
    plt.scatter(Xtest, Ytest, label="test set")
    plt.scatter(zeros, Y_raw, label="training set")
    plt.xlabel("Feature = Count of '0' measurements")
    plt.ylabel("Predicted Label")
    plt.legend()
    # fig.axes.append(circ.draw(output='mpl').axes[0])
    plt.show()
    def test_t2star(self):
        """
        Run the simulator with thermal relaxation noise.
        Then verify that the calculated T2star matches the t2
        parameter.
        """

        # Setting parameters

        num_of_gates = num_of_gates = np.append(
            (np.linspace(10, 150, 10)).astype(int),
            (np.linspace(160, 450, 5)).astype(int))
        gate_time = 0.1
        qubits = [0]

        expected_t2 = 10
        error = thermal_relaxation_error(np.inf, expected_t2, gate_time, 0.5)
        noise_model = NoiseModel()
        noise_model.add_all_qubit_quantum_error(error, 'id')

        backend = qiskit.Aer.get_backend('qasm_simulator')
        shots = 200

        # Estimating T2* via an exponential function
        circs, xdata, _ = t2star_circuits(num_of_gates, gate_time, qubits)
        backend_result = qiskit.execute(circs,
                                        backend,
                                        shots=shots,
                                        backend_options={
                                            'max_parallel_experiments': 0
                                        },
                                        noise_model=noise_model).result()

        initial_t2 = expected_t2
        initial_a = 0.5
        initial_c = 0.5

        T2Fitter(backend_result,
                 xdata,
                 qubits,
                 fit_p0=[initial_a, initial_t2, initial_c],
                 fit_bounds=([-0.5, 0, -0.5], [1.5, expected_t2 * 1.2, 1.5]),
                 circbasename='t2star')

        # Estimate T2* via an oscilliator function
        circs_osc, xdata, omega = t2star_circuits(num_of_gates, gate_time,
                                                  qubits, 5)

        backend_result = qiskit.execute(circs_osc,
                                        backend,
                                        shots=shots,
                                        backend_options={
                                            'max_parallel_experiments': 0
                                        },
                                        noise_model=noise_model).result()

        initial_a = 0.5
        initial_c = 0.5
        initial_f = omega
        initial_phi = 0

        T2StarFitter(
            backend_result,
            xdata,
            qubits,
            fit_p0=[initial_a, initial_t2, initial_f, initial_phi, initial_c],
            fit_bounds=([-0.5, 0, omega - 0.02, -np.pi, -0.5],
                        [1.5, expected_t2 * 1.2, omega + 0.02, np.pi, 1.5]))