Пример #1
0
 def test_build_path_o1_m2_i1_f_i1_f_one_element_custom_and_main_block_requires_stop(self) -> None:
     sequencer = Sequencer()
 
     ps = {'foo': ConstantParameter(1), 'bar': ConstantParameter(7.3)}
     cs = {'foo': DummyCondition()}
     wm = {}
     cm = {}
     elem_main = DummySequencingElement(True)
     sequencer.push(elem_main, ps, cs, channel_mapping=cm)
     
     elem_cstm = DummySequencingElement(True)
     target_block = InstructionBlock()
     sequencer.push(elem_cstm, ps, cs, window_mapping=wm, channel_mapping=cm, target_block=target_block)
     
     sequencer.build()
     
     self.assertFalse(sequencer.has_finished())
     self.assertEqual(ps, elem_main.parameters)
     self.assertEqual(cs, elem_main.conditions)
     self.assertEqual(1, elem_main.requires_stop_call_counter)
     self.assertEqual(0, elem_main.build_call_counter)
     self.assertEqual(ps, elem_cstm.parameters)
     self.assertEqual(cs, elem_cstm.conditions)
     self.assertEqual(1, elem_cstm.requires_stop_call_counter)
     self.assertEqual(0, elem_cstm.build_call_counter)
Пример #2
0
 def test_build_path_o2_m2_i0_i2_tt_m2_i0_i0_two_elements_custom_block(self) -> None:
     sequencer = Sequencer()
             
     ps = {'foo': ConstantParameter(1), 'bar': ConstantParameter(7.3)}
     cs = {'foo': DummyCondition()}
     wm = {'foo': 'bar'}
     
     target_block = InstructionBlock()
     elem2 = DummySequencingElement(False)
     sequencer.push(elem2, ps, cs, window_mapping=wm, target_block=target_block)
     
     elem1 = DummySequencingElement(False)
     sequencer.push(elem1, ps, cs, window_mapping=wm, target_block=target_block)
     
     sequencer.build()
     
     self.assertTrue(sequencer.has_finished())
     self.assertIs(target_block, elem1.target_block)
     self.assertEqual(ps, elem1.parameters)
     self.assertEqual(cs, elem1.conditions)
     self.assertEqual(1, elem1.requires_stop_call_counter)
     self.assertEqual(1, elem1.build_call_counter)
     self.assertIs(target_block, elem2.target_block)
     self.assertEqual(ps, elem2.parameters)
     self.assertEqual(cs, elem2.conditions)
     self.assertEqual(1, elem2.requires_stop_call_counter)
     self.assertEqual(1, elem2.build_call_counter)
Пример #3
0
 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
Пример #4
0
    def test_build_path_o2_m1_i2_tf_m2_i1_f_i1_f_two_elements_main_block_last_requires_stop_add_one_element_requires_stop_new_block(self) -> None:
        sequencer = Sequencer()
    
        ps = {'foo': ConstantParameter(1), 'bar': ConstantParameter(7.3)}
        cs = {'foo': DummyCondition()}
        
        new_block = InstructionBlock()
        new_elem = DummySequencingElement(True)
        
        elem1 = DummySequencingElement(False, (new_block, [new_elem]))
        elem2 = DummySequencingElement(True)
        sequencer.push(elem2, ps, cs)
        sequencer.push(elem1, ps, cs)

        instr, stop = sequencer.build()
        
        self.assertFalse(sequencer.has_finished())
        self.assertIs(elem1, instr.elem)
        self.assertEqual(ps, elem1.parameters)
        self.assertEqual(cs, elem1.conditions)
        self.assertEqual(1, elem1.requires_stop_call_counter)
        self.assertEqual(1, elem1.build_call_counter)
        self.assertEqual(ps, elem2.parameters)
        self.assertEqual(cs, elem2.conditions)
        self.assertEqual(2, elem2.requires_stop_call_counter)
        self.assertEqual(0, elem2.build_call_counter)
        self.assertEqual(ps, new_elem.parameters)
        self.assertEqual(cs, new_elem.conditions)
        self.assertEqual(1, new_elem.requires_stop_call_counter)
        self.assertEqual(0, new_elem.build_call_counter)
        self.assertEqual(STOPInstruction(), stop)
