Пример #1
0
    def test_ampcal1Q(self):
        """
        Run the amplitude cal circuit generation and through the
        simulator to make sure there are no errors
        """

        self._circs, xdata = ampcal_1Q_circuits(self._maxrep, self._qubits)

        # Set the simulator
        # Add a rotation error
        err_unitary = np.zeros([2, 2], dtype=complex)
        angle_err = 0.1
        for i in range(2):
            err_unitary[i, i] = np.cos(angle_err)
            err_unitary[i, (i + 1) % 2] = np.sin(angle_err)
        err_unitary[0, 1] *= -1.0

        error = coherent_unitary_error(err_unitary)
        noise_model = NoiseModel()
        noise_model.add_all_qubit_quantum_error(error, 'u2')

        initial_theta = 0.18
        initial_c = 0.5

        fit = AmpCalFitter(self.run_sim(noise_model),
                           xdata,
                           self._qubits,
                           fit_p0=[initial_theta, initial_c],
                           fit_bounds=([-np.pi, -1], [np.pi, 1]))
        print(fit.angle_err(0))
        self.assertAlmostEqual(fit.angle_err(0), 0.1, 2)
error_unitary_matrix[0, 1] *= -1.0

error = coherent_unitary_error(error_unitary_matrix)
my_noise_model = NoiseModel()
my_noise_model.add_all_qubit_quantum_error(error, 'u2')

# Runs simulator
backend = Aer.get_backend('qasm_simulator')
trials = 500
result = execute(circuits, backend, shots=trials,
                 noise_model=my_noise_model).result()

# FIts data to an oscillation
plt.figure(figsize=(10,6))
theta, c = 0.02, 0.5                # ?: again, what are these parameter values?
initial_parameter_bias = [theta, c]
parameter_lower_bounds = [-np.pi, -1]
parameter_upper_bounds = [np.pi, 1]
amplitude_calibration_fit = AmpCalFitter(result, delay_times, qubits,
                                         fit_p0 = initial_parameter_bias,
                                         fit_bounds=(parameter_lower_bounds,
                                                     parameter_upper_bounds))
amplitude_calibration_fit.plot(1, ax=plt.gca())
open_plot()

rotation_error = amplitude_calibration_fit.angle_err()[0]
print("Rotation Error on U2: %f rads" % rotation_error)

if __name__ == "__main__":
    pass