def __init__(self, *schedules: List[Union[ScheduleComponent, Tuple[int, ScheduleComponent]]],
                 name: Optional[str] = None):
        """Create an empty schedule.

        Args:
            *schedules: Child Schedules of this parent Schedule. May either be passed as
                        the list of schedules, or a list of ``(start_time, schedule)`` pairs.
            name: Name of this schedule. Defaults to an autogenerated string if not provided.
        """
        if name is None:
            name = self.prefix + str(next(self.instances_counter))
            if sys.platform != "win32" and not is_main_process():
                name += '-{}'.format(mp.current_process().pid)

        self._name = name
        self._duration = 0

        self._timeslots = {}
        self.__children = []

        for sched_pair in schedules:
            try:
                time, sched = sched_pair
            except TypeError:
                # recreate as sequence starting at 0.
                time, sched = 0, sched_pair
            self._mutable_insert(time, sched)
Example #2
0
    def __init__(self, *schedules: List[Union[ScheduleComponent, Tuple[int, ScheduleComponent]]],
                 name: Optional[str] = None):
        """Create an empty schedule.

        Args:
            *schedules: Child Schedules of this parent Schedule. May either be passed as
                        the list of schedules, or a list of ``(start_time, schedule)`` pairs.
            name: Name of this schedule. Defaults to an autogenerated string if not provided.
        """
        if name is None:
            name = self.prefix + str(next(self.instances_counter))
            if sys.platform != "win32" and not is_main_process():
                name += '-{}'.format(mp.current_process().pid)

        self._name = name
        self._duration = 0

        self._timeslots = {}
        _children = []
        for sched_pair in schedules:
            if isinstance(sched_pair, list):
                sched_pair = tuple(sched_pair)
            if not isinstance(sched_pair, tuple):
                # recreate as sequence starting at 0.
                sched_pair = (0, sched_pair)
            insert_time, sched = sched_pair
            # This will also update duration
            self._add_timeslots(insert_time, sched)
            _children.append(sched_pair)
        self.__children = tuple(_children)
Example #3
0
    def __init__(self,
                 *schedules: List[Union[ScheduleComponent,
                                        Tuple[int, ScheduleComponent]]],
                 name: Optional[str] = None):
        """Create an empty schedule.

        Args:
            *schedules: Child Schedules of this parent Schedule. May either be passed as
                        the list of schedules, or a list of ``(start_time, schedule)`` pairs.
            name: Name of this schedule. Defaults to an autogenerated string if not provided.

        Raises:
            PulseError: If the input schedules have instructions which overlap.
        """
        if name is None:
            name = self.prefix + str(next(self.instances_counter))
            if sys.platform != "win32" and not is_main_process():
                name += '-{}'.format(mp.current_process().pid)

        self._name = name

        timeslots = []
        _children = []
        for sched_pair in schedules:
            # recreate as sequence starting at 0.
            if not isinstance(sched_pair, (list, tuple)):
                sched_pair = (0, sched_pair)
            # convert to tuple
            sched_pair = tuple(sched_pair)
            insert_time, sched = sched_pair
            if not isinstance(insert_time, int):
                raise PulseError(
                    "Schedule start time was a non-integer. Please cast times to "
                    "integers.")
            sched_timeslots = sched.timeslots
            if insert_time:
                sched_timeslots = sched_timeslots.shift(insert_time)
            timeslots.append(sched_timeslots)
            _children.append(sched_pair)

        try:
            self._timeslots = TimeslotCollection(*timeslots)
        except PulseError as ts_err:
            formatted_schedules = []
            for sched_pair in schedules:
                sched = sched_pair[1] if isinstance(sched_pair,
                                                    (List,
                                                     tuple)) else sched_pair
                formatted_sched = 'Schedule(name="{0}", duration={1})'.format(
                    sched.name, sched.duration)
                formatted_schedules.append(formatted_sched)
            formatted_schedules = ", ".join(formatted_schedules)
            raise PulseError('Schedules overlap: {0} for {1}'
                             ''.format(ts_err.message,
                                       formatted_schedules)) from ts_err

        self.__children = tuple(_children)