Пример #5
0
 def test_build_path_o2_m2_i1_t_i1_t_m2_i0_i0_one_element_custom_block_one_element_main_block(self) -> None:
     sequencer = Sequencer()
             
     ps = {'foo': ConstantParameter(1), 'bar': ConstantParameter(7.3)}
     cs = {'foo': DummyCondition()}
     
     elem_main = DummySequencingElement(False)
     sequencer.push(elem_main, ps, cs)
     
     target_block = InstructionBlock()
     elem_cstm = DummySequencingElement(False)
     sequencer.push(elem_cstm, ps, cs, target_block=target_block)
     
     sequence = sequencer.build()
     
     self.assertTrue(sequencer.has_finished())
     self.assertIs(elem_main, sequence[0].elem)
     self.assertEqual(ps, elem_main.parameters)
     self.assertEqual(cs, elem_main.conditions)
     self.assertEqual(1, elem_main.requires_stop_call_counter)
     self.assertEqual(1, elem_main.build_call_counter)
     self.assertIs(target_block, elem_cstm.target_block)
     self.assertEqual(ps, elem_cstm.parameters)
     self.assertEqual(cs, elem_cstm.conditions)
     self.assertEqual(1, elem_cstm.requires_stop_call_counter)
     self.assertEqual(1, elem_cstm.build_call_counter)
     self.assertEqual(STOPInstruction(), sequence[1])
     self.assertEqual(2, len(sequence))
Пример #6
0
    def __qupulse_template_to_array(sequence, sampling_rate):
        """ Renders a qupulse sequence as array with voltages.

        Args:
            sequence (dict): a waveform is a dictionary with "type" value
            given the used pulse library. The "wave" value should contain
            the actual wave-object.
            sampling_rate (float): The number of samples per second.

        Returns:
            voltages (np.array): The array with voltages generated from the template.
        """
        sequencer = Sequencing()
        template = sequence['wave']
        channels = template.defined_channels
        sequencer.push(
            template,
            dict(),
            channel_mapping={ch: ch
                             for ch in channels},
            window_mapping={w: w
                            for w in template.measurement_names})
        instructions = sequencer.build()
        if not sequencer.has_finished():
            raise PlottingNotPossibleException(template)
        (_, voltages, _) = render(instructions,
                                  sampling_rate / Sequencer.__sec_to_ns)
        return np.array(voltages[next(iter(voltages))])
Пример #7
0
    def test_build_path_o2_m1_i2_tt_m1_i0_two_elements_main_block(self) -> None:
        sequencer = Sequencer()
    
        ps = {'foo': ConstantParameter(1), 'bar': ConstantParameter(7.3)}
        cs = {'foo': DummyCondition()}

        elem1 = DummySequencingElement(False)
        elem2 = DummySequencingElement(False)
        sequencer.push(elem2, ps, cs)
        sequencer.push(elem1, ps, cs)

        sequence = sequencer.build()
        
        self.assertTrue(sequencer.has_finished())
        self.assertIs(elem1, sequence[0].elem)
        self.assertEqual(ps, elem1.parameters)
        self.assertEqual(cs, elem1.conditions)
        self.assertEqual(1, elem1.requires_stop_call_counter)
        self.assertEqual(1, elem1.build_call_counter)
        self.assertIs(elem2, sequence[1].elem)
        self.assertEqual(ps, elem2.parameters)
        self.assertEqual(cs, elem2.conditions)
        self.assertEqual(1, elem2.requires_stop_call_counter)
        self.assertEqual(1, elem2.build_call_counter)
        self.assertEqual(STOPInstruction(), sequence[2])
        self.assertEqual(3, len(sequence))
