def noise_model_phase(error, measure=True, thermal=True): """ Creates error for phase flip :param error: Probability of happening a phaseflip :param measure: True or False, whether we include readout errors with probability 10 * error :param thermal: True or False, whether we include thermal relaxation, see noise_model_thermal :return: noise model for the error """ noise_model = NoiseModel() #basis_gates=['id', 'u2', 'u3', 'cx']) phase_error = error cz_error = 2 * error phase_flip = pauli_error([('Z', phase_error), ('I', 1 - phase_error)]) cz_error = pauli_error([('Z', cz_error), ('I', 1 - cz_error)]) cz_error = cz_error.tensor(cz_error) noise_model.add_all_qubit_quantum_error(cz_error, ['cx'], warnings=False) noise_model.add_all_qubit_quantum_error(phase_flip, ["u1", "u2", "u3"]) if measure: measure_error = 10 * error measure_error = array([[1 - measure_error, measure_error], [measure_error, 1 - measure_error]]) noise_model.add_all_qubit_readout_error(measure_error) if thermal: thermal = thermal_relaxation_error(1.5, 1.2, error) cthermal = thermal_relaxation_error(1.5, 1.2, 2 * error) cthermal = cthermal.tensor(cthermal) noise_model.add_all_qubit_quantum_error(cthermal, ['cx'], warnings=False) noise_model.add_all_qubit_quantum_error(thermal, ["u1", "u2", "u3"], warnings=False) return noise_model
def noise_model_bit(error, measure=True, thermal=True): """ Creates error for bit flip :param error: Probability of happening a bitflip :param measure: True or False, whether we include readout errors with probability 10 * error :param thermal: True or False, whether we include thermal relaxation, see noise_model_thermal :return: noise model for the error """ noise_model = NoiseModel() flip_error = error cnot_error = 2 * error bit_flip = pauli_error([('X', flip_error), ('I', 1 - flip_error)]) cnot_flip = pauli_error([('X', cnot_error), ('I', 1 - cnot_error)]) cnot_error = cnot_flip.tensor(cnot_flip) noise_model.add_all_qubit_quantum_error(bit_flip, ["u1", "u2", "u3"]) noise_model.add_all_qubit_quantum_error(cnot_error, ['cx'], warnings=False) if measure: measure_error = 10 * error measure_error = array([[1 - measure_error, measure_error], [measure_error, 1 - measure_error]]) noise_model.add_all_qubit_readout_error(measure_error) if thermal: thermal = thermal_relaxation_error(1.5, 1.2, error) cthermal = thermal_relaxation_error(1.5, 1.2, 2 * error) cthermal = cthermal.tensor(cthermal) noise_model.add_all_qubit_quantum_error(cthermal, ['cx'], warnings=False) noise_model.add_all_qubit_quantum_error(thermal, ["u1", "u2", "u3"], warnings=False) return noise_model
def create_pta_channel(T_1: float, T_2: float, t_step: float = 10e-9) -> NoiseModel: """Creates a noise model that does both phase and amplitude damping but in the Pauli Twirling Approximation discussed the following reference https://arxiv.org/pdf/1305.2021.pdf Args: T_1: Relaxation time (seconds) T_2: dephasing time (seconds) t_step: Discretized time step over which the relaxation occurs over (seconds) """ p_x = 0.25 * (1 - pow(np.e, -t_step / T_1)) p_y = 0.25 * (1 - pow(np.e, -t_step / T_1)) exp_1 = pow(np.e, -t_step / (2 * T_1)) exp_2 = pow(np.e, -t_step / T_2) p_z = 0.5 - p_x - 0.5 * exp_1 * exp_2 p_i = 1 - p_x - p_y - p_z errors = [("X", p_x), ("Y", p_y), ("Z", p_z), ("I", p_i)] pta_error = pauli_error(errors) noise_model = NoiseModel() noise_model.add_all_qubit_quantum_error(pta_error, ["id", "u3"]) gate_error = pta_error.tensor(pta_error) noise_model.add_all_qubit_quantum_error(gate_error, ["cx"]) return noise_model
def create_quantum_computer_simulation(couplingmap, depolarizingnoise=False, depolarizingnoiseparameter=0, bitfliperror=False, bitfliperrorparameter=0, measerror=False, measerrorparameter=0): """ Returns a dictionary, where the key is what type of simulation ("noisy_qasm", "noiseless_qasm", "real"), and the value are the objects required for that particular simulation """ sims = ["noisy_qasm", "noiseless_qasm"] dicto = dict() for sim in sims: if sim == "noiseless_qasm": backend = Aer.get_backend('qasm_simulator') dicto[sim] = backend elif sim == "noisy_qasm": backend = Aer.get_backend('qasm_simulator') coupling_map = CouplingMap(couplingmap) noise_model = NoiseModel() if depolarizingnoise == True: depolarizingerror = depolarizing_error( depolarizingnoiseparameter, 1) noise_model.add_all_qubit_quantum_error( depolarizingerror, ['u1', 'u2', 'u3']) if bitfliperror == True: error_gate1 = pauli_error([('X', bitfliperrorparameter), ('I', 1 - bitfliperrorparameter)]) noise_model.add_all_qubit_quantum_error( error_gate1, ["u1", "u2", "u3"]) error_gate2 = error_gate1.tensor(error_gate1) noise_model.add_all_qubit_quantum_error(error_gate2, ["cx"]) if measerror == True: error_meas = pauli_error([('X', measerrorparameter), ('I', 1 - measerrorparameter)]) noise_model.add_all_qubit_quantum_error(error_meas, "measure") dicto[sim] = (backend, coupling_map, noise_model) return dicto
def get_phase_flip(p): """ Return a phase flip error in qiskit. Parameters ---------- p: float: a probability. Returns ------- type: qiskit pauli error """ return qiskitnoise.pauli_error(noise_ops=[('Z', p), ('I', 1 - p)])
def test_backend_options_cleaned(self): """Test that the backend options are cleared upon new Aer device initialization.""" noise_model = noise.NoiseModel() bit_flip = noise.pauli_error([("X", 1), ("I", 0)]) # Create a noise model where the RX operation always flips the bit noise_model.add_all_qubit_quantum_error(bit_flip, ["rx"]) dev = qml.device("qiskit.aer", wires=2, noise_model=noise_model) assert dev.backend.options.get("noise_model") is not None dev2 = qml.device("qiskit.aer", wires=2) assert dev2.backend.options.get("noise_model") is None
def test_backend_options_cleaned(self): """Test that the backend options are cleared upon new Aer device initialization.""" noise_model = noise.NoiseModel() bit_flip = noise.pauli_error([('X', 1), ('I', 0)]) # Create a noise model where the RX operation always flips the bit noise_model.add_all_qubit_quantum_error(bit_flip, ["rx"]) dev = qml.device('qiskit.aer', wires=2, noise_model=noise_model) assert 'noise_model' in dev.backend.options dev2 = qml.device('qiskit.aer', wires=2) assert 'noise_model' not in dev2.backend.options
def create_pta_channel(T_1, T_2, t_step=10e-9): """ Creates a noise model that does both phase and amplitude damping but in the Pauli Twirling Approximation discussed the following reference https://arxiv.org/pdf/1305.2021.pdf Args: T_1 (float) : Relaxation time (seconds) T_2 (float) : dephasing time (seconds) t_step (float) : Discretized time step over which the relaxation occurs over (seconds) Returns: qiskit.providers.aer.noise.NoiseModel """ if T_1 == T_2: t_phi = 2*T_1 elif 2*T_1 == T_2: raise RuntimeError(" T_2 == 2*T_1 only in a pure amplitude damping case ") else: t_phi = T_2 - 2*T_1 p_x = 0.25*(1- pow(np.e, - t_step/T_1)) p_y = 0.25*(1- pow(np.e, - t_step/T_1)) exp_1 = pow(np.e, -t_step/(2*T_1)) exp_2 = pow(np.e, -t_step/t_phi) p_z = (0.5 - p_x - 0.5*exp_1*exp_2) p_i = 1 - p_x - p_y - p_z errors = [('X', p_x), ('Y', p_y), ('Z', p_z), ('I', p_i)] pta_error = pauli_error(errors) noise_model = NoiseModel() noise_model.add_all_qubit_quantum_error(pta_error, ['id', 'u3']) gate_error = pta_error.tensor(pta_error) noise_model.add_all_qubit_quantum_error(gate_error, ['cx']) return noise_model
def buildNoiseModel(errorProba, probaType): noise_bit_flip = NoiseModel() error = pauli_error([('X', probaType * errorProba), ('I', 1 - errorProba), ('Z', (1 - probaType) * errorProba)]) noise_bit_flip.add_all_qubit_quantum_error(error, ["id"]) return noise_bit_flip
job = execute(circ, ideal_simulator) result_ideal = job.result() plot_histogram(result_ideal.get_counts(0)) # # Noise Simulation _ 1 #%% # Example error probabilities p_reset = 0.03 p_meas = 0.1 p_gate1 = 0.05 #%% # QuantumError objects error_reset = pauli_error([('X', p_reset), ('I', 1 - p_reset)]) error_meas = pauli_error([('X',p_meas), ('I', 1 - p_meas)]) error_gate1 = pauli_error([('X',p_gate1), ('I', 1 - p_gate1)]) error_gate2 = error_gate1.tensor(error_gate1) # Add errors to noise model noise_bit_flip = NoiseModel() noise_bit_flip.add_all_qubit_quantum_error(error_reset, "reset") noise_bit_flip.add_all_qubit_quantum_error(error_meas, "measure") noise_bit_flip.add_all_qubit_quantum_error(error_gate1, ["u1", "u2", "u3"]) noise_bit_flip.add_all_qubit_quantum_error(error_gate2, ["cx"]) print(noise_bit_flip) # In[6]:
def bit_flip_noise(p): noise_model = NoiseModel() error = pauli_error([('X', p), ('I', 1 - p)]) noise_model.add_all_qubit_quantum_error(error, 'noise') noise_model.add_basis_gates(['unitary']) return noise_model
def get_bit_flip(p): return qiskitnoise.pauli_error(noise_ops=[('X', p), ('I', 1 - p)])
def get_phase_flip(p): return qiskitnoise.pauli_error(noise_ops=[('Z', p), ('I', 1 - p)])