def test_iter_waveform_exceptions(self) -> None: wf1 = DummyWaveform(duration=7) wf2 = DummyWaveform(duration=5) wf3 = DummyWaveform(duration=3) repeated_block = InstructionBlock() repeated_block.add_instruction_meas([('m', 1, 2)]) repeated_block.add_instruction_exec(wf2) repeated_block.add_instruction_exec(wf1) main_block = InstructionBlock() main_block.add_instruction_exec(wf1) main_block.add_instruction_repj(2, repeated_block) main_block.add_instruction_exec(wf3) main_block.add_instruction_goto(repeated_block) with self.assertRaises(NotImplementedError): list(iter_waveforms(main_block)) repeated_block.add_instruction(DummyInstruction()) with self.assertRaises(NotImplementedError): list(iter_waveforms(main_block)) main_block = InstructionBlock() main_block.add_instruction_stop() with self.assertRaises(StopIteration): next(iter_waveforms(main_block))
def test_iter_instruction_block_exceptions(self) -> None: wf1 = DummyWaveform(duration=7) wf2 = DummyWaveform(duration=5) wf3 = DummyWaveform(duration=3) repeated_block = InstructionBlock() repeated_block.add_instruction_meas([('m', 1, 2)]) repeated_block.add_instruction_exec(wf2) main_block = InstructionBlock() main_block.add_instruction_exec(wf1) main_block.add_instruction_repj(2, repeated_block) main_block.add_instruction_exec(wf3) repeated_block.add_instruction_goto(main_block) with self.assertRaises(NotImplementedError): iter_instruction_block(main_block, False) repeated_block = InstructionBlock() repeated_block.add_instruction_meas([('m', 1, 2)]) repeated_block.add_instruction_exec(wf2) repeated_block.add_instruction(DummyInstruction()) main_block = InstructionBlock() main_block.add_instruction_exec(wf1) main_block.add_instruction_repj(2, repeated_block) main_block.add_instruction_exec(wf3) with self.assertRaises(NotImplementedError): iter_instruction_block(main_block, False)
def build_sequence_branch(self, delegator: SequencingElement, if_branch: SequencingElement, else_branch: SequencingElement, sequencer: Sequencer, parameters: Dict[str, Parameter], conditions: Dict[str, Condition], measurement_mapping: Dict[str, str], channel_mapping: Dict[ChannelID, ChannelID], instruction_block: InstructionBlock) -> None: if_block = InstructionBlock() else_block = InstructionBlock() instruction_block.add_instruction_cjmp(self.__trigger, if_block) sequencer.push(if_branch, parameters, conditions, window_mapping=measurement_mapping, channel_mapping=channel_mapping, target_block=if_block) instruction_block.add_instruction_goto(else_block) sequencer.push(else_branch, parameters, conditions, window_mapping=measurement_mapping, channel_mapping=channel_mapping, target_block=else_block) if_block.return_ip = InstructionPointer(instruction_block, len(instruction_block.instructions)) else_block.return_ip = if_block.return_ip
def test_nested_goto(self) -> None: parent_block = InstructionBlock() block = InstructionBlock() block.return_ip = InstructionPointer(parent_block, 1) parent_block.add_instruction_goto(block) context = dict() immutable_block = ImmutableInstructionBlock(parent_block, context) self.__verify_block(parent_block, immutable_block, context)
def test_nested_no_context_argument(self) -> None: parent_block = InstructionBlock() block = InstructionBlock() block.return_ip = InstructionPointer(parent_block, 1) parent_block.add_instruction_goto(block) immutable_block = ImmutableInstructionBlock(parent_block) context = { parent_block: immutable_block, block: immutable_block.instructions[0].target.block } self.__verify_block(parent_block, immutable_block, context)
def test_add_instruction_goto(self) -> None: block = InstructionBlock() expected_instructions = [] targets = [InstructionBlock(), InstructionBlock(), InstructionBlock()] LOOKUP = [0, 1, 1, 0, 2, 1, 0, 0, 0, 1, 2, 2] for id in LOOKUP: target = targets[id] instruction = GOTOInstruction(InstructionPointer(target)) expected_instructions.append(instruction) block.add_instruction_goto(target) expected_compiled_instructions = expected_instructions.copy() expected_compiled_instructions.append(STOPInstruction()) self.__verify_block(block, expected_instructions, expected_compiled_instructions, None)