def test_error_post_acquire_pulse(self): """Test that an error is raised if a pulse occurs on a channel after an acquire.""" acquire = pulse.Acquire(5) sched = pulse.Schedule(name='fake_experiment') sched = sched.insert(0, self.short_pulse(self.device.drives[0])) sched = sched.insert( 4, acquire(self.device.acquires[0], self.device.memoryslots[0])) # No error with separate channel sched = sched.insert(10, self.short_pulse(self.device.drives[1])) align_measures([sched], self.cmd_def) sched = sched.insert(10, self.short_pulse(self.device.drives[0])) with self.assertRaises(PulseError): align_measures([sched], self.cmd_def)
def setUp(self): self.backend = FakeOpenPulse2Q() self.device = pulse.PulseChannelSpec.from_backend(self.backend) self.config = self.backend.configuration() self.defaults = self.backend.defaults() self.cmd_def = CmdDef.from_defaults(self.defaults.cmd_def, self.defaults.pulse_library) self.short_pulse = pulse.SamplePulse(samples=np.array([0.02739068], dtype=np.complex128), name='p0') acquire = pulse.Acquire(5) sched = pulse.Schedule(name='fake_experiment') sched = sched.insert(0, self.short_pulse(self.device.drives[0])) self.sched = sched.insert(5, acquire(self.device.acquires, self.device.memoryslots))
def setUp(self): self.backend = FakeOpenPulse2Q() self.config = self.backend.configuration() self.defaults = self.backend.defaults() self.cmd_def = CmdDef.from_defaults(self.defaults.cmd_def, self.defaults.pulse_library) self.short_pulse = pulse.SamplePulse(samples=np.array([0.02739068], dtype=np.complex128), name='p0') acquire = pulse.Acquire(5) sched = pulse.Schedule(name='fake_experiment') sched = sched.insert(0, self.short_pulse(self.config.drive(0))) self.sched = sched.insert(5, acquire([self.config.acquire(0), self.config.acquire(1)], [MemorySlot(0), MemorySlot(1)]))
def setUp(self): self.backend = FakeOpenPulse2Q() self.config = self.backend.configuration() self.cmd_def = self.backend.defaults().instruction_schedule_map self.short_pulse = pulse.SamplePulse(samples=np.array( [0.02739068], dtype=np.complex128), name='p0') acquire = pulse.Acquire(5) sched = pulse.Schedule(name='fake_experiment') sched = sched.insert(0, self.short_pulse(self.config.drive(0))) sched = sched.insert(5, acquire(self.config.acquire(0), MemorySlot(0))) sched = sched.insert(5, acquire(self.config.acquire(1), MemorySlot(1))) self.sched = sched
def setUp(self): self.backend = FakeOpenPulse2Q() self.device = pulse.DeviceSpecification.create_from(self.backend) self.config = self.backend.configuration() self.defaults = self.backend.defaults() self.cmd_def = CmdDef.from_defaults(self.defaults.cmd_def, self.defaults.pulse_library) self.short_pulse = pulse.SamplePulse(samples=np.array([0.02739068], dtype=np.complex128), name='p0') acquire = pulse.Acquire(5) sched = pulse.Schedule(name='fake_experiment') sched = sched.insert(0, self.short_pulse(self.device.q[0].drive)) self.sched = sched.insert(5, acquire(self.device.q, self.device.mem))
def test_set_parameter_to_complex_schedule(self): """Test get parameters from complicated schedule.""" test_block = deepcopy(self.test_sched) value_dict = { self.amp1_1: 0.1, self.amp1_2: 0.2, self.amp2: 0.3, self.amp3: 0.4, self.dur1: 100, self.dur2: 125, self.dur3: 150, self.ch1: 0, self.ch2: 2, self.ch3: 4, self.phi1: 1.0, self.phi2: 2.0, self.phi3: 3.0, self.meas_dur: 300, self.mem1: 3, self.reg1: 0, self.context_dur: 1000, } visitor = ParameterSetter(param_map=value_dict) assigned = visitor.visit(test_block) # create ref schedule subroutine = pulse.ScheduleBlock(alignment_context=AlignLeft()) subroutine += pulse.ShiftPhase(1.0, pulse.DriveChannel(0)) subroutine += pulse.Play(pulse.Gaussian(100, 0.3, 25), pulse.DriveChannel(0)) sched = pulse.Schedule() sched += pulse.ShiftPhase(3.0, pulse.DriveChannel(4)) ref_obj = pulse.ScheduleBlock(alignment_context=AlignEquispaced(1000), name="long_schedule") ref_obj += subroutine ref_obj += pulse.ShiftPhase(2.0, pulse.DriveChannel(2)) ref_obj += pulse.Play(pulse.Gaussian(125, 0.3, 25), pulse.DriveChannel(2)) ref_obj += pulse.Call(sched) ref_obj += pulse.Play(pulse.Gaussian(150, 0.4, 25), pulse.DriveChannel(4)) ref_obj += pulse.Acquire(300, pulse.AcquireChannel(0), pulse.MemorySlot(3), pulse.RegisterSlot(0)) self.assertEqual(assigned, ref_obj)
def test_assemble_meas_map(self): """Test assembling a single schedule, no lo config.""" acquire = pulse.Acquire(5) schedule = acquire(self.device.q, mem_slots=self.device.mem) assemble(schedule, qubit_lo_freq=self.default_qubit_lo_freq, meas_lo_freq=self.default_meas_lo_freq, meas_map=[[0], [1]]) with self.assertRaises(QiskitError): assemble(schedule, qubit_lo_freq=self.default_qubit_lo_freq, meas_lo_freq=self.default_meas_lo_freq, meas_map=[[0, 1, 2]])
def test_gen_filled_waveform_stepwise_acquire(self): """Test gen_filled_waveform_stepwise with acquire instruction.""" acquire = pulse.Acquire(duration=4, channel=pulse.AcquireChannel(0), mem_slot=pulse.MemorySlot(0), discriminator=pulse.Discriminator(name='test_discr'), name='acquire') inst_data = create_instruction(acquire, 0, 7e9, 5, 0.1) objs = waveform.gen_filled_waveform_stepwise(inst_data, formatter=self.formatter, device=self.device) # imaginary part is empty and not returned self.assertEqual(len(objs), 1) # type check self.assertEqual(type(objs[0]), drawing_objects.LineData) y_ref = np.array([1, 1]) # data check - data is compressed self.assertListEqual(objs[0].channels, [pulse.AcquireChannel(0)]) self.assertListEqual(list(objs[0].xvals), [5, 9]) np.testing.assert_array_almost_equal(objs[0].yvals, y_ref) # meta data check ref_meta = {'memory slot': 'm0', 'register slot': 'N/A', 'discriminator': 'test_discr', 'kernel': 'N/A', 'duration (cycle time)': 4, 'duration (sec)': 0.4, 't0 (cycle time)': 5, 't0 (sec)': 0.5, 'phase': 0, 'frequency': 7e9, 'qubit': 0, 'name': 'acquire', 'data': 'real'} self.assertDictEqual(objs[0].meta, ref_meta) # style check ref_style = {'alpha': self.formatter['alpha.fill_waveform'], 'zorder': self.formatter['layer.fill_waveform'], 'linewidth': self.formatter['line_width.fill_waveform'], 'linestyle': self.formatter['line_style.fill_waveform'], 'color': self.formatter['color.fill_waveform_a'][0]} self.assertDictEqual(objs[0].styles, ref_style)
def test_align_measures(self): """Test that one acquire is delayed to match the time of the later acquire.""" acquire = pulse.Acquire(5) sched = pulse.Schedule(name='fake_experiment') sched = sched.insert(0, self.short_pulse(self.device.drives[0])) sched = sched.insert(1, acquire(self.device.acquires[0], self.device.memoryslots[0])) sched = sched.insert(10, acquire(self.device.acquires[1], self.device.memoryslots[1])) sched = align_measures([sched], self.cmd_def)[0] for time, inst in sched.instructions: if isinstance(inst, AcquireInstruction): self.assertEqual(time, 10) sched = align_measures([sched], self.cmd_def, align_time=20)[0] for time, inst in sched.instructions: if isinstance(inst, AcquireInstruction): self.assertEqual(time, 20)
def test_align_post_u3(self): """Test that acquires are scheduled no sooner than the duration of the longest X gate. """ acquire = pulse.Acquire(5) sched = pulse.Schedule(name='fake_experiment') sched = sched.insert(0, self.short_pulse(self.config.drive(0))) sched = sched.insert(1, acquire(self.config.acquire(0), MemorySlot(0))) sched = align_measures([sched], self.cmd_def)[0] for time, inst in sched.instructions: if isinstance(inst, AcquireInstruction): self.assertEqual(time, 4) sched = align_measures([sched], self.cmd_def, max_calibration_duration=10)[0] for time, inst in sched.instructions: if isinstance(inst, AcquireInstruction): self.assertEqual(time, 10)
def test_assemble_meas_map(self): """Test assembling a single schedule, no lo config.""" acquire = pulse.Acquire(5) schedule = acquire([AcquireChannel(0), AcquireChannel(1)], [MemorySlot(0), MemorySlot(1)]) qobj = assemble(schedule, qubit_lo_freq=self.default_qubit_lo_freq, meas_lo_freq=self.default_meas_lo_freq, meas_map=[[0], [1]]) validate_qobj_against_schema(qobj) with self.assertRaises(QiskitError): assemble(schedule, qubit_lo_freq=self.default_qubit_lo_freq, meas_lo_freq=self.default_meas_lo_freq, meas_map=[[0, 1, 2]])
def test_align_across_schedules(self): """Test that acquires are aligned together across multiple schedules.""" acquire = pulse.Acquire(5) sched1 = pulse.Schedule(name='fake_experiment') sched1 = sched1.insert(0, self.short_pulse(self.config.drive(0))) sched1 = sched1.insert(10, acquire(self.config.acquire(0), MemorySlot(0))) sched2 = pulse.Schedule(name='fake_experiment') sched2 = sched2.insert(3, self.short_pulse(self.config.drive(0))) sched2 = sched2.insert(25, acquire(self.config.acquire(0), MemorySlot(0))) schedules = align_measures([sched1, sched2], self.cmd_def) for time, inst in schedules[0].instructions: if isinstance(inst, AcquireInstruction): self.assertEqual(time, 25) for time, inst in schedules[0].instructions: if isinstance(inst, AcquireInstruction): self.assertEqual(time, 25)
def test_assemble_meas_map(self): """Test assembling a single schedule, no lo config.""" acquire = pulse.Acquire(5) schedule = Schedule(name='fake_experiment') schedule = schedule.insert(5, acquire(AcquireChannel(0), MemorySlot(0))) schedule = schedule.insert(5, acquire(AcquireChannel(1), MemorySlot(1))) qobj = assemble(schedule, qubit_lo_freq=self.default_qubit_lo_freq, meas_lo_freq=self.default_meas_lo_freq, meas_map=[[0], [1]]) validate_qobj_against_schema(qobj) with self.assertRaises(QiskitError): assemble(schedule, qubit_lo_freq=self.default_qubit_lo_freq, meas_lo_freq=self.default_meas_lo_freq, meas_map=[[0, 1, 2]])
def test_assemble_memory_slots(self): """Test assembling a schedule and inferring number of memoryslots.""" acquire = pulse.Acquire(5) n_memoryslots = 10 # single acquisition schedule = acquire(self.device.acquires[0], mem_slots=pulse.MemorySlot(n_memoryslots-1)) qobj = assemble(schedule, meas_map=[[0], [1]]) self.assertEqual(qobj.config.memory_slots, n_memoryslots) # multiple acquisition schedule = acquire(self.device.acquires[0], mem_slots=pulse.MemorySlot(n_memoryslots-1)) schedule = schedule.insert(10, acquire(self.device.acquires[0], mem_slots=pulse.MemorySlot(n_memoryslots-1))) qobj = assemble(schedule, meas_map=[[0], [1]]) self.assertEqual(qobj.config.memory_slots, n_memoryslots)
def test_align_measures(self): """Test that one acquire is delayed to match the time of the later acquire.""" acquire = pulse.Acquire(5) sched = pulse.Schedule(name='fake_experiment') sched = sched.insert(0, self.short_pulse(self.config.drive(0))) sched = sched.insert(1, acquire(self.config.acquire(0), MemorySlot(0))) sched = sched.insert(10, acquire(self.config.acquire(1), MemorySlot(1))) sched = sched.insert(10, self.short_pulse(self.config.measure(0))) sched = sched.insert(10, self.short_pulse(self.config.measure(1))) sched = align_measures([sched], self.cmd_def)[0] for time, inst in sched.instructions: if isinstance(inst, AcquireInstruction): self.assertEqual(time, 10) sched = align_measures([sched], self.cmd_def, align_time=20)[0] for time, inst in sched.instructions: if isinstance(inst, AcquireInstruction): self.assertEqual(time, 20) if isinstance(inst.channels[0], MeasureChannel): self.assertEqual(time, 20)
def test_assemble_memory_slots_for_schedules(self): """Test assembling schedules with different memory slots.""" acquire = pulse.Acquire(5) n_memoryslots = [10, 5, 7] schedules = [] for n_memoryslot in n_memoryslots: schedule = acquire(self.backend_config.acquire(0), mem_slots=pulse.MemorySlot(n_memoryslot-1)) schedules.append(schedule) qobj = assemble(schedules, qubit_lo_freq=self.default_qubit_lo_freq, meas_lo_freq=self.default_meas_lo_freq, meas_map=[[0], [1]]) validate_qobj_against_schema(qobj) self.assertEqual(qobj.config.memory_slots, max(n_memoryslots)) self.assertEqual(qobj.experiments[0].header.memory_slots, n_memoryslots[0]) self.assertEqual(qobj.experiments[1].header.memory_slots, n_memoryslots[1]) self.assertEqual(qobj.experiments[2].header.memory_slots, n_memoryslots[2])
def freq_sweep_schedule(qbit, backend_config, drive_chan, meas_samples=1000,): dt = backend_config.dt print(f"Sampling time: {dt} ns") drive_pulse = make_drive_pulse(dt) meas_pulse = make_meas_pulse(dt, samples=meas_samples) ### Construct the acquire pulse to trigger the acquisition # Acquire pulse samples acq_cmd = pulse.Acquire(duration=meas_samples) # Find out which group of qubits need to be acquired with this qubit meas_map_idx = None for i, measure_group in enumerate(backend_config.meas_map): if qbit in measure_group: meas_map_idx = i break assert meas_map_idx is not None, f"Couldn't find qubit {qbit} in the meas_map!" ### Collect the necessary channels #drive_chan = pulse.DriveChannel(qbit) meas_chan = pulse.MeasureChannel(qbit) #acq_chan = pulse.AcquireChannel(qbit) schedule = pulse.Schedule(name='Frequency sweep') schedule += drive_pulse(drive_chan) measure_schedule = meas_pulse(meas_chan) # Trigger data acquisition, and store measured values into respective memory slots measure_schedule += acq_cmd([pulse.AcquireChannel(i) for i in backend_config.meas_map[meas_map_idx]], [pulse.MemorySlot(i) for i in backend_config.meas_map[meas_map_idx]]) # shift the start time of the schedule by some duration schedule += measure_schedule << schedule.duration schedule += drive_pulse(drive_chan)<< schedule.duration - drive_pulse.duration schedule += measure_schedule << drive_pulse.duration return schedule
def test_assemble_memory_slots(self): """Test assembling a schedule and inferring number of memoryslots.""" acquire = pulse.Acquire(5) n_memoryslots = 10 # single acquisition schedule = acquire(self.backend_config.acquire(0), mem_slot=pulse.MemorySlot(n_memoryslots - 1)) qobj = assemble(schedule, qubit_lo_freq=self.default_qubit_lo_freq, meas_lo_freq=self.default_meas_lo_freq, meas_map=[[0], [1]]) validate_qobj_against_schema(qobj) self.assertEqual(qobj.config.memory_slots, n_memoryslots) # this should be in experimental header as well self.assertEqual(qobj.experiments[0].header.memory_slots, n_memoryslots) # multiple acquisition schedule = acquire(self.backend_config.acquire(0), mem_slot=pulse.MemorySlot(n_memoryslots - 1)) schedule = schedule.insert( 10, acquire(self.backend_config.acquire(0), mem_slot=pulse.MemorySlot(n_memoryslots - 1))) qobj = assemble(schedule, qubit_lo_freq=self.default_qubit_lo_freq, meas_lo_freq=self.default_meas_lo_freq, meas_map=[[0], [1]]) validate_qobj_against_schema(qobj) self.assertEqual(qobj.config.memory_slots, n_memoryslots) # this should be in experimental header as well self.assertEqual(qobj.experiments[0].header.memory_slots, n_memoryslots)
def _1Q_frame_change_schedule(self, phi, fc_phi, total_samples, dur_drive1, dur_drive2): """Creates schedule for frame change test. Does a pulse w/ phase phi of duration dur_drive1, then frame change of phase fc_phi, then another pulse of phase phi of duration dur_drive2. The different durations for the pulses allow manipulation of rotation angles on Bloch sphere Args: phi (float): drive phase (phi in Hamiltonian) fc_phi (float): phase for frame change total_samples (int): length of pulses dur_drive1 (int): duration of first pulse dur_drive2 (int): duration of second pulse Returns: schedule (pulse schedule): schedule for frame change test """ phase = np.exp(1j * phi) drive_pulse_1 = SamplePulse(phase * np.ones(dur_drive1), name='drive_pulse_1') drive_pulse_2 = SamplePulse(phase * np.ones(dur_drive2), name='drive_pulse_2') # frame change fc_pulse = FrameChange(phase=fc_phi, name='fc') # set up acquire command acq_cmd = pulse.Acquire(duration=total_samples) # add commands to schedule schedule = pulse.Schedule(name='fc_schedule') schedule |= drive_pulse_1(DriveChannel(0)) schedule += fc_pulse(DriveChannel(0)) schedule += drive_pulse_2(DriveChannel(0)) schedule |= acq_cmd(AcquireChannel(0), MemorySlot(0)) << schedule.duration return schedule
def test_multi_acquire(self): """Test that an error is raised if multiple acquires occur on the same channel.""" acquire = pulse.Acquire(5) sched = pulse.Schedule(name='fake_experiment') sched = sched.insert(0, self.short_pulse(self.config.drive(0))) sched = sched.insert(4, acquire(self.config.acquire(0), MemorySlot(0))) sched = sched.insert(10, acquire(self.config.acquire(0), MemorySlot(0))) with self.assertRaises(PulseError): align_measures([sched], self.cmd_def) # Test for measure channel sched = pulse.Schedule(name='fake_experiment') sched = sched.insert(10, self.short_pulse(self.config.measure(0))) sched = sched.insert(30, self.short_pulse(self.config.measure(0))) with self.assertRaises(PulseError): align_measures([sched], self.cmd_def) # Test both using cmd_def sched = pulse.Schedule() sched += self.cmd_def.get('measure', (0, 1)) align_measures([sched], align_time=50) sched += self.cmd_def.get('measure', (0, 1)) with self.assertRaises(PulseError): align_measures([sched], align_time=50)
def _simple_1Q_schedule(self, phi, total_samples, shape="square", gauss_sigma=0): """Creates schedule for single pulse test Args: phi (float): drive phase (phi in Hamiltonian) total_samples (int): length of pulses shape (str): shape of the pulse; defaults to square pulse gauss_sigma (float): std dev for gaussian pulse if shape=="gaussian" Returns: schedule (pulse schedule): schedule for this test """ # set up pulse command phase = np.exp(1j * phi) drive_pulse = None if shape == "square": const_pulse = np.ones(total_samples) drive_pulse = SamplePulse(phase * const_pulse, name='drive_pulse') if shape == "gaussian": times = 1.0 * np.arange(total_samples) gaussian = np.exp(-times**2 / 2 / gauss_sigma**2) drive_pulse = SamplePulse(phase * gaussian, name='drive_pulse') # set up acquire command acq_cmd = pulse.Acquire(duration=total_samples) # add commands into a schedule for first qubit schedule = pulse.Schedule(name='drive_pulse') schedule |= drive_pulse(DriveChannel(0)) schedule |= acq_cmd(AcquireChannel(0), MemorySlot(0)) << schedule.duration return schedule
def cr_drive_experiments(drive_idx, target_idx, flip_drive_qubit = False, #cr_drive_amps=np.linspace(0, 0.9, 16), #cr_drive_samples=800, #cr_drive_sigma=4, #pi_drive_samples=128, #pi_drive_sigma=16 #meas_amp = Dims/128*0.025/2 #meas_width = int(rows/128*1150/2) cr_drive_amps=np.linspace(0, 0.9, meas_width**2), cr_drive_samples=sum(label1[:] == label2[:]), cr_drive_sigma=meas_sigma, pi_drive_samples=sum((label1[:] ==1)*(label2[:] ==1)), #label1[:] ==1 and label2[:] ==1 pi_drive_sigma=cr_drive_sigma**2): """Generate schedules corresponding to CR drive experiments. Args: drive_idx (int): label of driven qubit target_idx (int): label of target qubit flip_drive_qubit (bool): whether or not to start the driven qubit in the ground or excited state cr_drive_amps (array): list of drive amplitudes to use cr_drive_samples (int): number samples for each CR drive signal cr_drive_sigma (float): standard deviation of CR Gaussian pulse pi_drive_samples (int): number samples for pi pulse on drive pi_drive_sigma (float): standard deviation of Gaussian pi pulse on drive Returns: list[Schedule]: A list of Schedule objects for each experiment """ # Construct measurement commands to be used for all schedules #meas_amp = 0.025 #meas_samples = 1200 #meas_sigma = 4 #meas_width = 1150 meas_amp = 0.025 meas_sigma = 4 ni = int(np.ceil(cols/meas_sigma)) print(ni) meas_samples = rows*ni meas_width = int(rows*ni*23/24) meas_pulse = GaussianSquare(duration=meas_samples, amp=meas_amp/np.linalg.norm(meas_amp), sigma=meas_sigma, width=meas_width) acq_sched = pulse.Acquire(meas_samples, pulse.AcquireChannel(0), pulse.MemorySlot(0)) acq_sched += pulse.Acquire(meas_samples, pulse.AcquireChannel(1), pulse.MemorySlot(1)) # create measurement schedule measure_sched = (pulse.Play(meas_pulse, pulse.MeasureChannel(0)) | pulse.Play(meas_pulse, pulse.MeasureChannel(1))| acq_sched) # Create schedule schedules = [] for ii, cr_drive_amp in enumerate(cr_drive_amps): # pulse for flipping drive qubit if desired pi_pulse = Gaussian(duration=pi_drive_samples, amp=pi_amps[drive_idx], sigma=pi_drive_sigma) # cr drive pulse cr_width = cr_drive_samples - 2*cr_drive_sigma*4 cr_rabi_pulse = GaussianSquare(duration=cr_drive_samples, amp=cr_drive_amp/np.linalg.norm(cr_drive_amp), sigma=cr_drive_sigma, width=cr_width) # add commands to schedule schedule = pulse.Schedule(name='cr_rabi_exp_amp_%s' % cr_drive_amp) #schedule = pulse.Schedule(name='cr_rabi_exp_amp_%s' % cr_drive_amp/np.linalg.norm(cr_drive_amp)) # flip drive qubit if desired if flip_drive_qubit: schedule += pulse.Play(pi_pulse, pulse.DriveChannel(drive_idx)) # do cr drive # First, get the ControlChannel index for CR drive from drive to target cr_idx = two_qubit_model.control_channel_index((drive_idx, target_idx)) schedule += pulse.Play(cr_rabi_pulse, pulse.ControlChannel(cr_idx)) << schedule.duration schedule += measure_sched << schedule.duration schedules.append(schedule) return schedules
#4.1 Constructing the schedules # list of qubits to be used throughout the notebook qubits = [0, 1] # Construct a measurement schedule and add it to an InstructionScheduleMap meas_amp = 0.025 meas_sigma = 4 ni = int(np.ceil(cols/meas_sigma)) print(ni) meas_samples = rows*ni meas_width = int(rows*ni*23/24) meas_pulse = GaussianSquare(duration=meas_samples, amp=meas_amp, sigma=meas_sigma, width=meas_width) acq_sched = pulse.Acquire(meas_samples, pulse.AcquireChannel(0), pulse.MemorySlot(0)) acq_sched += pulse.Acquire(meas_samples, pulse.AcquireChannel(1), pulse.MemorySlot(1)) measure_sched = pulse.Play(meas_pulse, pulse.MeasureChannel(0)) | pulse.Play(meas_pulse, pulse.MeasureChannel(1)) | acq_sched inst_map = pulse.InstructionScheduleMap() inst_map.add('measure', qubits, measure_sched) #Rabi schedules #recall: Rabii oscillation # The magnetic moment is thus {\displaystyle {\boldsymbol {\mu }}={\frac {\hbar }{2}}\gamma {\boldsymbol {\sigma }}}{\boldsymbol {\mu }}={\frac {\hbar }{2}}\gamma {\boldsymbol {\sigma }}. # The Hamiltonian of this system is then given by {H} =-{{\mu }}\cdot{B} =-{\frac {\hbar }{2}}\omega _{0}\sigma _{z}-{\frac {\hbar }{2}}\omega _{1}(\sigma _{x}\cos \omega t-\sigma _{y}\sin \omega t)}\mathbf {H} =-{\boldsymbol {\mu }}\cdot \mathbf {B} =-{\frac {\hbar }{2}}\omega _{0}\sigma _{z}-{\frac {\hbar }{2}}\omega _{1}(\sigma _{x}\cos \omega t-\sigma _{y}\sin \omega t) where {\displaystyle \omega _{0}=\gamma B_{0}}\omega _{0}=\gamma B_{0} and {\displaystyle \omega _{1}=\gamma B_{1}}\omega _{1}=\gamma B_{1} # Now, let the qubit be in state {\displaystyle |0\rangle }{\displaystyle |0\rangle } at time {\displaystyle t=0}t=0. Then, at time {\displaystyle t}t, the probability of it being found in state {\displaystyle |1\rangle }|1\rangle is given by {\displaystyle P_{0\to 1}(t)=\left({\frac {\omega _{1}}{\Omega }}\right)^{2}\sin ^{2}\left({\frac {\Omega t}{2}}\right)}{\displaystyle P_{0\to 1}(t)=\left({\frac {\omega _{1}}{\Omega }}\right)^{2}\sin ^{2}\left({\frac {\Omega t}{2}}\right)} where {\displaystyle \Omega ={\sqrt {(\omega -\omega _{0})^{2}+\omega _{1}^{2}}}}\Omega ={\sqrt {(\omega -\omega _{0})^{2}+\omega _{1}^{2}}} # the qubit oscillates between the {\displaystyle |0\rangle }|0\rang and {\displaystyle |1\rangle }|1\rangle states. # The maximum amplitude for oscillation is achieved at {\displaystyle \omega =\omega _{0}}\omega =\omega _{0}, which is the condition for resonance. # At resonance, the transition probability is given by {\displaystyle P_{0\to 1}(t)=\sin ^{2}\left({\frac {\omega _{1}t}{2}}\right)}{\displaystyle P_{0\to 1}(t)=\sin ^{2}\left({\frac {\omega _{1}t}{2}}\right)}
def setUp(self): """Just some useful, reusable Parameters, constants, schedules.""" super().setUp() self.amp1_1 = Parameter("amp1_1") self.amp1_2 = Parameter("amp1_2") self.amp2 = Parameter("amp2") self.amp3 = Parameter("amp3") self.dur1 = Parameter("dur1") self.dur2 = Parameter("dur2") self.dur3 = Parameter("dur3") self.parametric_waveform1 = pulse.Gaussian(duration=self.dur1, amp=self.amp1_1 + self.amp1_2, sigma=self.dur1 / 4) self.parametric_waveform2 = pulse.Gaussian(duration=self.dur2, amp=self.amp2, sigma=self.dur2 / 5) self.parametric_waveform3 = pulse.Gaussian(duration=self.dur3, amp=self.amp3, sigma=self.dur3 / 6) self.ch1 = Parameter("ch1") self.ch2 = Parameter("ch2") self.ch3 = Parameter("ch3") self.d1 = pulse.DriveChannel(self.ch1) self.d2 = pulse.DriveChannel(self.ch2) self.d3 = pulse.DriveChannel(self.ch3) self.phi1 = Parameter("phi1") self.phi2 = Parameter("phi2") self.phi3 = Parameter("phi3") self.meas_dur = Parameter("meas_dur") self.mem1 = Parameter("s1") self.reg1 = Parameter("m1") self.context_dur = Parameter("context_dur") # schedule under test subroutine = pulse.ScheduleBlock(alignment_context=AlignLeft()) subroutine += pulse.ShiftPhase(self.phi1, self.d1) subroutine += pulse.Play(self.parametric_waveform1, self.d1) sched = pulse.Schedule() sched += pulse.ShiftPhase(self.phi3, self.d3) long_schedule = pulse.ScheduleBlock(alignment_context=AlignEquispaced( self.context_dur), name="long_schedule") long_schedule += subroutine long_schedule += pulse.ShiftPhase(self.phi2, self.d2) long_schedule += pulse.Play(self.parametric_waveform2, self.d2) long_schedule += pulse.Call(sched) long_schedule += pulse.Play(self.parametric_waveform3, self.d3) long_schedule += pulse.Acquire( self.meas_dur, pulse.AcquireChannel(self.ch1), mem_slot=pulse.MemorySlot(self.mem1), reg_slot=pulse.RegisterSlot(self.reg1), ) self.test_sched = long_schedule
meas_samples_us = 4.0 meas_sigma_us = 1.0 # The width of the gaussian part of the rise and fall meas_risefall_us = 0.1 # and the truncating parameter: how many samples to dedicate to the risefall meas_samples = get_closest_multiple_of_16(meas_samples_us * 1e-6/dt) meas_sigma = get_closest_multiple_of_16(meas_sigma_us * 1e-6/dt) # The width of the gaussian part of the rise and fall meas_risefall = get_closest_multiple_of_16(meas_risefall_us * 1e-6/dt) meas_amp = 0.2 # In[58]: acq_cmd = pulse.Acquire(duration=meas_samples) # In[59]: meas_pulse = pulse_lib.gaussian_square(duration=meas_samples, sigma=meas_sigma, amp=meas_amp, risefall=meas_risefall, name='measurement_pulse') measure_schedule = meas_pulse(meas_chan)<<measure_time measure_schedule += acq_cmd([pulse.AcquireChannel(i) for i in backend_config.meas_map[meas_map_idx]], [pulse.MemorySlot(i) for i in backend_config.meas_map[meas_map_idx]])
) # Import backend configurations backend_config = backend.configuration() # Set measurement channels meas_chan = pulse.MeasureChannel(qubit) acq_chan = pulse.AcquireChannel(qubit) # Add a measurement stimulus on the measure channel pulse to trigger readout measure_schedule = pulse.Play(measurement_pulse, meas_chan) # Trigger data acquisition, and store measured values into respective memory slots measure_schedule += pulse.Acquire( measurement_pulse.duration, pulse.AcquireChannel(backend_config.meas_map[meas_map_idx][0]), pulse.MemorySlot(backend_config.meas_map[meas_map_idx][0]), ) # Run 0-1 state discrimination experiment gnd_exc_experiment_result = ground_excited_experiment( qubit, backend, num_shots_with_training, measure_schedule) # Train and classify data with Q-CTRL's discriminator gnd_exc_results = train_discriminator(gnd_exc_experiment_result, test_sample_size)[2] # Store results measurement_data.append(gnd_exc_results) silhouette_time_list.append(intercluster_distance(gnd_exc_results))