Пример #8
0
    def test_build_path_o2_m1_i1_t_m2_i0_i1_f_one_element_main_block_adds_one_element_requires_stop_new_block(self) -> None:
        sequencer = Sequencer()
    
        ps = {'foo': ConstantParameter(1), 'bar': ConstantParameter(7.3)}
        cs = {'foo': DummyCondition()}
        
        new_block = InstructionBlock()
        new_elem = DummySequencingElement(True)
        
        elem = DummySequencingElement(False, (new_block, [new_elem]))
        sequencer.push(elem, ps, cs)

        sequence = sequencer.build()
        
        self.assertFalse(sequencer.has_finished())
        self.assertIs(elem, sequence[0].elem)
        self.assertEqual(ps, elem.parameters)
        self.assertEqual(cs, elem.conditions)
        self.assertEqual(1, elem.requires_stop_call_counter)
        self.assertEqual(1, elem.build_call_counter)
        self.assertEqual(ps, new_elem.parameters)
        self.assertEqual(cs, new_elem.conditions)
        self.assertEqual(1, new_elem.requires_stop_call_counter)
        self.assertEqual(0, new_elem.build_call_counter)
        self.assertEqual(STOPInstruction(), sequence[1])
        self.assertEqual(2, len(sequence))
    def build_sequence(self,
                       sequencer: Sequencer,
                       parameters: Dict[str, Parameter],
                       conditions: Dict[str, Condition],
                       measurement_mapping: Dict[str, Optional[str]],
                       channel_mapping: Dict[ChannelID, Optional[ChannelID]],
                       instruction_block: InstructionBlock) -> None:
        self.validate_parameter_constraints(parameters=parameters)
        try:
            real_parameters = {v: parameters[v].get_value() for v in self._repetition_count.variables}
        except KeyError:
            raise ParameterNotProvidedException(next(v for v in self.repetition_count.variables if v not in parameters))

        self.insert_measurement_instruction(instruction_block,
                                            parameters=parameters,
                                            measurement_mapping=measurement_mapping)

        repetition_count = self.get_repetition_count_value(real_parameters)
        if repetition_count > 0:
            body_block = InstructionBlock()
            body_block.return_ip = InstructionPointer(instruction_block, len(instruction_block))

            instruction_block.add_instruction_repj(repetition_count, body_block)
            sequencer.push(self.body, parameters=parameters, conditions=conditions,
                           window_mapping=measurement_mapping, channel_mapping=channel_mapping, target_block=body_block)
 def sequence_pulse(self):
     sequencer = Sequencer()
     sequencer.push(self.pulse,
                    parameters=self.parameters,
                    window_mapping=self.window_mapping,
                    channel_mapping=self.channel_mapping)
     self.program = sequencer.build()
    def test_internal_create_program_both_children_no_duration(self) -> None:
        sub1 = DummyPulseTemplate(duration=0, waveform=None, measurements=[('b', 1, 2)], defined_channels={'A'})
        sub2 = DummyPulseTemplate(duration=0, waveform=None, parameter_names={'foo'}, defined_channels={'A'})
        parameters = {'foo': DummyNoValueParameter()}
        measurement_mapping = {'a': 'a', 'b': 'b'}
        channel_mapping = dict()

        seq = SequencePulseTemplate(sub1, sub2, measurements=[('a', 0, 1)])
        loop = Loop(measurements=None)
        seq._internal_create_program(parameters=parameters,
                                     measurement_mapping=measurement_mapping,
                                     channel_mapping=channel_mapping,
                                     global_transformation=None,
                                     to_single_waveform=set(),
                                     parent_loop=loop)
        self.assertEqual(1, loop.repetition_count)
        self.assertIsNone(loop.waveform)
        self.assertEqual([], loop.children)
        self.assertIsNone(loop._measurements)

        # ensure same result as from Sequencer
        sequencer = Sequencer()
        sequencer.push(seq, parameters=parameters, conditions={}, window_mapping=measurement_mapping, channel_mapping=channel_mapping)
        block = sequencer.build()
        old_program = MultiChannelProgram(block, channels={'A'})
        old_loop = old_program.programs[frozenset({'A'})]
        self.assertEqual(old_loop.waveform, loop.waveform)
        self.assertEqual(old_loop.children, loop.children)
Пример #12
0
 def test_push(self) -> None:
     sequencer = Sequencer()
     
     ps = {'foo': ConstantParameter(1), 'bar': ConstantParameter(7.3)}
     cs = {'foo': DummyCondition()}
     wm = {'foo' : 'bar'}
     elem = DummySequencingElement()
     
     sequencer.push(elem, ps, cs, window_mapping=wm)
     self.assertFalse(sequencer.has_finished())
     sequencer.build()
     self.assertEqual(ps, elem.parameters)
