def test_call_gate_and_circuit(self): """Test calling circuit with gates.""" h_control = circuit.QuantumCircuit(2) h_control.h(0) with pulse.build(self.backend) as schedule: with pulse.align_sequential(): # this is circuit, a subroutine stored as Call instruction pulse.call(h_control) # this is instruction, not subroutine pulse.cx(0, 1) # this is macro, not subroutine pulse.measure([0, 1]) # subroutine h_reference = compiler.schedule(compiler.transpile(h_control, self.backend), self.backend) # gate cx_circ = circuit.QuantumCircuit(2) cx_circ.cx(0, 1) cx_reference = compiler.schedule(compiler.transpile(cx_circ, self.backend), self.backend) # measurement measure_reference = macros.measure( qubits=[0, 1], inst_map=self.inst_map, meas_map=self.configuration.meas_map ) reference = pulse.Schedule() reference += pulse.instructions.Call(h_reference) reference += cx_reference reference += measure_reference << reference.duration self.assertScheduleEqual(schedule, reference)
def test_measure(self): """Test pulse measurement macro against circuit measurement and ensure agreement.""" with pulse.build(self.backend) as schedule: with pulse.align_sequential(): pulse.x(0) pulse.measure(0) reference_qc = circuit.QuantumCircuit(1, 1) reference_qc.x(0) reference_qc.measure(0, 0) reference_qc = compiler.transpile(reference_qc, self.backend) reference = compiler.schedule(reference_qc, self.backend) self.assertEqual(schedule, reference)
def test_measure_multi_qubits(self): """Test utility function - measure with multi qubits.""" with pulse.build(self.backend) as schedule: regs = pulse.measure([0, 1]) self.assertListEqual(regs, [pulse.MemorySlot(0), pulse.MemorySlot(1)]) reference = macros.measure(qubits=[0, 1], inst_map=self.inst_map, meas_map=self.configuration.meas_map) self.assertEqual(schedule, reference)
def test_measure(self): """Test utility function - measure.""" with pulse.build(self.backend) as schedule: reg = pulse.measure(0) self.assertEqual(reg, pulse.MemorySlot(0)) reference = macros.measure(qubits=[0], inst_map=self.inst_map, meas_map=self.configuration.meas_map) self.assertEqual(schedule, reference)
def test_complex_build(self): """Test a general program build with nested contexts, circuits and macros.""" d0 = pulse.DriveChannel(0) d1 = pulse.DriveChannel(1) d2 = pulse.DriveChannel(2) delay_dur = 19 short_dur = 31 long_dur = 101 with pulse.build(self.backend) as schedule: with pulse.align_sequential(): pulse.delay(delay_dur, d0) pulse.u2(0, pi/2, 1) with pulse.align_right(): pulse.play(library.Constant(short_dur, 0.1), d1) pulse.play(library.Constant(long_dur, 0.1), d2) pulse.u2(0, pi/2, 1) with pulse.align_left(): pulse.u2(0, pi/2, 0) pulse.u2(0, pi/2, 1) pulse.u2(0, pi/2, 0) pulse.measure(0) # prepare and schedule circuits that will be used. single_u2_qc = circuit.QuantumCircuit(2) single_u2_qc.u2(0, pi/2, 1) single_u2_qc = compiler.transpile(single_u2_qc, self.backend) single_u2_sched = compiler.schedule(single_u2_qc, self.backend) # sequential context sequential_reference = pulse.Schedule() sequential_reference += instructions.Delay(delay_dur, d0) sequential_reference.insert(delay_dur, single_u2_sched, inplace=True) # align right align_right_reference = pulse.Schedule() align_right_reference += pulse.Play( library.Constant(long_dur, 0.1), d2) align_right_reference.insert(long_dur-single_u2_sched.duration, single_u2_sched, inplace=True) align_right_reference.insert( long_dur-single_u2_sched.duration-short_dur, pulse.Play(library.Constant(short_dur, 0.1), d1), inplace=True) # align left triple_u2_qc = circuit.QuantumCircuit(2) triple_u2_qc.u2(0, pi/2, 0) triple_u2_qc.u2(0, pi/2, 1) triple_u2_qc.u2(0, pi/2, 0) triple_u2_qc = compiler.transpile(triple_u2_qc, self.backend) align_left_reference = compiler.schedule( triple_u2_qc, self.backend, method='alap') # measurement measure_reference = macros.measure(qubits=[0], inst_map=self.inst_map, meas_map=self.configuration.meas_map) reference = pulse.Schedule() reference += sequential_reference # Insert so that the long pulse on d2 occurs as early as possible # without an overval on d1. insert_time = (reference.ch_stop_time(d1) - align_right_reference.ch_start_time(d1)) reference.insert(insert_time, align_right_reference, inplace=True) reference.insert(reference.ch_stop_time(d0, d1), align_left_reference, inplace=True) reference += measure_reference self.assertEqual(schedule, reference)
def output(data): print("We have F: ", data.F, " nT") N_delta = 2 N = int(math.log(data.T_2 * 10 ** (-6) / data.t_init) / math.log(2))-N_delta multiplier = 30 # Ramsey experiment parameters detuning_max_MHz = data.const * data.F_max * data.F_degree / (2 * math.pi) / MHz / multiplier detuning_min_MHz = data.const * data.F_min * data.F_degree / (2 * math.pi) / MHz / multiplier detuning_MHz = data.const * data.F * data.F_degree / (2 * math.pi) / MHz / multiplier delta_min_det_MHz = -0.05 - 0.02 - 0.12 - 0.22 delta_max_det_MHz = -0.05 - 0.05 - 0.05 - 0.12 - 0.20 detuning_MHz = (detuning_min_MHz+delta_min_det_MHz) + (detuning_max_MHz+delta_max_det_MHz - (detuning_min_MHz+delta_min_det_MHz))*(detuning_MHz - detuning_min_MHz)/(detuning_max_MHz-detuning_min_MHz) times = [data.t_init*2**(i) for i in range(N)] # Drive parameters # The drive amplitude for pi/2 is simply half the amplitude of the pi pulse drive_amp = pi_amp / 2 # x_90 is a concise way to say pi_over_2; i.e., an X rotation of 90 degrees with pulse.build(backend) as x90_pulse: drive_duration = get_closest_multiple_of_16(pulse.seconds_to_samples(drive_duration_sec)) drive_sigma = pulse.seconds_to_samples(drive_sigma_sec) drive_chan = pulse.drive_channel(qubit) pulse.play(pulse.Gaussian(duration=drive_duration, amp=drive_amp, sigma=drive_sigma, name='x90_pulse'), drive_chan) # create schedules for Ramsey experiment ramsey_schedules = [] ramsey_frequency = round(precise_qubit_freq + detuning_MHz * MHz, 6) # need ramsey freq in Hz for time in times: with pulse.build(backend=backend, default_alignment='sequential', name=f"det = {detuning_MHz} MHz") as ramsey_schedule: drive_chan = pulse.drive_channel(qubit) pulse.set_frequency(ramsey_frequency, drive_chan) pulse.call(x90_pulse) pulse.delay(get_closest_multiple_of_16(pulse.seconds_to_samples(time*multiplier)), drive_chan) pulse.call(x90_pulse) pulse.measure(qubits=[qubit], registers=[pulse.MemorySlot(mem_slot)]) ramsey_schedules.append(ramsey_schedule) # Execution settings num_shots = data.num_of_repetitions job = backend.run(ramsey_schedules, meas_level=1, meas_return='single', shots=num_shots) job_monitor(job) ramsey_results = job.result(timeout=120) ramsey_values = {} for i in range(len(times)): iq_data = ramsey_results.get_memory(i)[:, qubit] * scale_factor ramsey_values[times[i]]=int(round(sum(map(classify, iq_data)) / num_shots)) ''' times = [data.t_init * 2 ** (i) for i in range(N, N+N_delta)] # create schedules for Ramsey experiment ramsey_schedules = [] ramsey_frequency = round(precise_qubit_freq + detuning_MHz * MHz, 6) # need ramsey freq in Hz for time in times: with pulse.build(backend=backend, default_alignment='sequential', name=f"det = {detuning_MHz} MHz") as ramsey_schedule: drive_chan = pulse.drive_channel(qubit) pulse.set_frequency(ramsey_frequency, drive_chan) pulse.call(x90_pulse) pulse.delay(get_closest_multiple_of_16(pulse.seconds_to_samples(time * multiplier)), drive_chan) pulse.call(x90_pulse) pulse.measure(qubits=[qubit], registers=[pulse.MemorySlot(mem_slot)]) ramsey_schedules.append(ramsey_schedule) # Execution settings num_shots = data.num_of_repetitions job = backend.run(ramsey_schedules, meas_level=1, meas_return='single', shots=num_shots) job_monitor(job) ramsey_results = job.result(timeout=120) for i in range(len(times)): iq_data = ramsey_results.get_memory(i)[:, qubit] * scale_factor ramsey_values[times[i]] = int(round(sum(map(classify, iq_data)) / num_shots)) #''' print(ramsey_values) return ramsey_values #print(output(data))
# Creare il programma di base # Start with drive pulse acting on the drive channel freq = Parameter('freq') with pulse.build(backend=backend, default_alignment='sequential', name='Frequency sweep') as sweep_sched: drive_duration = get_closest_multiple_of_16(pulse.seconds_to_samples(drive_duration_sec)) drive_sigma = pulse.seconds_to_samples(drive_sigma_sec) drive_chan = pulse.drive_channel(qubit) pulse.set_frequency(freq, drive_chan) # Drive pulse samples pulse.play(pulse.Gaussian(duration=drive_duration, sigma=drive_sigma, amp=drive_amp, name='freq_sweep_excitation_pulse'), drive_chan) # Define our measurement pulse pulse.measure(qubits=[qubit], registers=[pulse.MemorySlot(mem_slot)]) # Create the frequency settings for the sweep (MUST BE IN HZ) frequencies_Hz = frequencies_GHz*GHz schedules = [sweep_sched.assign_parameters({freq : f}, inplace=False) for f in frequencies_Hz] schedules[0].draw() #Argomento backend=backend num_shots_per_frequency = 1024 job = backend.run(schedules, meas_level=1, meas_return='avg', shots=num_shots_per_frequency)