示例#1
0
 def build_sequence_branch(self,
                           delegator: sequencing.SequencingElement,
                           if_branch: sequencing.SequencingElement,
                           else_branch: sequencing.SequencingElement,
                           sequencer: sequencing.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
示例#2
0
 def test_nested_cjmp(self) -> None:
     parent_block = InstructionBlock()
     block = InstructionBlock()
     block.return_ip = InstructionPointer(parent_block, 1)
     parent_block.add_instruction_cjmp(Trigger(), block)
     context = dict()
     immutable_block = ImmutableInstructionBlock(parent_block, context)
     self.__verify_block(parent_block, immutable_block, context)
示例#3
0
    def build_sequence_loop(self, delegator: SequencingElement,
                            body: SequencingElement, sequencer: Sequencer,
                            parameters: Dict[str, Parameter],
                            conditions: Dict[str, Condition],
                            instruction_block: InstructionBlock) -> None:
        body_block = InstructionBlock()
        body_block.return_ip = InstructionPointer(
            instruction_block, len(instruction_block.instructions))

        instruction_block.add_instruction_cjmp(self.__trigger, body_block)
        sequencer.push(body, parameters, conditions, body_block)
    def test_add_instruction_cjmp(self) -> None:
        block = InstructionBlock()
        expected_instructions = []
        expected_compiled_instructions = []
        
        targets = [(InstructionBlock(), 0), (InstructionBlock(), 1), (InstructionBlock(), 50)]
        triggers = [Trigger(), Trigger()]
        LOOKUP = [(0, 0), (1, 0), (1, 1), (0, 1), (2, 0), (1, 0), (0, 1), (0, 1), (0, 0), (1, 0), (2, 1), (2, 1)]
        for i in LOOKUP:
            block.add_instruction_cjmp(triggers[i[1]], targets[i[0]])
            expected_instructions.append(CJMPInstruction(triggers[i[1]], targets[i[0]], 0))

        expected_compiled_instructions = expected_instructions.copy()
        expected_compiled_instructions.append(STOPInstruction())
        self.__verify_block(block, expected_instructions, expected_compiled_instructions)
示例#5
0
 def build_sequence_loop(self, 
                         delegator: sequencing.SequencingElement,
                         body: sequencing.SequencingElement,
                         sequencer: sequencing.Sequencer,
                         parameters: Dict[str, Parameter],
                         conditions: Dict[str, Condition],
                         measurement_mapping: Dict[str, str],
                         channel_mapping: Dict[ChannelID, ChannelID],
                         instruction_block: InstructionBlock) -> None:
     body_block = InstructionBlock()
     body_block.return_ip = InstructionPointer(instruction_block,
                                               len(instruction_block.instructions))
     
     instruction_block.add_instruction_cjmp(self.__trigger, body_block)
     sequencer.push(body, parameters, conditions, window_mapping=measurement_mapping,
                    channel_mapping=channel_mapping,
                    target_block=body_block)
示例#6
0
    def test_add_instruction_cjmp(self) -> None:
        block = InstructionBlock()
        expected_instructions = []

        targets = [InstructionBlock(), InstructionBlock(), InstructionBlock()]
        triggers = [Trigger(), Trigger()]
        LOOKUP = [(0, 0), (1, 0), (1, 1), (0, 1), (2, 0), (1, 0), (0, 1),
                  (0, 1), (0, 0), (1, 0), (2, 1), (2, 1)]
        for i in LOOKUP:
            block.add_instruction_cjmp(triggers[i[1]], targets[i[0]])
            expected_instructions.append(
                CJMPInstruction(triggers[i[1]],
                                InstructionPointer(targets[i[0]], 0)))

        expected_compiled_instructions = expected_instructions.copy()
        expected_compiled_instructions.append(STOPInstruction())
        self.__verify_block(block, expected_instructions,
                            expected_compiled_instructions, None)
示例#7
0
    def build_sequence_branch(self, delegator: SequencingElement,
                              if_branch: SequencingElement,
                              else_branch: SequencingElement,
                              sequencer: Sequencer,
                              parameters: Dict[str, Parameter],
                              conditions: Dict[str, Condition],
                              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, if_block)

        instruction_block.add_instruction_goto(else_block)
        sequencer.push(else_branch, parameters, conditions, else_block)

        if_block.return_ip = InstructionPointer(
            instruction_block, len(instruction_block.instructions))
        else_block.return_ip = if_block.return_ip
示例#8
0
    def test_multiple_nested_block_construction(self) -> None:
        main_block = InstructionBlock()
        blocks = []
        waveforms = [DummyWaveform(), DummyWaveform(), DummyWaveform()]

        main_block.add_instruction_exec(waveforms[0])

        block = InstructionBlock()
        trigger = Trigger()
        ip = InstructionPointer(block)
        main_block.add_instruction_cjmp(trigger, block)
        block.return_ip = InstructionPointer(main_block, len(main_block))
        blocks.append(block)

        block = InstructionBlock()
        trigger = Trigger()
        ip = InstructionPointer(block)
        main_block.add_instruction_cjmp(trigger, block)
        block.return_ip = InstructionPointer(main_block, len(main_block))
        blocks.append(block)

        WAVEFORM_LOOKUP = [[2, 2, 1, 1], [0, 1, 1, 0, 2, 1]]
        for i in [0, 1]:
            block = blocks[i]
            lookup = WAVEFORM_LOOKUP[i]
            for id in lookup:
                waveform = waveforms[id]
                block.add_instruction_exec(waveform)

        block = InstructionBlock()
        ip = InstructionPointer(block)
        blocks[0].add_instruction_cjmp(trigger, block)
        block.return_ip = InstructionPointer(blocks[0], len(blocks[0]))
        blocks.append(block)

        for id in [1, 2, 0, 2]:
            waveform = waveforms[id]
            block.add_instruction_exec(waveform)

        context = dict()
        immutable_block = ImmutableInstructionBlock(main_block, context)
        self.__verify_block(main_block, immutable_block, context.copy())
 def test_nested_block_construction(self) -> None:
     main_block = InstructionBlock()
     expected_instructions = [[], [], [], []]
     expected_compiled_instructions = [[], [], [], []]
     
     blocks = []
         
     waveforms = [DummyWaveform(), DummyWaveform(), DummyWaveform()]
     
     main_block.add_instruction_exec(waveforms[0])
     expected_instructions[0].append(EXECInstruction(waveforms[0]))
     
     block = main_block.create_embedded_block() 
     trigger = Trigger()
     main_block.add_instruction_cjmp(trigger, block)
     expected_instructions[0].append(CJMPInstruction(trigger, block, 0))
     block.return_ip = InstructionPointer(main_block, len(main_block))
     blocks.append(block)
     
     block = main_block.create_embedded_block()
     trigger = Trigger()
     main_block.add_instruction_cjmp(trigger, block)
     expected_instructions[0].append(CJMPInstruction(trigger, block, 0))
     block.return_ip = InstructionPointer(main_block, len(main_block))
     blocks.append(block)
     
     WAVEFORM_LOOKUP = [[2, 2, 1, 1],[0, 1, 1, 0, 2, 1]]
     for i in [0, 1]:
         block = blocks[i]
         lookup = WAVEFORM_LOOKUP[i]
         for id in lookup:
             waveform = waveforms[id]
             expected_instructions[i + 1].append(EXECInstruction(waveform))
             block.add_instruction_exec(waveform)
         
     block = blocks[0].create_embedded_block()
     blocks[0].add_instruction_cjmp(trigger, block)
     expected_instructions[1].append(CJMPInstruction(trigger, block, 0))
     block.return_ip = InstructionPointer(blocks[0], len(blocks[0]))
     blocks.append(block)
     
     for id in [1, 2, 0, 2]:
         waveform = waveforms[id]
         expected_instructions[3].append(EXECInstruction(waveform))
         block.add_instruction_exec(waveform)
     
     for i in [0, 1, 2, 3]:
         expected_compiled_instructions[i] = expected_instructions[i].copy()
     
     expected_compiled_instructions[0].append(STOPInstruction())
     for i in [0, 1, 2]:
         expected_compiled_instructions[i + 1].append(GOTOInstruction(blocks[i].return_ip.block, blocks[i].return_ip.offset))
     
     positions = [0, None, None, None]                
     positions[3] = len(expected_compiled_instructions[1])
     
     expected_compiled_instructions[1].extend(expected_compiled_instructions[3])
     for i in [1, 2]:
         positions[i] = len(expected_compiled_instructions[0])
         expected_compiled_instructions[0].extend(expected_compiled_instructions[i])
         
     positions[3] += positions[1]
     
     self.__verify_block(blocks[2], expected_instructions[3], expected_compiled_instructions[3])
     self.__verify_block(blocks[1], expected_instructions[2], expected_compiled_instructions[2])
     self.__verify_block(blocks[0], expected_instructions[1], expected_compiled_instructions[1])
     self.__verify_block(main_block, expected_instructions[0], expected_compiled_instructions[0])
     
     self.assertEqual(positions[3], blocks[2].get_start_address())
     self.assertEqual(positions[2], blocks[1].get_start_address())
     self.assertEqual(positions[1], blocks[0].get_start_address())
     self.assertEqual(positions[0], main_block.get_start_address())
     
     for instruction in main_block.instructions:
         if isinstance(instruction, GOTOInstruction) or isinstance(instruction, CJMPInstruction):
             self.assertIsInstance(instruction.target.get_absolute_address(), int)
示例#10
0
    def test_nested_block_construction(self) -> None:
        main_block = InstructionBlock()
        expected_instructions = [[], [], [], []]
        expected_compiled_instructions = [[], [], [], []]
        expected_return_ips = [None]

        blocks = []

        waveforms = [DummyWaveform(), DummyWaveform(), DummyWaveform()]

        main_block.add_instruction_exec(waveforms[0])
        expected_instructions[0].append(EXECInstruction(waveforms[0]))

        block = InstructionBlock()
        trigger = Trigger()
        ip = InstructionPointer(block)
        main_block.add_instruction_cjmp(trigger, block)
        expected_instructions[0].append(CJMPInstruction(trigger, ip))
        block.return_ip = InstructionPointer(main_block, len(main_block))
        expected_return_ips.append(
            InstructionPointer(main_block, len(main_block)))
        blocks.append(block)

        block = InstructionBlock()
        trigger = Trigger()
        ip = InstructionPointer(block)
        main_block.add_instruction_cjmp(trigger, block)
        expected_instructions[0].append(CJMPInstruction(trigger, ip))
        block.return_ip = InstructionPointer(main_block, len(main_block))
        expected_return_ips.append(
            InstructionPointer(main_block, len(main_block)))
        blocks.append(block)

        WAVEFORM_LOOKUP = [[2, 2, 1, 1], [0, 1, 1, 0, 2, 1]]
        for i in [0, 1]:
            block = blocks[i]
            lookup = WAVEFORM_LOOKUP[i]
            for id in lookup:
                waveform = waveforms[id]
                expected_instructions[i + 1].append(EXECInstruction(waveform))
                block.add_instruction_exec(waveform)

        block = InstructionBlock()
        ip = InstructionPointer(block)
        blocks[0].add_instruction_cjmp(trigger, block)
        expected_instructions[1].append(CJMPInstruction(trigger, ip))
        block.return_ip = InstructionPointer(blocks[0], len(blocks[0]))
        expected_return_ips.append(
            InstructionPointer(blocks[0], len(blocks[0])))
        blocks.append(block)

        for id in [1, 2, 0, 2]:
            waveform = waveforms[id]
            expected_instructions[3].append(EXECInstruction(waveform))
            block.add_instruction_exec(waveform)

        for i in [0, 1, 2, 3]:
            expected_compiled_instructions[i] = expected_instructions[i].copy()

        expected_compiled_instructions[0].append(STOPInstruction())
        for i in [0, 1, 2]:
            expected_compiled_instructions[i + 1].append(
                GOTOInstruction(blocks[i].return_ip))

        positions = [0, None, None, None]
        positions[3] = len(expected_compiled_instructions[1])

        self.__verify_block(blocks[2], expected_instructions[3],
                            expected_compiled_instructions[3],
                            expected_return_ips[3])
        self.__verify_block(blocks[1], expected_instructions[2],
                            expected_compiled_instructions[2],
                            expected_return_ips[2])
        self.__verify_block(blocks[0], expected_instructions[1],
                            expected_compiled_instructions[1],
                            expected_return_ips[1])
        self.__verify_block(main_block, expected_instructions[0],
                            expected_compiled_instructions[0],
                            expected_return_ips[0])