Пример #13
0
    def test_push_float_params(self) -> None:
        sequencer = Sequencer()

        ps = {'foo': 1, 'bar': 7.3}
        cs = {'foo': DummyCondition()}
        elem = DummySequencingElement()
        sequencer.push(elem, ps, cs)
        self.assertFalse(sequencer.has_finished())
        sequencer.build()
        self.assertIsInstance(elem.parameters['foo'], ConstantParameter)
        self.assertIsInstance(elem.parameters['bar'], ConstantParameter)
        self.assertEqual(cs, elem.conditions)
 def build_program_with_sequencer(self: unittest.TestCase,
                                  pulse_template,
                                  measurement_mapping=None,
                                  **kwargs):
     sequencer = Sequencer()
     sequencer.push(sequencing_element=pulse_template,
                    conditions=dict(),
                    **kwargs,
                    window_mapping=measurement_mapping)
     instruction_block = sequencer.build()
     mcp = MultiChannelProgram(instruction_block=instruction_block)
     self.assertEqual(len(mcp.programs), 1)
     return next(iter(mcp.programs.values()))
    def test_create_program_subtemplate_none(self) -> None:
        measurement_mapping = {'meas1': 'meas2'}
        parameter_mapping = {'t': 'k'}
        channel_mapping = {'B': 'default'}

        template = DummyPulseTemplate(measurements=[('meas1', 0, 1)],
                                      measurement_names={'meas1'},
                                      defined_channels={'B'},
                                      waveform=None,
                                      duration=0,
                                      parameter_names={'t'})
        st = MappingPulseTemplate(template,
                                  parameter_mapping=parameter_mapping,
                                  measurement_mapping=measurement_mapping,
                                  channel_mapping=channel_mapping)

        pre_parameters = {'k': ConstantParameter(5)}
        pre_measurement_mapping = {'meas2': 'meas3'}
        pre_channel_mapping = {'default': 'A'}

        program = Loop()
        st._internal_create_program(
            parameters=pre_parameters,
            measurement_mapping=pre_measurement_mapping,
            channel_mapping=pre_channel_mapping,
            to_single_waveform=set(),
            global_transformation=None,
            parent_loop=program)

        self.assertEqual(1, len(template.create_program_calls))
        self.assertEqual(
            (st.map_parameters(pre_parameters),
             st.get_updated_measurement_mapping(pre_measurement_mapping),
             st.get_updated_channel_mapping(pre_channel_mapping), program),
            template.create_program_calls[-1])

        self.assertEqual(1, program.repetition_count)
        self.assertEqual(0, len(program.children))
        self.assertIsNone(program._measurements)

        # ensure same result as from Sequencer
        sequencer = Sequencer()
        sequencer.push(st,
                       parameters=pre_parameters,
                       conditions={},
                       window_mapping=pre_measurement_mapping,
                       channel_mapping=pre_channel_mapping)
        block = sequencer.build()
        program_old = MultiChannelProgram(
            block, channels={'A'}).programs[frozenset({'A'})]
        self.assertEqual(program_old, program)
