def get_counts(self, qc): # Construct the error i_error = get_quantum_error(self.n) # Build the noise model by adding the error to the "iswap" gate noise_model = NoiseModel() noise_model.add_all_qubit_quantum_error(i_error, 'noisy_I') noise_model.add_basis_gates(['unitary']) # Execute on the simulator with noise job = execute(qc, QasmSimulator(), shots=1024, basis_gates=noise_model.basis_gates, noise_model=noise_model) result = job.result() return result.get_counts(qc)
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 thermal_noise(mu1, mu2, sigma, p, t): num = 2 + (2 * t - 1) * p # T1 and T2 values for qubits 0-num T1s = np.random.normal( mu1, sigma, num ) # Sampled from normal distribution mean mu1 microsec, sigma = 10e3 T2s = np.random.normal( mu2, sigma, num) # Sampled from normal distribution mean mu2 microsec # Truncate random T2s <= T1s T2s = np.array([min(T2s[j], 2 * T1s[j]) for j in range(num)]) # Instruction times (in nanoseconds) time_u1 = 0 # virtual gate time_u2 = 50 # (single X90 pulse) time_u3 = 100 # (two X90 pulses) time_cx = 300 #Time to implement controlled/controlled-controlled evolution unitary #Done this way to save on computational cost of simulating noise. time_cu = 2 * (2 * time_u1 + 2 * time_cx + 2 * time_u3 ) #time is 2* cu3(1). time_ccu = 3 * ( 2 * time_u1 + 2 * time_cx + 2 * time_u3 ) + 2 * time_cx #ccu(2) can be decomposed into 2 ccu(1) which can be decomposed to 3 cu3(1) and 2 cx gates # QuantumError objects errors_u1 = [ thermal_relaxation_error(t1, t2, time_u1) for t1, t2 in zip(T1s, T2s) ] errors_u2 = [ thermal_relaxation_error(t1, t2, time_u2) for t1, t2 in zip(T1s, T2s) ] errors_u3 = [ thermal_relaxation_error(t1, t2, time_u3) for t1, t2 in zip(T1s, T2s) ] errors_cx = [[ thermal_relaxation_error(t1a, t2a, time_cx).expand( thermal_relaxation_error(t1b, t2b, time_cx)) for t1a, t2a in zip(T1s, T2s) ] for t1b, t2b in zip(T1s, T2s)] errors_cu = [[[ thermal_relaxation_error(t1a, t2a, time_cu).expand( thermal_relaxation_error(t1b, t2b, time_cu).expand( thermal_relaxation_error(t1c, t2c, time_cu))) for t1a, t2a in zip(T1s, T2s) ] for t1b, t2b in zip(T1s, T2s)] for t1c, t2c in zip(T1s, T2s)] if num > 5: #i.e. more than 1 iteration of PEA errors_ccu = [[[[ thermal_relaxation_error(t1a, t2a, time_ccu).expand( thermal_relaxation_error(t1b, t2b, time_ccu).expand( thermal_relaxation_error(t1c, t2c, time_ccu).expand( thermal_relaxation_error(t1d, t2d, time_ccu)))) for t1a, t2a in zip(T1s, T2s) ] for t1b, t2b in zip(T1s, T2s)] for t1c, t2c in zip(T1s, T2s)] for t1d, t2d in zip(T1s, T2s)] # Add errors to noise model noise_thermal = NoiseModel() for j in range(num): noise_thermal.add_quantum_error(errors_u1[j], "u1", [j]) noise_thermal.add_quantum_error(errors_u2[j], "u2", [j]) noise_thermal.add_quantum_error(errors_u3[j], "u3", [j]) for k in range(num): noise_thermal.add_quantum_error(errors_cx[j][k], "cx", [j, k]) #Only Need CU and CCU gate noise between qubits that actually implement this gate! state_qubit_0 = num - 2 state_qubit_1 = num - 1 for q in range( t ): #CU only acts on state qubits and register from first round (in this order) noise_thermal.add_quantum_error( errors_cu[state_qubit_1][state_qubit_0][q], "cu", [state_qubit_1, state_qubit_0, q]) if num > 5: for j in range( 1, p ): #CCU acts on state qubits, or qubit from previous round and fresh register qubits (in this order) for q in range(t * j, t * (j + 1)): noise_thermal.add_quantum_error( errors_ccu[state_qubit_1][state_qubit_0][p * t + (j - 1)][q], "ccu", [state_qubit_1, state_qubit_0, p * t + (j - 1), q]) noise_thermal.add_basis_gates(['unitary']) return noise_thermal
def depolarizing_noise(p): noise_model = NoiseModel() error = depolarizing_error(p, num_qubits=1) noise_model.add_all_qubit_quantum_error(error, 'noise') noise_model.add_basis_gates(['unitary']) return noise_model