Skip to content

Commit

Permalink
Bugfix: raise instruction block error in correct position
Browse files Browse the repository at this point in the history
  • Loading branch information
terrorfisch committed Jun 14, 2018
1 parent 30faa75 commit 37be7fd
Showing 1 changed file with 10 additions and 9 deletions.
19 changes: 10 additions & 9 deletions qctoolkit/hardware/program.py
Original file line number Diff line number Diff line change
Expand Up @@ -269,24 +269,25 @@ def __init__(self, instruction_block: AbstractInstructionBlock, channels: Iterab
def find_defined_channels(instruction_list):
for instruction in instruction_list:
if isinstance(instruction, EXECInstruction):
return instruction.waveform.defined_channels
yield instruction.waveform.defined_channels
elif isinstance(instruction, REPJInstruction):
for _ in range(instruction.count):
return find_defined_channels(
instruction.target.block.instructions[instruction.target.offset:])
yield from find_defined_channels(
instruction.target.block.instructions[instruction.target.offset:])
elif isinstance(instruction, GOTOInstruction):
return find_defined_channels(instruction.target.block.instructions[instruction.target.offset:])
yield from find_defined_channels(instruction.target.block.instructions[instruction.target.offset:])
elif isinstance(instruction, CHANInstruction):
return itertools.chain(*instruction.channel_to_instruction_block.keys())
yield itertools.chain(*instruction.channel_to_instruction_block.keys())
elif isinstance(instruction, STOPInstruction):
break
return
elif isinstance(instruction, MEASInstruction):
pass
else:
raise TypeError('Unhandled instruction type', type(instruction))
raise ValueError('Instruction block has no defined channels')

channels = find_defined_channels(instruction_block.instructions)
try:
channels = next(find_defined_channels(instruction_block.instructions))
except StopIteration:
raise ValueError('Instruction block has no defined channels')
else:
channels = set(channels)

Expand Down

0 comments on commit 37be7fd

Please sign in to comment.