Пример #16
0
 def test_build_path_o1_m1_i1_f_single_element_requires_stop_main_block(self) -> None:
     sequencer = Sequencer()
 
     elem = DummySequencingElement(True)
     ps = {'foo': ConstantParameter(1), 'bar': ConstantParameter(7.3)}
     cs = {'foo': DummyCondition()}
     sequencer.push(elem, ps, cs)
     sequencer.build()
     
     self.assertFalse(sequencer.has_finished())
     self.assertEqual(ps, elem.parameters)
     self.assertEqual(cs, elem.conditions)
     self.assertEqual(1, elem.requires_stop_call_counter)
     self.assertEqual(0, elem.build_call_counter)
    def test_create_program_internal(self) -> None:
        sub1 = DummyPulseTemplate(duration=3, waveform=DummyWaveform(duration=3), measurements=[('b', 1, 2)], defined_channels={'A'})
        sub2 = DummyPulseTemplate(duration=2, waveform=DummyWaveform(duration=2), parameter_names={'foo'}, defined_channels={'A'})
        parameters = {'foo': DummyNoValueParameter()}
        measurement_mapping = {'a': 'a', 'b': 'b'}
        channel_mapping = dict()
        seq = SequencePulseTemplate(sub1, sub2, measurements=[('a', 0, 1)])
        loop = Loop()
        seq._internal_create_program(parameters=parameters,
                                     measurement_mapping=measurement_mapping,
                                     channel_mapping=channel_mapping,
                                     global_transformation=None,
                                     to_single_waveform=set(),
                                     parent_loop=loop)
        self.assertEqual(1, loop.repetition_count)
        self.assertIsNone(loop.waveform)
        self.assertEqual([Loop(repetition_count=1, waveform=sub1.waveform),
                          Loop(repetition_count=1, waveform=sub2.waveform)],
                         loop.children)
        self.assert_measurement_windows_equal({'a': ([0], [1]), 'b': ([1], [2])}, loop.get_measurement_windows())

        # ensure same result as from Sequencer
        sequencer = Sequencer()
        sequencer.push(seq, parameters=parameters, conditions={}, window_mapping=measurement_mapping, channel_mapping=channel_mapping)
        block = sequencer.build()
        old_program = MultiChannelProgram(block, channels={'A'})
        self.assertEqual(old_program.programs[frozenset({'A'})], loop)

        ### test again with inverted sequence
        seq = SequencePulseTemplate(sub2, sub1, measurements=[('a', 0, 1)])
        loop = Loop()
        seq._internal_create_program(parameters=parameters,
                                     measurement_mapping=measurement_mapping,
                                     channel_mapping=channel_mapping,
                                     global_transformation=None,
                                     to_single_waveform=set(),
                                     parent_loop=loop)
        self.assertEqual(1, loop.repetition_count)
        self.assertIsNone(loop.waveform)
        self.assertEqual([Loop(repetition_count=1, waveform=sub2.waveform),
                          Loop(repetition_count=1, waveform=sub1.waveform)],
                         loop.children)
        self.assert_measurement_windows_equal({'a': ([0], [1]), 'b': ([3], [2])}, loop.get_measurement_windows())

        # ensure same result as from Sequencer
        sequencer = Sequencer()
        sequencer.push(seq, parameters=parameters, conditions={}, window_mapping=measurement_mapping, channel_mapping=channel_mapping)
        block = sequencer.build()
        old_program = MultiChannelProgram(block, channels={'A'})
        self.assertEqual(old_program.programs[frozenset({'A'})], loop)
Пример #18
0
 def build_sequence_loop(self, 
                         delegator: SequencingElement,
                         body: 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:
     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)
Пример #19
0
    def test_create_program_body_none(self) -> None:
        dt = DummyPulseTemplate(parameter_names={'i'},
                                waveform=None,
                                duration=0,
                                measurements=[('b', 2, 1)])
        flt = ForLoopPulseTemplate(body=dt,
                                   loop_index='i',
                                   loop_range=('a', 'b', 'c'),
                                   measurements=[('A', 0, 1)],
                                   parameter_constraints=['c > 1'])

        parameters = {
            'a': ConstantParameter(1),
            'b': ConstantParameter(4),
            'c': ConstantParameter(2)
        }
        measurement_mapping = dict(A='B', b='b')
        channel_mapping = dict(C='D')

        program = Loop()
        flt._internal_create_program(parameters=parameters,
                                     measurement_mapping=measurement_mapping,
                                     channel_mapping=channel_mapping,
                                     parent_loop=program,
                                     to_single_waveform=set(),
                                     global_transformation=None)

        self.assertEqual(0, len(program.children))
        self.assertEqual(1, program.repetition_count)
        self.assertEqual([], program.children)

        # ensure same result as from Sequencer
        sequencer = Sequencer()
        sequencer.push(flt,
                       parameters=parameters,
                       conditions={},
                       window_mapping=measurement_mapping,
                       channel_mapping=channel_mapping)
        block = sequencer.build()
        program_old = MultiChannelProgram(
            block, channels={'A'}).programs[frozenset({'A'})]
        self.assertEqual(program_old.repetition_count,
                         program.repetition_count)
        self.assertEqual(program_old.children, program.children)
        self.assertEqual(program_old.waveform, program.waveform)
Пример #20
0
 def build_sequence(self,
                    sequencer: Sequencer,
                    parameters: Dict[str, Parameter],
                    conditions: Dict[str, Condition],
                    measurement_mapping: Dict[str, str],
                    channel_mapping: Dict['ChannelID', 'ChannelID'],
                    instruction_block: InstructionBlock) -> None:
     self.validate_parameter_constraints(parameters=parameters)
     self.insert_measurement_instruction(instruction_block=instruction_block,
                                         parameters=parameters,
                                         measurement_mapping=measurement_mapping)
     for subtemplate in reversed(self.subtemplates):
         sequencer.push(subtemplate,
                        parameters=parameters,
                        conditions=conditions,
                        window_mapping=measurement_mapping,
                        channel_mapping=channel_mapping,
                        target_block=instruction_block)
