def test_default(self): """Test default persistent value. """ pv_comm = PersistentValue(value=0.5-0.5j) self.assertEqual(pv_comm.value, 0.5-0.5j) self.assertEqual(pv_comm.duration, 0)
def test_can_create_valid_schedule(self): """Test valid schedule creation without error.""" gp0 = pulse_lib.gaussian(duration=20, amp=0.7, sigma=3) gp1 = pulse_lib.gaussian(duration=20, amp=0.7, sigma=3) fc_pi_2 = FrameChange(phase=1.57) acquire = Acquire(10) sched = Schedule() sched = sched.append(gp0(self.config.drive(0))) sched = sched.insert( 0, PersistentValue(value=0.2 + 0.4j)(self.config.control(0))) sched = sched.insert(60, FrameChange(phase=-1.57)(self.config.drive(0))) sched = sched.insert(30, gp1(self.config.drive(0))) sched = sched.insert(60, gp0(self.config.control(0))) sched = sched.insert(80, Snapshot("label", "snap_type")) sched = sched.insert(90, fc_pi_2(self.config.drive(0))) sched = sched.insert( 90, acquire(self.config.acquire(0), MemorySlot(0), RegisterSlot(0))) self.assertEqual(0, sched.start_time) self.assertEqual(100, sched.stop_time) self.assertEqual(100, sched.duration) new_sched = Schedule() new_sched = new_sched.append(sched) new_sched = new_sched.append(sched) self.assertEqual(0, new_sched.start_time) self.assertEqual(200, new_sched.stop_time) self.assertEqual(200, new_sched.duration)
def sample_schedule(self): """Generate a sample schedule that includes the most common elements of pulse schedules.""" gp0 = pulse_lib.gaussian(duration=20, amp=1.0, sigma=1.0) gp1 = pulse_lib.gaussian(duration=20, amp=-1.0, sigma=2.0) gs0 = pulse_lib.gaussian_square(duration=20, amp=-1.0, sigma=2.0, risefall=3) fc_pi_2 = FrameChange(phase=1.57) acquire = Acquire(10) delay = Delay(100) sched = Schedule() sched = sched.append(gp0(DriveChannel(0))) sched = sched.insert( 0, PersistentValue(value=0.2 + 0.4j)(ControlChannel(0))) sched = sched.insert(60, FrameChange(phase=-1.57)(DriveChannel(0))) sched = sched.insert(30, gp1(DriveChannel(1))) sched = sched.insert(60, gp0(ControlChannel(0))) sched = sched.insert(60, gs0(MeasureChannel(0))) sched = sched.insert(90, fc_pi_2(DriveChannel(0))) sched = sched.insert( 90, acquire(AcquireChannel(1), MemorySlot(1), RegisterSlot(1))) sched = sched.append(delay(DriveChannel(0))) sched = sched + sched sched |= Snapshot("snapshot_1", "snap_type") << 60 sched |= Snapshot("snapshot_2", "snap_type") << 120 return sched
def test_name_inherited(self): """Test that schedule keeps name if an instruction is added.""" gp0 = pulse_lib.gaussian(duration=100, amp=0.7, sigma=3, name='pulse_name') with self.assertWarns(DeprecationWarning): pv0 = PersistentValue(0.1) snapshot = Snapshot('snapshot_label', 'state') sched1 = Schedule(name='test_name') sched2 = Schedule(name=None) sched3 = sched1 | sched2 self.assertEqual(sched3.name, 'test_name') sched_acq = Acquire( 10, self.config.acquire(1), MemorySlot(1), name='acq_name') | sched1 self.assertEqual(sched_acq.name, 'acq_name') sched_pulse = Play(gp0, self.config.drive(0)) | sched1 self.assertEqual(sched_pulse.name, 'pulse_name') with self.assertWarns(DeprecationWarning): sched_pv = pv0(self.config.drive(0), name='pv_name') | sched1 self.assertEqual(sched_pv.name, 'pv_name') sched_fc = ShiftPhase(0.1, self.config.drive(0), name='fc_name') | sched1 self.assertEqual(sched_fc.name, 'fc_name') sched_snapshot = snapshot | sched1 self.assertEqual(sched_snapshot.name, 'snapshot_label')
def test_can_create_valid_schedule(self): """Test valid schedule creation without error.""" gp0 = pulse_lib.gaussian(duration=20, amp=0.7, sigma=3) gp1 = pulse_lib.gaussian(duration=20, amp=0.7, sigma=3) sched = Schedule() sched = sched.append(Play(gp0, self.config.drive(0))) with self.assertWarns(DeprecationWarning): sched = sched.insert( 0, PersistentValue(value=0.2 + 0.4j)(self.config.control([0, 1])[0])) sched = sched.insert(60, ShiftPhase(-1.57, self.config.drive(0))) sched = sched.insert(30, Play(gp1, self.config.drive(0))) sched = sched.insert(60, Play(gp0, self.config.control([0, 1])[0])) sched = sched.insert(80, Snapshot("label", "snap_type")) sched = sched.insert(90, ShiftPhase(1.57, self.config.drive(0))) sched = sched.insert( 90, Acquire(10, self.config.acquire(0), MemorySlot(0), RegisterSlot(0))) # TODO: this shouldn't raise a warning self.assertEqual(0, sched.start_time) self.assertEqual(100, sched.stop_time) self.assertEqual(100, sched.duration) new_sched = Schedule() new_sched = new_sched.append(sched) new_sched = new_sched.append(sched) self.assertEqual(0, new_sched.start_time) self.assertEqual(200, new_sched.stop_time) self.assertEqual(200, new_sched.duration) ids = set() for _, inst in sched.instructions: self.assertFalse(inst.id in ids) ids.add(inst.id)
def test_can_create_valid_schedule(self): """Test valid schedule creation without error.""" device = self.two_qubit_device gp0 = pulse_lib.gaussian(duration=20, amp=0.7, sigma=3) gp1 = pulse_lib.gaussian(duration=20, amp=0.7, sigma=3) fc_pi_2 = FrameChange(phase=1.57) acquire = Acquire(10) sched = Schedule() sched = sched.append(gp0(device.q[0].drive)) sched = sched.insert( 0, PersistentValue(value=0.2 + 0.4j)(device.q[0].controls[0])) sched = sched.insert(60, FrameChange(phase=-1.57)(device.q[0].drive)) sched = sched.insert(30, gp1(device.q[1].drive)) sched = sched.insert(60, gp0(device.q[0].controls[0])) sched = sched.insert(80, Snapshot("label", "snap_type")) sched = sched.insert(90, fc_pi_2(device.q[0].drive)) sched = sched.insert(90, acquire(device.q[1], device.mem[1], device.c[1])) self.assertEqual(0, sched.start_time) self.assertEqual(100, sched.stop_time) self.assertEqual(100, sched.duration) new_sched = Schedule() new_sched = new_sched.append(sched) new_sched = new_sched.append(sched) self.assertEqual(0, new_sched.start_time) self.assertEqual(200, new_sched.stop_time) self.assertEqual(200, new_sched.duration)
def test_can_create_valid_schedule_with_syntax_sugar(self): """Test valid schedule creation using syntax sugar without error.""" device = self.two_qubit_device # pylint: disable=invalid-name @functional_pulse def gaussian(duration, amp, t0, sig): x = np.linspace(0, duration - 1, duration) return amp * np.exp(-(x - t0)**2 / sig**2) gp0 = gaussian(duration=20, amp=0.7, t0=9.5, sig=3) gp1 = gaussian(duration=20, amp=0.5, t0=9.5, sig=3) fc_pi_2 = FrameChange(phase=1.57) acquire = Acquire(10) sched = Schedule() sched += gp0(device.q[0].drive) sched |= PersistentValue(value=0.2 + 0.4j)( device.q[0].control).shifted(0) sched |= FrameChange(phase=-1.57)(device.q[0].drive).shifted(60) sched |= gp1(device.q[1].drive).shifted(30) sched |= gp0(device.q[0].control).shifted(60) sched |= Snapshot("label", "snap_type").shifted(80) sched |= fc_pi_2(device.q[0].drive).shifted(90) sched |= acquire(device.q[1], device.mem[1], device.c[1]).shifted(90) _ = Schedule() + sched + sched
def test_can_create_valid_schedule(self): """Test valid schedule creation without error. """ device = self.two_qubit_device @functional_pulse def gaussian(duration, amp, t0, sig): x = np.linspace(0, duration - 1, duration) return amp * np.exp(-(x - t0)**2 / sig**2) gp0 = gaussian(duration=20, name='pulse0', amp=0.7, t0=9.5, sig=3) gp1 = gaussian(duration=20, name='pulse1', amp=0.5, t0=9.5, sig=3) fc_pi_2 = FrameChange(phase=1.57) acquire = Acquire(10) sched = Schedule() sched = sched.append(gp0(device.q[0].drive)) sched = sched.insert( 0, PersistentValue(value=0.2 + 0.4j)(device.q[0].control)) sched = sched.insert(30, gp1(device.q[1].drive)) sched = sched.insert(60, FrameChange(phase=-1.57)(device.q[0].drive)) sched = sched.insert(60, gp0(device.q[0].control)) sched = sched.insert(80, Snapshot("label", "snap_type")) sched = sched.insert(90, fc_pi_2(device.q[0].drive)) sched = sched.insert(90, acquire(device.q[1], device.mem[1], device.c[1])) # print(sched) new_sched = Schedule() new_sched = new_sched.append(sched) new_sched = new_sched.append(sched) _ = new_sched.flat_instruction_sequence()
def sample_schedule(self): """Generate a sample schedule that includes the most common elements of pulse schedules.""" gp0 = pulse_lib.gaussian(duration=20, amp=1.0, sigma=1.0) gp1 = pulse_lib.gaussian(duration=20, amp=-1.0, sigma=2.0) gs0 = pulse_lib.gaussian_square(duration=20, amp=-1.0, sigma=2.0, risefall=3) fc_pi_2 = FrameChange(phase=1.57) acquire = Acquire(10) sched = Schedule() sched = sched.append(gp0(self.device.q[0].drive)) sched = sched.insert( 0, PersistentValue(value=0.2 + 0.4j)(self.device.q[0].controls[0])) sched = sched.insert(60, FrameChange(phase=-1.57)(self.device.q[0].drive)) sched = sched.insert(30, gp1(self.device.q[1].drive)) sched = sched.insert(60, gp0(self.device.q[0].controls[0])) sched = sched.insert(60, gs0(self.device.q[0].measure)) sched = sched.insert(90, fc_pi_2(self.device.q[0].drive)) sched = sched.insert( 90, acquire(self.device.q[1], self.device.mem[1], self.device.c[1])) sched = sched + sched sched |= Snapshot("snapshot_1", "snap_type") << 60 sched |= Snapshot("snapshot_2", "snap_type") << 120 return sched
def test_name_inherited(self): """Test that schedule keeps name if an instruction is added.""" device = self.two_qubit_device acquire = Acquire(10) gp0 = pulse_lib.gaussian(duration=100, amp=0.7, sigma=3, name='pulse_name') pv0 = PersistentValue(0.1) fc0 = FrameChange(0.1) snapshot = Snapshot('snapshot_label', 'state') sched1 = Schedule(name='test_name') sched2 = Schedule(name=None) sched3 = sched1 | sched2 self.assertEqual(sched3.name, 'test_name') sched_acq = acquire(device.q[1], device.mem[1], name='acq_name') | sched1 self.assertEqual(sched_acq.name, 'acq_name') sched_pulse = gp0(device.q[0].drive) | sched1 self.assertEqual(sched_pulse.name, 'pulse_name') sched_pv = pv0(device.q[0].drive, name='pv_name') | sched1 self.assertEqual(sched_pv.name, 'pv_name') sched_fc = fc0(device.q[0].drive, name='fc_name') | sched1 self.assertEqual(sched_fc.name, 'fc_name') sched_snapshot = snapshot | sched1 self.assertEqual(sched_snapshot.name, 'snapshot_label')
def test_persistent_value(self): """Test converted qobj from PersistentValueInstruction.""" converter = PulseQobjConverter(PulseQobjInstruction, meas_level=2) command = PersistentValue(value=0.1j) instruction = command(self.device.q[0].drive) valid_qobj = PulseQobjInstruction(name='pv', ch='d0', t0=0, val=0.1j) self.assertEqual(converter(0, instruction), valid_qobj)
def test_persistent_value(self): """Test converted qobj from PersistentValueInstruction.""" cmd = PersistentValue(value=0.1j) instruction = cmd(ControlChannel(1)) qobj = PulseQobjInstruction(name='pv', ch='u1', t0=0, val=0.1j) converted_instruction = self.converter(qobj) self.assertEqual(converted_instruction.timeslots, instruction.timeslots) self.assertEqual(converted_instruction.instructions[0][-1].command, cmd)
def test_persistent_value(self): """Test converted qobj from PersistentValueInstruction.""" with self.assertWarns(DeprecationWarning): cmd = PersistentValue(value=0.1j) with self.assertWarns(DeprecationWarning): instruction = cmd(ControlChannel(1)) qobj = PulseQobjInstruction(name='pv', ch='u1', t0=0, val=0.1j) with self.assertWarns(DeprecationWarning): converted_instruction = self.converter(qobj) self.assertEqual(converted_instruction.timeslots, instruction.timeslots) self.assertEqual(converted_instruction.instructions[0][-1], instruction)
def test_persistent_value(self): """Test converted qobj from PersistentValueInstruction.""" converter = InstructionToQobjConverter(PulseQobjInstruction, meas_level=2) with self.assertWarns(DeprecationWarning): command = PersistentValue(value=0.1j) with self.assertWarns(DeprecationWarning): instruction = command(DriveChannel(0)) valid_qobj = PulseQobjInstruction(name='pv', ch='d0', t0=0, val=0.1j) with self.assertWarns(DeprecationWarning): self.assertEqual(converter(0, instruction), valid_qobj)
def test_parameterized_persistent_value(self): """Test converted qobj from PersistentValueInstruction.""" cmd = PersistentValue(value=0.5+0.j) instruction = cmd(ControlChannel(1)) << 10 qobj = PulseQobjInstruction(name='pv', ch='u1', t0=10, val='P1*cos(np.pi*P2)') converted_instruction = self.converter(qobj) self.assertIsInstance(converted_instruction, ParameterizedSchedule) evaluated_instruction = converted_instruction.bind_parameters(P1=0.5, P2=0.) self.assertEqual(evaluated_instruction.timeslots, instruction.timeslots) self.assertEqual(evaluated_instruction.instructions[0][-1].command, cmd)
def test_can_create_valid_schedule_with_syntax_sugar(self): """Test that in place operations on schedule are still immutable and return equivalent schedules.""" gp0 = pulse_lib.gaussian(duration=20, amp=0.7, sigma=3) gp1 = pulse_lib.gaussian(duration=20, amp=0.5, sigma=3) acquire = Acquire(10) sched = Schedule() sched += gp0(self.config.drive(0)) sched |= PersistentValue(value=0.2 + 0.4j)(self.config.control(0)) sched |= ShiftPhase(-1.57, self.config.drive(0)) << 60 sched |= gp1(self.config.drive(0)) << 30 sched |= gp0(self.config.control(0)) << 60 sched |= Snapshot("label", "snap_type") << 60 sched |= ShiftPhase(1.57, self.config.drive(0)) << 90 sched |= acquire(self.config.acquire(0), MemorySlot(0), RegisterSlot(0)) << 90 sched += sched
def test_can_create_valid_schedule_with_syntax_sugar(self): """Test that in place operations on schedule are still immutable and return equivalent schedules.""" gp0 = pulse_lib.gaussian(duration=20, amp=0.7, sigma=3) gp1 = pulse_lib.gaussian(duration=20, amp=0.5, sigma=3) sched = Schedule() sched += Play(gp0, self.config.drive(0)) with self.assertWarns(DeprecationWarning): sched |= PersistentValue(value=0.2 + 0.4j)(self.config.control( [0, 1])[0]) sched |= ShiftPhase(-1.57, self.config.drive(0)) << 60 sched |= Play(gp1, self.config.drive(0)) << 30 sched |= Play(gp0, self.config.control(qubits=[0, 1])[0]) << 60 sched |= Snapshot("label", "snap_type") << 60 sched |= ShiftPhase(1.57, self.config.drive(0)) << 90 sched |= Acquire(10, self.config.acquire(0), MemorySlot(0)) << 90 sched += sched
def test_parameterized_persistent_value(self): """Test converted qobj from PersistentValueInstruction.""" with self.assertWarns(DeprecationWarning): cmd = PersistentValue(value=0.5+0.j) with self.assertWarns(DeprecationWarning): instruction = cmd(ControlChannel(1)) << 10 qobj = PulseQobjInstruction(name='pv', ch='u1', t0=10, val='P1*cos(np.pi*P2)') converted_instruction = self.converter(qobj) self.assertIsInstance(converted_instruction, ParameterizedSchedule) with self.assertWarns(DeprecationWarning): evaluated_instruction = converted_instruction.bind_parameters(P1=0.5, P2=0.) self.assertEqual(evaluated_instruction.start_time, instruction.start_time) self.assertEqual(evaluated_instruction.duration, instruction.duration) self.assertEqual(evaluated_instruction.instructions[0][-1].command, cmd)
def test_can_create_valid_schedule_with_syntax_sugar(self): """Test that in place operations on schedule are still immutable and return equivalent schedules.""" device = self.two_qubit_device gp0 = pulse_lib.gaussian(duration=20, amp=0.7, sigma=3) gp1 = pulse_lib.gaussian(duration=20, amp=0.5, sigma=3) fc_pi_2 = FrameChange(phase=1.57) acquire = Acquire(10) sched = Schedule() sched += gp0(device.q[0].drive) sched |= PersistentValue(value=0.2 + 0.4j)(device.q[0].controls[0]) sched |= FrameChange(phase=-1.57)(device.q[0].drive) << 60 sched |= gp1(device.q[1].drive) << 30 sched |= gp0(device.q[0].controls[0]) << 60 sched |= Snapshot("label", "snap_type") << 60 sched |= fc_pi_2(device.q[0].drive) << 90 sched |= acquire(device.q[1], device.mem[1], device.c[1]) << 90 sched += sched