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 #3
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 #4
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))