Пример #21
0
    def test_internal_create_program_no_waveform(self) -> None:
        measurement_windows = [('M', 0, 5)]

        template = AtomicPulseTemplateStub(measurements=measurement_windows,
                                           parameter_names={'foo'})
        parameters = {'foo': ConstantParameter(7.2)}
        measurement_mapping = {'M': 'N'}
        channel_mapping = {'B': 'A'}
        program = Loop()

        expected_parameters = {k: p.get_value() for k, p in parameters.items()}
        expected_program = Loop()

        with mock.patch.object(template, 'build_waveform',
                               return_value=None) as build_waveform:
            with mock.patch.object(template,
                                   'get_measurement_windows',
                                   wraps=template.get_measurement_windows
                                   ) as get_meas_windows:
                template._internal_create_program(
                    parameters=parameters,
                    measurement_mapping=measurement_mapping,
                    channel_mapping=channel_mapping,
                    parent_loop=program,
                    to_single_waveform=set(),
                    global_transformation=None)
                build_waveform.assert_called_once_with(
                    parameters=expected_parameters,
                    channel_mapping=channel_mapping)
                get_meas_windows.assert_not_called()

        self.assertEqual(expected_program, program)

        # ensure same result as from Sequencer
        sequencer = Sequencer()
        sequencer.push(template,
                       parameters=parameters,
                       conditions={},
                       window_mapping=measurement_mapping,
                       channel_mapping=channel_mapping)
        with mock.patch.object(template, 'build_waveform', return_value=None):
            block = sequencer.build()
        old_program = MultiChannelProgram(block, channels={'A'})
        self.assertEqual(old_program.programs[frozenset({'A'})], program)
    def test_crash(self) -> None:
        table = TablePulseTemplate({'default': [('ta', 'va', 'hold'),
                                                ('tb', 'vb', 'linear'),
                                                ('tend', 0, 'jump')]}, identifier='foo')

        expected_parameters = {'ta', 'tb', 'tc', 'td', 'va', 'vb', 'tend'}
        first_mapping = {
            'ta': 'ta',
            'tb': 'tb',
            'va': 'va',
            'vb': 'vb',
            'tend': 'tend'
        }
        second_mapping = {
            'ta': 'tc',
            'tb': 'td',
            'va': 'vb',
            'vb': 'va + vb',
            'tend': '2 * tend'
        }
        sequence = SequencePulseTemplate((table, first_mapping, {}), (table, second_mapping, {}))
        self.assertEqual(expected_parameters, sequence.parameter_names)

        parameters = {
            'ta': ConstantParameter(2),
            'va': ConstantParameter(2),
            'tb': ConstantParameter(4),
            'vb': ConstantParameter(3),
            'tc': ConstantParameter(5),
            'td': ConstantParameter(11),
            'tend': ConstantParameter(6)}

        sequencer = DummySequencer()
        block = DummyInstructionBlock()
        self.assertFalse(sequence.requires_stop(parameters, {}))
        sequence.build_sequence(sequencer,
                                parameters=parameters,
                                conditions={},
                                measurement_mapping={},
                                channel_mapping={'default': 'default'},
                                instruction_block=block)
        from qupulse.pulses.sequencing import Sequencer
        s = Sequencer()
        s.push(sequence, parameters, channel_mapping={'default': 'EXAMPLE_A'})
Пример #23
0
 def build_sequence(self,
                    sequencer: Sequencer,
                    parameters: Dict[str, Parameter],
                    conditions: Dict[str, 'Condition'],
                    measurement_mapping: Optional[Dict[str, str]],
                    channel_mapping: Dict['ChannelID', 'ChannelID'],
                    instruction_block: InstructionBlock) -> None:
     self.build_call_counter += 1
     self.target_block = instruction_block
     instruction_block.add_instruction(DummyInstruction(self))
     self.parameters = parameters
     self.conditions = conditions
     self.window_mapping = measurement_mapping
     self.channel_mapping = channel_mapping
     if self.push_elements is not None:
         for element in self.push_elements[1]:
             sequencer.push(element, parameters, conditions,
                            window_mapping=measurement_mapping,
                            channel_mapping=channel_mapping,
                            target_block=self.push_elements[0])
