def test_phase_offset(self): """Test the phase offset context.""" d0 = pulse.DriveChannel(0) with pulse.build() as schedule: with pulse.phase_offset(3.14, d0): pulse.delay(10, d0) reference = pulse.Schedule() reference += instructions.ShiftPhase(3.14, d0) reference += instructions.Delay(10, d0) reference += instructions.ShiftPhase(-3.14, d0) self.assertEqual(schedule, reference)
def convert_shift_phase(self, instruction): """Return converted `ShiftPhase`. Args: instruction (PulseQobjInstruction): phase shift qobj instruction Returns: Schedule: Converted and scheduled Instruction """ t0 = instruction.t0 channel = self.get_channel(instruction.ch) phase = instruction.phase # This is parameterized if isinstance(phase, str): phase_expr = parse_string_expr(phase, partial_binding=False) def gen_fc_sched(*args, **kwargs): # this should be real value _phase = phase_expr(*args, **kwargs) return instructions.ShiftPhase(_phase, channel) << t0 return ParameterizedSchedule(gen_fc_sched, parameters=phase_expr.params) return instructions.ShiftPhase(phase, channel) << t0
def test_default(self): """Test basic ShiftPhase.""" shift_phase = instructions.ShiftPhase(1.57, channels.DriveChannel(0)) self.assertIsInstance(shift_phase.id, int) self.assertEqual(shift_phase.name, None) self.assertEqual(shift_phase.duration, 0) self.assertEqual(shift_phase.phase, 1.57) self.assertEqual(shift_phase.operands, (1.57, channels.DriveChannel(0))) self.assertEqual(shift_phase, instructions.ShiftPhase(1.57, channels.DriveChannel(0), name='test')) self.assertNotEqual(shift_phase, instructions.ShiftPhase(1.57j, channels.DriveChannel(0), name='test')) self.assertEqual(repr(shift_phase), "ShiftPhase(1.57, DriveChannel(0))")
def test_shift_phase(self): """Test shift phase instruction.""" d0 = pulse.DriveChannel(0) with pulse.build() as schedule: pulse.shift_phase(3.14, d0) reference = pulse.Schedule() reference += instructions.ShiftPhase(3.14, d0) self.assertEqual(schedule, reference)
def convert_shift_phase(self, instruction): """Return converted `ShiftPhase`. Args: instruction (PulseQobjInstruction): phase shift qobj instruction Returns: Schedule: Converted and scheduled Instruction """ t0 = instruction.t0 channel = self.get_channel(instruction.ch) phase = self.disassemble_value(instruction.phase) return instructions.ShiftPhase(phase, channel) << t0
def test_phase_compensated_frequency_offset(self): """Test that the phase offset context properly compensates for phase accumulation.""" d0 = pulse.DriveChannel(0) with pulse.build(self.backend) as schedule: with pulse.frequency_offset(1e9, d0, compensate_phase=True): pulse.delay(10, d0) reference = pulse.Schedule() reference += instructions.ShiftFrequency(1e9, d0) # pylint: disable=no-member reference += instructions.Delay(10, d0) reference += instructions.ShiftPhase( -(1e9*10*self.configuration.dt % (2*np.pi)), d0) reference += instructions.ShiftFrequency(-1e9, d0) # pylint: disable=no-member self.assertEqual(schedule, reference)
def gen_fc_sched(*args, **kwargs): # this should be real value _phase = phase_expr(*args, **kwargs) return instructions.ShiftPhase(_phase, channel) << t0
def test_shift_phase_non_pulse_channel(self): """Test shift phase constructor with illegal channel""" with self.assertRaises(exceptions.PulseError): instructions.ShiftPhase(1.57, channels.RegisterSlot(1), name="test")