Beispiel #1
0
 def test_shift(self):
     """Test if `shift` shifts the collection for specified time.
     """
     actual = TimeslotCollection(Timeslot(Interval(1, 3),
                                          AcquireChannel(0))).shift(10)
     expected = TimeslotCollection(
         Timeslot(Interval(11, 13), AcquireChannel(0)))
     self.assertEqual(expected, actual)
Beispiel #2
0
    def test_zero_duration_timeslot(self):
        """Test that TimeslotCollection works properly for zero duration timeslots."""
        # test that inserting zero duration pulses at start and stop of pulse works.
        TimeslotCollection(Timeslot(Interval(0, 10), AcquireChannel(0)),
                           Timeslot(Interval(0, 0), AcquireChannel(0)),
                           Timeslot(Interval(10, 10), AcquireChannel(0)))

        with self.assertRaises(PulseError):
            TimeslotCollection(Timeslot(Interval(0, 10), AcquireChannel(0)),
                               Timeslot(Interval(5, 5), AcquireChannel(0)))
Beispiel #3
0
    def test_empty_collection(self):
        """Test empty collection creation and its operations.
        """
        empty = TimeslotCollection()
        self.assertEqual(True, empty.is_mergeable_with(empty))

        # can merge with normal collection
        normal = TimeslotCollection(Timeslot(Interval(1, 3), AcquireChannel(0)),
                                    Timeslot(Interval(3, 5), AcquireChannel(0)))
        self.assertEqual(True, empty.is_mergeable_with(normal))
        self.assertEqual(normal, empty.merged(normal))
Beispiel #4
0
    def test_merged_timeslots_do_not_overlap_internally(self):
        """Test to make sure the timeslots do not overlap internally."""
        # same interval but different channel
        int1 = Timeslot(Interval(1, 3), AcquireChannel(0))
        col1 = TimeslotCollection(Timeslot(Interval(5, 7), AcquireChannel(0)))
        col2 = TimeslotCollection(Timeslot(Interval(5, 7), AcquireChannel(1)))

        merged = TimeslotCollection(int1, col1, col2)

        from_internal = TimeslotCollection(*merged.timeslots)

        self.assertEqual(merged, from_internal)
Beispiel #5
0
    def test_complement(self):
        """Test complement of TimeslotCollection is properly created."""
        test_collection = TimeslotCollection(
            Timeslot(Interval(5, 7), DriveChannel(0)),
            Timeslot(Interval(10, 12), DriveChannel(0)),
            Timeslot(Interval(0, 3), DriveChannel(1)))
        ref_complement = TimeslotCollection(
            Timeslot(Interval(0, 5), DriveChannel(0)),
            Timeslot(Interval(7, 10), DriveChannel(0)),
            Timeslot(Interval(3, 12), DriveChannel(1)))
        complement_collection = test_collection.complement()

        self.assertEqual(ref_complement, complement_collection)
Beispiel #6
0
    def test_complement_set_stop_time(self):
        """Test complement of TimeslotCollection obeys stop_time."""
        stop_time = 20

        test_collection = TimeslotCollection(
            Timeslot(Interval(5, 7), DriveChannel(0)),
            Timeslot(Interval(10, 12), DriveChannel(0)),
            Timeslot(Interval(0, 3), DriveChannel(1)))
        ref_complement = TimeslotCollection(
            Timeslot(Interval(0, 5), DriveChannel(0)),
            Timeslot(Interval(7, 10), DriveChannel(0)),
            Timeslot(Interval(12, stop_time), DriveChannel(0)),
            Timeslot(Interval(3, stop_time), DriveChannel(1)))
        complement_collection = test_collection.complement(stop_time=stop_time)

        self.assertEqual(ref_complement, complement_collection)