Пример #24
0
    def build_sequence(self,
                       sequencer: Sequencer,
                       parameters: Dict[str, Parameter],
                       conditions: Dict[str, Condition],
                       measurement_mapping: Dict[str, str],
                       channel_mapping: Dict[ChannelID, ChannelID],
                       instruction_block: InstructionBlock) -> None:
        self.validate_parameter_constraints(parameters=parameters)

        self.insert_measurement_instruction(instruction_block=instruction_block,
                                            parameters=parameters,
                                            measurement_mapping=measurement_mapping)

        for local_parameters in self._body_parameter_generator(parameters, forward=False):
            sequencer.push(self.body,
                           parameters=local_parameters,
                           conditions=conditions,
                           window_mapping=measurement_mapping,
                           channel_mapping=channel_mapping,
                           target_block=instruction_block)
Пример #25
0
    def integrated_test_with_sequencer_and_pulse_templates(self) -> None:
        # Setup test data
        square = TablePulseTemplate()
        square.add_entry('up', 'v', 'hold')
        square.add_entry('down', 0, 'hold')
        square.add_entry('length', 0)

        mapping1 = {
            'up': 'uptime',
            'down': 'uptime + length',
            'v': 'voltage',
            'length': '0.5 * pulse_length'
        }

        outer_parameters = ['uptime', 'length', 'pulse_length', 'voltage']

        parameters = {}
        parameters['uptime'] = 5
        parameters['length'] = 10
        parameters['pulse_length'] = 100
        parameters['voltage'] = 10

        sequence = SequencePulseTemplate([(square, mapping1),
                                          (square, mapping1)],
                                         outer_parameters)

        # run the sequencer and render the plot
        sample_rate = 20
        sequencer = Sequencer()
        sequencer.push(sequence, parameters)
        block = sequencer.build()
        times, voltages = render(block, sample_rate=sample_rate)

        # compute expected values
        expected_times = numpy.linspace(0, 100, sample_rate)
        expected_voltages = numpy.zeros_like(expected_times)
        expected_voltages[100:300] = numpy.ones(200) * parameters['voltage']

        # compare
        self.assertEqual(expected_times, times)
        self.assertEqual(expected_voltages, voltages)
Пример #26
0
    def test_qupulse_template_to_array_new_style_vs_old_style(self):
        with warnings.catch_warnings():
            warnings.filterwarnings("ignore",
                                    category=UserWarning,
                                    message="qupulse")
            warnings.filterwarnings(
                "ignore",
                category=DeprecationWarning,
                message="InstructionBlock API is deprecated")
            period = 1e-3
            amplitude = 1.5
            sampling_rate = 1e9
            sequence = Sequencer.make_sawtooth_wave(amplitude, period)
            template = sequence['wave']
            channels = template.defined_channels
            sequencer = Sequencing()
            sequencer.push(
                template,
                dict(),
                channel_mapping={ch: ch
                                 for ch in channels},
                window_mapping={w: w
                                for w in template.measurement_names})
            instructions = sequencer.build()
            if not sequencer.has_finished():
                raise PlottingNotPossibleException(template)
            (_, voltages_old, _) = render(instructions, sampling_rate / 1e9)

            loop = template.create_program(
                parameters=dict(),
                measurement_mapping={w: w
                                     for w in template.measurement_names},
                channel_mapping={ch: ch
                                 for ch in channels},
                global_transformation=None,
                to_single_waveform=set())

            (_, voltages_new, _) = render(loop, sampling_rate / 1e9)
            self.assertTrue(len(voltages_old) == len(voltages_new))
            self.assertTrue(np.min(voltages_old) == np.min(voltages_old))
            self.assertTrue(np.max(voltages_old) == np.max(voltages_old))
