Beispiel #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)
Beispiel #2
0
 def test_build_path_o2_m2_i1_f_i2_tf_m2_i1_f_i1_f_two_elements_custom_block_last_requires_stop_one_element_requires_stop_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_main = DummySequencingElement(True)
     sequencer.push(elem_main, ps, cs)
     
     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.assertEqual(ps, elem_main.parameters)
     self.assertEqual(cs, elem_main.conditions)
     self.assertEqual(2, elem_main.requires_stop_call_counter)
     self.assertEqual(0, elem_main.build_call_counter)
Beispiel #3
0
 def test_build_path_o2_m2_i1_f_i1_t_m2_i1_f_i0_one_element_custom_block_one_element_requires_stop_main_block(self) -> None:
     sequencer = Sequencer()
             
     ps = {'foo': ConstantParameter(1), 'bar': ConstantParameter(7.3)}
     cs = {'foo': DummyCondition()}
     
     elem_main = DummySequencingElement(True)
     sequencer.push(elem_main, ps, cs)
     
     target_block = InstructionBlock()
     elem_cstm = DummySequencingElement(False)
     sequencer.push(elem_cstm, ps, cs, 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(2, elem_main.requires_stop_call_counter)
     self.assertEqual(0, 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)
Beispiel #4
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)
Beispiel #5
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)
    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)
Beispiel #7
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)
Beispiel #8
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)
Beispiel #9
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))
Beispiel #10
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))
Beispiel #11
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))])
 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)
Beispiel #14
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)
 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)
Beispiel #17
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)
Beispiel #18
0
 def test_build_path_o2_m2_i2_tt_t_i2_tt_m2_i0_i0_two_elements_custom_block_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(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)
     
     elem_main2 = DummySequencingElement(False)
     sequencer.push(elem_main2, ps, cs)
     
     elem_main1 = DummySequencingElement(False)
     sequencer.push(elem_main1, ps, cs)
     
     sequence = 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)
     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))
Beispiel #19
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)
Beispiel #20
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)
Beispiel #21
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))
    def test_all(self):
        from qupulse.hardware.feature_awg.tabor import TaborChannelTuple, TaborDevice
        #import warnings
        tawg = TaborDevice(r'USB0::0x168C::0x2184::0000216488::INSTR')
        tchannelpair = TaborChannelTuple(tawg, (1, 2), 'TABOR_AB')
        tawg.paranoia_level = 2

        #warnings.simplefilter('error', Warning)

        from qupulse.hardware.setup import HardwareSetup, PlaybackChannel, MarkerChannel
        hardware_setup = HardwareSetup()

        hardware_setup.set_channel('TABOR_A', PlaybackChannel(tchannelpair, 0))
        hardware_setup.set_channel('TABOR_B', PlaybackChannel(tchannelpair, 1))
        hardware_setup.set_channel('TABOR_A_MARKER',
                                   MarkerChannel(tchannelpair, 0))
        hardware_setup.set_channel('TABOR_B_MARKER',
                                   MarkerChannel(tchannelpair, 1))

        if with_alazar:
            from qupulse.hardware.dacs.alazar import AlazarCard
            import atsaverage.server

            if not atsaverage.server.Server.default_instance.running:
                atsaverage.server.Server.default_instance.start(key=b'guest')

            import atsaverage.core

            alazar = AlazarCard(atsaverage.core.getLocalCard(1, 1))
            alazar.register_mask_for_channel('A', 0)
            alazar.register_mask_for_channel('B', 0)
            alazar.register_mask_for_channel('C', 0)
            alazar.config = get_alazar_config()

            alazar.register_operations('test', get_operations())
            window = get_window(atsaverage.core.getLocalCard(1, 1))
            hardware_setup.register_dac(alazar)

        repeated = get_pulse()

        from qupulse.pulses.sequencing import Sequencer

        sequencer = Sequencer()
        sequencer.push(repeated,
                       parameters=dict(n=1000, min=-0.5, max=0.5, tau=192 * 3),
                       channel_mapping={
                           'out': 'TABOR_A',
                           'trigger': 'TABOR_A_MARKER'
                       },
                       window_mapping=dict(A='A', B='B', C='C'))
        instruction_block = sequencer.build()

        hardware_setup.register_program('test', instruction_block)

        if with_alazar:
            from atsaverage.masks import PeriodicMask
            m = PeriodicMask()
            m.identifier = 'D'
            m.begin = 0
            m.end = 1
            m.period = 1
            m.channel = 0
            alazar._registered_programs['test'].masks.append(m)

        hardware_setup.arm_program('test')

        d = 1
    def test_table_sequence_sequencer_integration(self) -> None:
        t1 = TablePulseTemplate(entries={'default': [(2, 'foo'), (5, 0)]},
                                measurements=[('foo', 2, 2)])

        t2 = TablePulseTemplate(
            entries={'default': [(4, 0), (4.5, 'bar', 'linear'), (5, 0)]},
            measurements=[('foo', 4, 1)])

        seqt = SequencePulseTemplate(
            MappingPulseTemplate(t1, measurement_mapping={'foo': 'bar'}),
            MappingPulseTemplate(t2, parameter_mapping={'bar': '2 * hugo'}))

        with self.assertRaises(ParameterNotProvidedException):
            t1.requires_stop(dict(), dict())
        with self.assertRaises(ParameterNotProvidedException):
            t2.requires_stop(dict(), dict())
        self.assertFalse(
            seqt.requires_stop(
                {
                    'foo': DummyParameter(),
                    'hugo': DummyParameter()
                }, {}))

        foo = DummyNoValueParameter()
        bar = DummyNoValueParameter()
        sequencer = Sequencer()
        sequencer.push(seqt, {
            'foo': foo,
            'hugo': bar
        },
                       window_mapping=dict(bar='my', foo='thy'),
                       channel_mapping={'default': 'A'})
        instructions = sequencer.build()
        self.assertFalse(sequencer.has_finished())
        self.assertEqual(1, len(instructions))

        # stop after first TablePT
        foo = DummyParameter(value=1.1)
        bar = DummyNoValueParameter()
        sequencer = Sequencer()
        sequencer.push(seqt, {
            'foo': foo,
            'hugo': bar
        },
                       window_mapping=dict(bar='my', foo='thy'),
                       channel_mapping={'default': 'A'})
        block = sequencer.build()
        instructions = block.instructions
        self.assertFalse(sequencer.has_finished())
        self.assertIsInstance(block, AbstractInstructionBlock)
        self.assertEqual(2, len(instructions))
        self.assertEqual(instructions[0], MEASInstruction([('my', 2, 2)]))
        self.assertIsInstance(instructions[1], EXECInstruction)

        # stop before first TablePT
        foo = DummyParameter(value=1.1)
        bar = DummyNoValueParameter()
        sequencer = Sequencer()
        sequencer.push(seqt, {
            'foo': bar,
            'hugo': foo
        },
                       window_mapping=dict(bar='my', foo='thy'),
                       channel_mapping={'default': 'A'})
        instructions = sequencer.build()
        self.assertFalse(sequencer.has_finished())
        self.assertEqual(1, len(instructions))

        foo = DummyParameter(value=1.1)
        bar = DummyParameter(value=-0.2)
        sequencer = Sequencer()
        sequencer.push(seqt, {
            'foo': foo,
            'hugo': bar
        },
                       window_mapping=dict(bar='my', foo='thy'),
                       channel_mapping={'default': 'A'})
        instructions = sequencer.build()
        self.assertTrue(sequencer.has_finished())
        self.assertEqual(4, len(instructions.instructions))

        self.assertEqual(instructions[0], MEASInstruction([('my', 2, 2)]))
        self.assertIsInstance(instructions[1], EXECInstruction)
        self.assertEqual(instructions[2], MEASInstruction([('thy', 4, 1)]))
        self.assertIsInstance(instructions[3], EXECInstruction)
