def test_frequency_offset(self):
        """Test the frequency offset context."""
        d0 = pulse.DriveChannel(0)

        with pulse.build() as schedule:
            with pulse.frequency_offset(1e9, d0):
                pulse.delay(10, d0)

        reference = pulse.Schedule()
        reference += instructions.ShiftFrequency(1e9, d0)  # pylint: disable=no-member
        reference += instructions.Delay(10, d0)
        reference += instructions.ShiftFrequency(-1e9, d0)  # pylint: disable=no-member

        self.assertEqual(schedule, reference)
    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)
Beispiel #3
0
    def convert_shift_frequency(self, instruction):
        """Return converted `ShiftFrequency`.

        Args:
            instruction (PulseQobjInstruction): Shift frequency qobj instruction.
                                                The input frequency is expressed  in GHz,
                                                so it will be scaled by a factor 1e9.

        Returns:
            Schedule: Converted and scheduled Instruction
        """
        t0 = instruction.t0
        channel = self.get_channel(instruction.ch)
        frequency = instruction.frequency

        if isinstance(frequency, str):
            frequency_expr = parse_string_expr(frequency,
                                               partial_binding=False)

            def gen_sf_schedule(*args, **kwargs):
                _frequency = frequency_expr(*args, **kwargs)
                return instructions.ShiftFrequency(
                    _frequency * GIGAHERTZ_TO_SI_UNITS, channel) << t0

            return ParameterizedSchedule(gen_sf_schedule,
                                         parameters=frequency_expr.params)
        else:
            frequency = frequency * GIGAHERTZ_TO_SI_UNITS

        return instructions.ShiftFrequency(frequency, channel) << t0
    def convert_shift_frequency(self, instruction):
        """Return converted `ShiftFrequency`.

        Args:
            instruction (PulseQobjInstruction): Shift frequency qobj instruction.

        Returns:
            Schedule: Converted and scheduled Instruction
        """
        t0 = instruction.t0
        channel = self.get_channel(instruction.ch)
        frequency = instruction.frequency * 1e9

        if isinstance(frequency, str):
            frequency_expr = parse_string_expr(frequency,
                                               partial_binding=False)

            def gen_sf_schedule(*args, **kwargs):
                _frequency = frequency_expr(*args, **kwargs)
                return instructions.ShiftFrequency(_frequency, channel) << t0

            return ParameterizedSchedule(gen_sf_schedule,
                                         parameters=frequency_expr.params)

        return instructions.ShiftFrequency(frequency, channel) << t0
    def test_shift_frequency(self):  # pylint: disable=no-member
        """Test shift frequency instruction."""
        d0 = pulse.DriveChannel(0)

        with pulse.build() as schedule:
            pulse.shift_frequency(0.1e9, d0)

        reference = pulse.Schedule()
        reference += instructions.ShiftFrequency(0.1e9, d0)  # pylint: disable=no-member

        self.assertEqual(schedule, reference)
Beispiel #6
0
    def test_shift_frequency(self):
        """Test shift frequency instruction."""
        d0 = pulse.DriveChannel(0)

        with pulse.build() as schedule:
            pulse.shift_frequency(0.1e9, d0)

        reference = pulse.Schedule()
        reference += instructions.ShiftFrequency(0.1e9, d0)

        self.assertScheduleEqual(schedule, reference)
Beispiel #7
0
    def test_shift_freq(self):
        """Test shift frequency basic functionality."""
        shift_freq = instructions.ShiftFrequency(4.5e9,
                                                 channels.DriveChannel(1),
                                                 name="test")

        self.assertIsInstance(shift_freq.id, int)
        self.assertEqual(shift_freq.duration, 0)
        self.assertEqual(shift_freq.frequency, 4.5e9)
        self.assertEqual(shift_freq.operands,
                         (4.5e9, channels.DriveChannel(1)))
        self.assertEqual(
            shift_freq,
            instructions.ShiftFrequency(4.5e9,
                                        channels.DriveChannel(1),
                                        name="test"))
        self.assertNotEqual(
            shift_freq,
            instructions.ShiftFrequency(4.5e8,
                                        channels.DriveChannel(1),
                                        name="test"))
        self.assertEqual(
            repr(shift_freq),
            "ShiftFrequency(4500000000.0, DriveChannel(1), name='test')")
    def convert_shift_frequency(self, instruction):
        """Return converted `ShiftFrequency`.

        Args:
            instruction (PulseQobjInstruction): Shift frequency qobj instruction.
                                                The input frequency is expressed  in GHz,
                                                so it will be scaled by a factor 1e9.

        Returns:
            Schedule: Converted and scheduled Instruction
        """
        t0 = instruction.t0
        channel = self.get_channel(instruction.ch)
        frequency = self.disassemble_value(instruction.frequency) * GIGAHERTZ_TO_SI_UNITS

        return instructions.ShiftFrequency(frequency, channel) << t0
 def gen_sf_schedule(*args, **kwargs):
     _frequency = frequency_expr(*args, **kwargs)
     return instructions.ShiftFrequency(_frequency, channel) << t0
Beispiel #10
0
 def gen_sf_schedule(*args, **kwargs):
     _frequency = frequency_expr(*args, **kwargs)
     return instructions.ShiftFrequency(
         _frequency * GIGAHERTZ_TO_SI_UNITS, channel) << t0
Beispiel #11
0
 def test_freq_non_pulse_channel(self):
     """Test shift frequency constructor with illegal channel"""
     with self.assertRaises(exceptions.PulseError):
         instructions.ShiftFrequency(4.5e9,
                                     channels.RegisterSlot(1),
                                     name="test")