Пример #27
0
 def build_sequence_loop(self, 
                         delegator: SequencingElement,
                         body: 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:
     
     evaluation_result = self.__callback(self.__loop_iteration)
     if evaluation_result is None:
         raise ConditionEvaluationException()
     if evaluation_result is True:
         sequencer.push(delegator, parameters, conditions, window_mapping=measurement_mapping,
                        channel_mapping=channel_mapping,
                        target_block=instruction_block)
         sequencer.push(body, parameters, conditions, window_mapping=measurement_mapping,
                        channel_mapping=channel_mapping,
                        target_block=instruction_block)
         self.__loop_iteration += 1 # next time, evaluate for next iteration
Пример #28
0
 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:
     
     evaluation_result = self.__callback(self.__loop_iteration)
     if evaluation_result is None:
         raise ConditionEvaluationException()
     if evaluation_result is True:
         sequencer.push(if_branch, parameters, conditions, window_mapping=measurement_mapping,
                        channel_mapping=channel_mapping,
                        target_block=instruction_block)
     else:
         sequencer.push(else_branch, parameters, conditions, window_mapping=measurement_mapping,
                        channel_mapping=channel_mapping,
                        target_block=instruction_block)
Пример #29
0
    def test_build_path_o2_m2_i0_i1_t_m2_i0_i0_one_element_custom_block(self) -> None:
        sequencer = Sequencer()
                
        ps = {'foo': ConstantParameter(1), 'bar': ConstantParameter(7.3)}
        cs = {'foo': DummyCondition()}
        wm = {'foo': 'bar'}
        cm = {'A': 'B'}

        target_block = InstructionBlock()
        elem = DummySequencingElement(False)
        sequencer.push(elem, ps, cs, window_mapping=wm, channel_mapping=cm, target_block=target_block)
        
        sequencer.build()
        
        self.assertTrue(sequencer.has_finished())
        self.assertIs(target_block, elem.target_block)
        self.assertEqual(ps, elem.parameters)
        self.assertEqual(cs, elem.conditions)
        self.assertEqual(wm, elem.window_mapping)
        self.assertEqual(cm, elem.channel_mapping)
        self.assertEqual(1, elem.requires_stop_call_counter)
        self.assertEqual(1, elem.build_call_counter)
Пример #30
0
 def test_build_path_o2_m2_i2_tt_t_i2_tf_m2_i0_i1_f_two_elements_custom_block_last_requires_stop_two_element_main_block(self) -> None:
     sequencer = Sequencer()
             
     ps = {'foo': ConstantParameter(1), 'bar': ConstantParameter(7.3)}
     cs = {'foo': DummyCondition()}
     wm = {'foo': 'bar'}
     
     target_block = InstructionBlock()
     elem2 = DummySequencingElement(True)
     sequencer.push(elem2, ps, cs, window_mapping=wm, target_block=target_block)
     
     elem1 = DummySequencingElement(False)
     sequencer.push(elem1, ps, cs, window_mapping=wm, target_block=target_block)
     
     elem_main2 = DummySequencingElement(False)
     sequencer.push(elem_main2, ps, cs)
     
     elem_main1 = DummySequencingElement(False)
     sequencer.push(elem_main1, ps, cs)
     
     sequence = sequencer.build()
     
     self.assertFalse(sequencer.has_finished())
     self.assertIs(target_block, elem1.target_block)
     self.assertEqual(ps, elem1.parameters)
     self.assertEqual(cs, elem1.conditions)
     self.assertEqual(1, elem1.requires_stop_call_counter)
     self.assertEqual(1, elem1.build_call_counter)
     self.assertEqual(ps, elem2.parameters)
     self.assertEqual(cs, elem2.conditions)
     self.assertEqual(2, elem2.requires_stop_call_counter)
     self.assertEqual(0, elem2.build_call_counter)
     self.assertIs(elem_main1, sequence[0].elem)
     self.assertEqual(ps, elem_main1.parameters)
     self.assertEqual(cs, elem_main1.conditions)
     self.assertEqual(1, elem_main1.requires_stop_call_counter)
     self.assertEqual(1, elem_main1.build_call_counter)
     self.assertIs(elem_main2, sequence[1].elem)
     self.assertEqual(ps, elem_main2.parameters)
     self.assertEqual(cs, elem_main2.conditions)
     self.assertEqual(1, elem_main2.requires_stop_call_counter)
     self.assertEqual(1, elem_main2.build_call_counter)
     self.assertEqual(STOPInstruction(), sequence[2])
     self.assertEqual(3, len(sequence))