Beispiel #24
0
 def test_build_path_no_loop_nothing_to_do(self) -> None:
     sequencer = Sequencer()
     
     sequencer.build()
     self.assertTrue(sequencer.has_finished())
Beispiel #25
0
def exec_test():
    import time
    import numpy as np

    t = []
    names = []

    def tic(name):
        t.append(time.time())
        names.append(name)

    from qupulse.hardware.awgs.tabor import TaborChannelPair, TaborAWGRepresentation
    tawg = TaborAWGRepresentation(r'USB0::0x168C::0x2184::0000216488::INSTR', reset=True)

    tchannelpair = TaborChannelPair(tawg, (1, 2), 'TABOR_AB')
    tawg.paranoia_level = 2

    # warnings.simplefilter('error', Warning)

    from qupulse.hardware.setup import HardwareSetup, PlaybackChannel, MarkerChannel
    hardware_setup = HardwareSetup()

    hardware_setup.set_channel('TABOR_A', PlaybackChannel(tchannelpair, 0))
    hardware_setup.set_channel('TABOR_B', PlaybackChannel(tchannelpair, 1))
    hardware_setup.set_channel('TABOR_A_MARKER', MarkerChannel(tchannelpair, 0))
    hardware_setup.set_channel('TABOR_B_MARKER', MarkerChannel(tchannelpair, 1))

    if with_alazar:
        from qupulse.hardware.dacs.alazar import AlazarCard
        import atsaverage.server

        if not atsaverage.server.Server.default_instance.running:
            atsaverage.server.Server.default_instance.start(key=b'guest')

        import atsaverage.core

        alazar = AlazarCard(atsaverage.core.getLocalCard(1, 1))
        alazar.register_mask_for_channel('A', 0)
        alazar.config = get_alazar_config()

        alazar.register_operations('test', get_operations())

        window = get_window(atsaverage.core.getLocalCard(1, 1))

        hardware_setup.register_dac(alazar)

    repeated = get_pulse()

    from qupulse.pulses.sequencing import Sequencer

    tic('init')
    sequencer = Sequencer()
    sequencer.push(repeated,
                   parameters=dict(n=10000, tau=1920, U=0.5),
                   channel_mapping={'out': 'TABOR_A', 'trigger': 'TABOR_A_MARKER'},
                   window_mapping=dict(A='A'))
    instruction_block = sequencer.build()

    tic('sequence')

    hardware_setup.register_program('test', instruction_block)

    tic('register')

    if with_alazar:
        from atsaverage.masks import PeriodicMask
        m = PeriodicMask()
        m.identifier = 'D'
        m.begin = 0
        m.end = 1
        m.period = 1
        m.channel = 0
        alazar._registered_programs['test'].masks.append(m)

    tic('per_mask')

    hardware_setup.arm_program('test')

    tic('arm')

    for d, name in zip(np.diff(np.asarray(t)), names[1:]):
        print(name, d)

    d = 1