Пример #1
0
def t2star_circuit_execution(
) -> Tuple[qiskit.result.Result, np.array, List[int], float, float]:
    """
    Create T2* circuits and simulate them.

    Returns:
        *   Backend result.
        *   xdata.
        *   Qubits for the T2* measurement.
        *   T2* that was used in the circuits creation.
        *   Frequency.
    """

    # Setting parameters

    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]

    t2_value = 10
    error = thermal_relaxation_error(np.inf, t2_value, 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

    # 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,
                                    seed_simulator=SEED,
                                    backend_options={
                                        'max_parallel_experiments': 0
                                    },
                                    noise_model=noise_model,
                                    optimization_level=0).result()

    return backend_result, xdata, qubits, t2_value, omega
Пример #2
0
    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, 30)).astype(int),
            (np.linspace(160, 450, 20)).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 = 300

        # 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

        fit = 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')

        self.assertAlmostEqual(fit.time(qid=0), expected_t2, delta=2,
                               msg='Calculated T2 is inaccurate')
        self.assertTrue(
            fit.time_err(qid=0) < 2,
            'Confidence in T2 calculation is too low: ' + str(fit.time_err))

        # 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

        fit = 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]))

        self.assertAlmostEqual(fit.time(qid=0), expected_t2, delta=2,
                               msg='Calculated T2 is inaccurate')
        self.assertTrue(
            fit.time_err(qid=0) < 2,
            'Confidence in T2 calculation is too low: ' + str(fit.time_err))
Пример #3
0
    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,
                                        seed_simulator=SEED,
                                        backend_options={
                                            'max_parallel_experiments': 0
                                        },
                                        noise_model=noise_model,
                                        optimization_level=0).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,
                                        seed_simulator=SEED,
                                        backend_options={
                                            'max_parallel_experiments': 0
                                        },
                                        noise_model=noise_model,
                                        optimization_level=0).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]))
Пример #4
0
    def test_t2star(self):
        """
        Run the simulator with phase damping noise.
        Then verify that the calculated T2star matches the phase damping
        parameter.
        """

        # Setting parameters

        # 25 numbers ranging from 100 to 1000, linearly spaced
        num_of_gates = num_of_gates = np.append(
            (np.linspace(10, 150, 30)).astype(int),
            (np.linspace(160, 450, 20)).astype(int))
        gate_time = 0.1
        num_of_qubits = 1
        qubit = 0

        expected_t2 = 10
        p = 1 - np.exp(-2 * gate_time / expected_t2)
        error = phase_damping_error(p)
        noise_model = NoiseModel()
        noise_model.add_all_qubit_quantum_error(error, 'id')

        backend = qiskit.Aer.get_backend('qasm_simulator')
        shots = 300
        # Estimating T2* via an exponential function
        circs, xdata, _ = t2star_circuits(num_of_gates, gate_time,
                                          num_of_qubits, qubit)
        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

        fit = T2StarExpFitter(backend_result,
                              shots,
                              xdata,
                              num_of_qubits,
                              qubit,
                              fit_p0=[initial_a, initial_t2, initial_c],
                              fit_bounds=([-0.5, 0, -0.5],
                                          [1.5, expected_t2 * 1.2, 1.5]))

        self.assertAlmostEqual(fit.time,
                               expected_t2,
                               delta=2,
                               msg='Calculated T2 is inaccurate')
        self.assertTrue(
            fit.time_err < 2,
            'Confidence in T2 calculation is too low: ' + str(fit.time_err))
        # Estimate T2* via an oscilliator function
        circs_osc, xdata, omega = t2star_circuits(num_of_gates, gate_time,
                                                  num_of_qubits, qubit, 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
        fit = T2StarOscFitter(
            backend_result,
            shots,
            xdata,
            num_of_qubits,
            qubit,
            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]))
        self.assertAlmostEqual(fit.time,
                               expected_t2,
                               delta=2,
                               msg='Calculated T2 is inaccurate')
        self.assertTrue(
            fit.time_err < 2,
            'Confidence in T2 calculation is too low: ' + str(fit.time_err))
print(result_real2.get_counts(0))

# # End of Run on Real Hardware

# End Circuit 2

# Question 2
print("Question 2:")

# T2* Charactirization circuit
SEED = 0
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, 1]
circs_osc, xdata, omega = t2star_circuits(num_of_gates, gate_time, qubits, 5)
shots = 2048

# Start of T2* characteristic whithout noise - simulation

# T2_cha_result = qiskit.execute(
#     circs_osc, backend,
#     shots=shots,
#     seed_simulator=SEED,
#     optimization_level=0).result()

# print("T2* characteristic - simulation without noise - NOT GOOD NEED TO CHANGE TO GRAPH")
# print(T2_cha_result.get_counts(0))

# End of T2* characteristic whithout noise  - simulation