Beispiel #7
0
    def test_is_mergeable_does_not_mutate_TimeslotCollection(self):
        """Test that is_mergeable_with does not mutate the given TimeslotCollection"""

        # Different channel but different interval
        col1 = TimeslotCollection(Timeslot(Interval(1, 2), AcquireChannel(0)))
        expected_channels = col1.channels
        col2 = TimeslotCollection(Timeslot(Interval(3, 4), AcquireChannel(1)))
        col1.is_mergeable_with(col2)
        self.assertEqual(col1.channels, expected_channels)

        # Different channel but same interval
        col1 = TimeslotCollection(Timeslot(Interval(1, 2), AcquireChannel(0)))
        expected_channels = col1.channels
        col2 = TimeslotCollection(Timeslot(Interval(1, 2), AcquireChannel(1)))
        col1.is_mergeable_with(col2)
        self.assertEqual(col1.channels, expected_channels)
    def __init__(self,
                 command,
                 *channels: List[Channel],
                 timeslots: TimeslotCollection = None,
                 name=None):
        """
        command (Command): Pulse command to schedule
        *channels: List of pulse channels to schedule with command
        timeslots: Optional list of timeslots. If channels are supplied timeslots
            cannot also be given
        name: Name of Instruction
        """
        self._command = command
        self._name = name if name else self._command.name

        if timeslots and channels:
            raise PulseError(
                'Channels and timeslots may not both be supplied.')

        if not timeslots:
            duration = command.duration
            self._timeslots = TimeslotCollection(
                *(Timeslot(Interval(0, duration), channel)
                  for channel in channels))
        else:
            self._timeslots = timeslots
    def __init__(self,
                 command,
                 *channels: List[Channel],
                 timeslots: Optional[TimeslotCollection] = None,
                 name: Optional[str] = None):
        """
        Args:
            command: Pulse command to schedule
            *channels: List of pulse channels to schedule with command
            timeslots: Optional list of timeslots. If channels are supplied timeslots
                cannot also be given
            name: Name of Instruction

        Raises:
            PulseError: If both channels and timeslots are supplied
        """
        self._command = command
        self._name = name if name else self._command.name

        if timeslots and channels:
            raise PulseError(
                'Channels and timeslots may not both be supplied.')

        if not timeslots:
            duration = command.duration
            self._timeslots = TimeslotCollection(
                *(Timeslot(Interval(0, duration), channel)
                  for channel in channels))
        else:
            self._timeslots = timeslots

        channels = self.channels

        self._buffer = max(chan.buffer for chan in channels) if channels else 0
Beispiel #10
0
    def __init__(self, duration: Union['commands.Command', int],
                 *channels: Channel,
                 name: Optional[str] = None):
        """Instruction initializer.

        Args:
            duration: Length of time taken by the instruction in terms of dt.
            *channels: List of pulse channels that this instruction operates on.
            name: Display name for this instruction.
        """
        self._command = None
        if not isinstance(duration, int):
            # TODO: Add deprecation warning once all instructions are migrated
            self._command = duration
            if name is None:
                name = self.command.name
            duration = self.command.duration
        self._duration = duration

        self._timeslots = TimeslotCollection(*(Timeslot(Interval(0, duration), channel)
                                               for channel in channels if channel is not None))

        if name is None:
            name = "{}{}".format(self.__class__.__name__.lower(), str(hex(self.__hash__()))[3:8])
        self._name = name
Beispiel #11
0
 def test_can_create_with_valid_timeslots(self):
     """Test valid time-slot collection creation without error.
     """
     slots = [
         Timeslot(Interval(1, 3), AcquireChannel(0)),
         Timeslot(Interval(3, 5), AcquireChannel(0))
     ]
     TimeslotCollection(*slots)
 def test_empty_schedule(self):
     """Test empty schedule."""
     sched = Schedule()
     self.assertEqual(0, sched.start_time)
     self.assertEqual(0, sched.stop_time)
     self.assertEqual(0, sched.duration)
     self.assertEqual((), sched._children)
     self.assertEqual(TimeslotCollection(), sched.timeslots)
     self.assertEqual([], list(sched.instructions))
Beispiel #13
0
    def __init__(self, command, *channels: List[Channel],
                 name: Optional[str] = None):
        """Instruction initializer.

        Args:
            command: Pulse command to schedule
            *channels: List of pulse channels to schedule with command
            name: Name of Instruction
        """
        self._command = command
        self._name = name if name else self._command.name

        duration = command.duration

        self._timeslots = TimeslotCollection(*(Timeslot(Interval(0, duration), channel)
                                               for channel in channels))

        channels = self.channels
Beispiel #14
0
    def test_can_merge_two_mergeable_collections(self):
        """Test if merge two mergeable time-slot collections.
        """
        # same interval but different channel
        col1 = TimeslotCollection(Timeslot(Interval(1, 3), AcquireChannel(0)))
        col2 = TimeslotCollection(Timeslot(Interval(1, 3), AcquireChannel(1)))
        self.assertEqual(True, col1.is_mergeable_with(col2))
        expected = TimeslotCollection(Timeslot(Interval(1, 3), AcquireChannel(0)),
                                      Timeslot(Interval(1, 3), AcquireChannel(1)))
        self.assertEqual(expected, col1.merged(col2))

        # same channel but different interval
        col1 = TimeslotCollection(Timeslot(Interval(1, 3), AcquireChannel(0)))
        col2 = TimeslotCollection(Timeslot(Interval(3, 5), AcquireChannel(0)))
        self.assertEqual(True, col1.is_mergeable_with(col2))
        expected = TimeslotCollection(Timeslot(Interval(1, 3), AcquireChannel(0)),
                                      Timeslot(Interval(3, 5), AcquireChannel(0)))
        self.assertEqual(expected, col1.merged(col2))
Beispiel #15
0
 def test_unmergeable_collections(self):
     """Test if return false for unmergeable collections.
     """
     col1 = TimeslotCollection(Timeslot(Interval(1, 3), AcquireChannel(0)))
     col2 = TimeslotCollection(Timeslot(Interval(2, 4), AcquireChannel(0)))
     self.assertEqual(False, col1.is_mergeable_with(col2))