Skip to content

Commit

Permalink
Merge pull request #2 from nkanazawa1989/schedule-improve
Browse files Browse the repository at this point in the history
Schedule improve
  • Loading branch information
itoko authored Mar 7, 2019
2 parents 5aacb11 + 812801e commit 003f2c4
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 25 deletions.
3 changes: 3 additions & 0 deletions qiskit/pulse/channels/output_channel.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,9 @@ def __init__(self, index: int, lo_frequency: float = None):
def lo_frequency(self) -> float:
return self._lo_frequency

def set_lo_frequency(self, lo_frequency: float):
self._lo_frequency = lo_frequency

def __eq__(self, other):
"""Two output channels are the same if they are of the same type, and
have the same index and lo_frequency.
Expand Down
36 changes: 11 additions & 25 deletions qiskit/pulse/schedule/pulse_schedule.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,46 +94,39 @@ def channels(self) -> ChannelBank:
def add(self,
commands: Union[PulseCommand, List[PulseCommand]],
channel: PulseChannel,
start_time: int) -> bool:
start_time: int):
"""Add new pulse command(s) with channel and start time context.
Args:
commands (PulseCommand|list):
channel:
start_time:
Returns:
True if succeeded, otherwise False
"""
if isinstance(commands, PulseCommand):
return self.add_block(TimedPulse(commands, channel, start_time))
try:
self.add_block(TimedPulse(commands, channel, start_time))
except ScheduleError as err:
logger.warning("Fail to add %s to %s at %s", commands, channel, start_time)
raise ScheduleError(err.message)
elif isinstance(commands, list):
for cmd in commands:
success = self.add(cmd, channel, start_time)
if not success:
logger.warning("Fail to add %s to %s at %s", cmd, channel, start_time)
return False # TODO: or raise Exception?
return True
self.add(cmd, channel, start_time)

def add_block(self, block: TimedPulseBlock) -> bool:
def add_block(self, block: TimedPulseBlock):
"""Add a new composite pulse `TimedPulseBlock`.
Args:
block:
Returns:
True if succeeded, otherwise False
"""
if isinstance(block, PulseSchedule):
if self._channel_bank != block._channel_bank:
raise ScheduleError("additional block must have the same channels as self")
raise ScheduleError("Additional block must have the same channels as self")

if self._is_occupied_time(block):
logger.warning("a pulse block is not added due to the occupied timing: %s", str(block))
return False # TODO: or raise Exception?
logger.warning("A pulse block is not added due to the occupied timing: %s", str(block))
raise ScheduleError("Cannot add to occupied time slot.")
else:
self._children.append(block)
return True

def start_time(self) -> int:
return min([self._start_time(child) for child in self._children])
Expand Down Expand Up @@ -171,13 +164,6 @@ def _is_occupied_time(self, timed_pulse) -> bool:
return True
return False

def remove(self, timed_pulse: TimedPulseBlock):
# TODO: This is still a MVP
for child in self._children:
if not isinstance(child, TimedPulse):
raise NotImplementedError()
self._children.remove(timed_pulse)

def get_sample_pulses(self) -> List[PulseCommand]:
# TODO: This is still a MVP
for child in self._children:
Expand Down

0 comments on commit 003f2c4

Please sign in to comment.