Пример #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)
print("Import complete.")

def open_plot():
    '''
    Opens and maximizes the current figure.
    '''
    manager = plt.get_current_fig_manager()
    manager.window.showMaximized()


## Ammplitude Error Characterization for Single Qubit Gates

# Measures amplitude error, in the pi/2 pulse, on qubits 2 and 4
qubits = [4, 2]
max_circuit_repetitions = 10
circuits, delay_times = ampcal_1Q_circuits(max_circuit_repetitions, qubits)

# Sets simulator and adds rotation error.
angle_error = 0.1
error_unitary_matrix = np.zeros([2,2], dtype=complex)
for i in range(2):
    error_unitary_matrix[i, i] = np.cos(angle_error)
    error_unitary_matrix[i, (i+1) % 2] = np.sin(angle_error)
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')