def test_t2(self): """ Run the simulator with dephasing noise. Then verify that the calculated T2 matches the dephasing parameter. """ # 25 numbers ranging from 1 to 200, linearly spaced num_of_gates = (np.linspace(1, 300, 35)).astype(int) gate_time = 0.11 num_of_qubits = 2 qubit = 0 circs, xdata = t2_circuits(num_of_gates, gate_time, num_of_qubits, qubit) expected_t2 = 20 gamma = 1 - np.exp(-2 * gate_time / expected_t2) error = phase_damping_error(gamma) noise_model = NoiseModel() noise_model.add_all_qubit_quantum_error(error, 'id') # TODO: Include SPAM errors backend = qiskit.Aer.get_backend('qasm_simulator') shots = 300 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 = 1 initial_c = 0.5 * (-1) fit = T2Fitter(backend_result, shots, xdata, num_of_qubits, qubit, fit_p0=[initial_a, initial_t2, initial_c], fit_bounds=([0, 0, -1], [2, expected_t2 * 1.2, 1])) self.assertAlmostEqual(fit.time, expected_t2, delta=4, msg='Calculated T2 is inaccurate') self.assertTrue( fit.time_err < 5, 'Confidence in T2 calculation is too low: ' + str(fit.time_err))
def main(): # Get backends IBMQ.load_account() provider = IBMQ.get_provider(hub="ibm-q-ornl", group="anl", project="chm168") backend = provider.get_backend("ibmq_burlington") plugin_backend = Quac.get_backend("fake_burlington_density_simulator", t1=True, t2=True, meas=False, zz=False) # Get calibration circuits hardware_properties = FakeBurlington().properties() num_gates = np.linspace(10, 500, 30, dtype='int') qubits = list(range(len(backend.properties().qubits))) t1_circs, t1_delay = t1_circuits(num_gates, hardware_properties.gate_length('id', [0]) * 1e9, qubits) t2_circs, t2_delay = t2_circuits((num_gates / 2).astype('int'), hardware_properties.gate_length('id', [0]) * 1e9, qubits) # Formulate real noise model real_noise_model = QuacNoiseModel( t1_times=[1234, 2431, 2323, 2222, 3454], t2_times=[12000, 14000, 14353, 20323, 30232] ) # Formulate initial guess noise model (only same order of magnitude) guess_noise_model = QuacNoiseModel( t1_times=[1000, 1000, 1000, 1000, 1000], t2_times=[10000, 10000, 10000, 10000, 10000] ) # Calculate calibration circuit reference results reference_job = execute(t1_circs + t2_circs, plugin_backend, quac_noise_model=real_noise_model, optimization_level=0) reference_result = reference_job.result() # Calculate optimized noise model new_noise_model = optimize_noise_model_ng( guess_noise_model=guess_noise_model, circuits=t1_circs + t2_circs, backend=plugin_backend, reference_result=reference_result, loss_function=angle_objective_function ) # Show original noise model and optimized noise model print(f"Original noise model: {real_noise_model}") print(f"New noise model: {new_noise_model}")
def test_t2(self): """ Run the simulator with thermal relaxation noise. Then verify that the calculated T2 matches the t2 parameter. """ num_of_gates = (np.linspace(1, 30, 30)).astype(int) gate_time = 0.11 qubits = [0] n_echos = 5 alt_phase_echo = True circs, xdata = t2_circuits(num_of_gates, gate_time, qubits, n_echos, alt_phase_echo) expected_t2 = 20 error = thermal_relaxation_error(np.inf, expected_t2, gate_time, 0.5) noise_model = NoiseModel() noise_model.add_all_qubit_quantum_error(error, 'id') # TODO: Include SPAM errors backend = qiskit.Aer.get_backend('qasm_simulator') shots = 300 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 = 1 initial_c = 0.5*(-1) fit = T2Fitter(backend_result, xdata, qubits, fit_p0=[initial_a, initial_t2, initial_c], fit_bounds=([0, 0, -1], [2, expected_t2*1.2, 1])) self.assertAlmostEqual(fit.time(qid=0), expected_t2, delta=5, msg='Calculated T2 is inaccurate') self.assertTrue( fit.time_err(qid=0) < 5, 'Confidence in T2 calculation is too low: ' + str(fit.time_err))
def test_t2(self): """ Run the simulator with thermal relaxation noise. Then verify that the calculated T2 matches the t2 parameter. """ num_of_gates = (np.linspace(1, 30, 10)).astype(int) gate_time = 0.11 qubits = [0] n_echos = 5 alt_phase_echo = True circs, xdata = t2_circuits(num_of_gates, gate_time, qubits, n_echos, alt_phase_echo) expected_t2 = 20 error = thermal_relaxation_error(np.inf, expected_t2, gate_time, 0.5) noise_model = NoiseModel() noise_model.add_all_qubit_quantum_error(error, 'id') # TODO: Include SPAM errors backend = qiskit.Aer.get_backend('qasm_simulator') shots = 100 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 = 1 initial_c = 0.5 * (-1) T2Fitter(backend_result, xdata, qubits, fit_p0=[initial_a, initial_t2, initial_c], fit_bounds=([0, 0, -1], [2, expected_t2 * 1.2, 1]))
def t2_circuit_execution( ) -> Tuple[qiskit.result.Result, np.array, List[int], float]: """ Create T2 circuits and simulate them. Returns: * Backend result. * xdata. * Qubits for the T2 measurement. * T2 that was used in the circuits creation. """ num_of_gates = (np.linspace(1, 30, 10)).astype(int) gate_time = 0.11 qubits = [0] n_echos = 5 alt_phase_echo = True circs, xdata = t2_circuits(num_of_gates, gate_time, qubits, n_echos, alt_phase_echo) t2_value = 20 error = thermal_relaxation_error(np.inf, t2_value, gate_time, 0.5) noise_model = NoiseModel() noise_model.add_all_qubit_quantum_error(error, 'id') # TODO: Include SPAM errors backend = qiskit.Aer.get_backend('qasm_simulator') shots = 100 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() return backend_result, xdata, qubits, t2_value