Exemplo n.º 1
0
    def test_init(self):
        prog = MultiChannelProgram(MultiChannelTests().root_block)
        TaborProgram(prog['A'], self.instr_props, ('A', None), (None, None))

        with self.assertRaises(KeyError):
            TaborProgram(prog['A'], self.instr_props, ('A', 'B'), (None, None))

        with self.assertRaises(TaborException):
            TaborProgram(prog['A'], self.instr_props, ('A', 'B'),
                         (None, None, None))
        with self.assertRaises(TaborException):
            TaborProgram(prog['A'], self.instr_props, ('A', 'B', 'C'),
                         (None, None))
Exemplo n.º 2
0
    def test_advanced_sequence_exceptions(self):
        temp_properties = self.instr_props.copy()
        temp_properties['max_seq_len'] = 5

        program = Loop(children=[
            Loop(waveform=DummyWaveform(defined_channels={'A'}),
                 repetition_count=1)
            for _ in range(temp_properties['max_seq_len'] + 1)
        ],
                       repetition_count=2)
        with self.assertRaises(TaborException):
            TaborProgram(program.copy_tree_structure(),
                         channels=(None, 'A'),
                         markers=(None, None),
                         device_properties=temp_properties)

        temp_properties['min_seq_len'] = 100
        temp_properties['max_seq_len'] = 120
        with self.assertRaises(TaborException) as exception:
            TaborProgram(program.copy_tree_structure(),
                         channels=(None, 'A'),
                         markers=(None, None),
                         device_properties=temp_properties)
        self.assertEqual(
            str(exception.exception), 'The algorithm is not smart enough '
            'to make this sequence table longer')

        program = Loop(children=[
            Loop(children=[
                Loop(waveform=DummyWaveform(defined_channels={'A'})),
                Loop(waveform=DummyWaveform(defined_channels={'A'}))
            ]),
            Loop(children=[
                Loop(waveform=DummyWaveform(defined_channels={'A'})),
                Loop(waveform=DummyWaveform(defined_channels={'A'}))
            ])
        ])
        with self.assertRaises(TaborException) as exception:
            TaborProgram(program.copy_tree_structure(),
                         channels=(None, 'A'),
                         markers=(None, None),
                         device_properties=temp_properties)
        self.assertEqual(
            str(exception.exception), 'The algorithm is not smart enough '
            'to make this sequence table longer')
Exemplo n.º 3
0
    def test_depth_0_single_waveform(self):
        program = Loop(waveform=DummyWaveform(defined_channels={'A'}),
                       repetition_count=3)

        t_program = TaborProgram(program,
                                 channels=(None, 'A'),
                                 markers=(None, None),
                                 device_properties=self.instr_props)

        self.assertEqual(t_program.waveform_mode, TaborSequencing.SINGLE)

        self.assertEqual(t_program.get_sequencer_tables(), [[(3, 0, 0)]])
        self.assertEqual(t_program.get_advanced_sequencer_table(), [(1, 1, 0)])
Exemplo n.º 4
0
    def test_upload_offset_handling(self):

        program = self.Loop(
            waveform=self.TableWaveform(1, [(
                0, 0.1, self.HoldInterpolationStrategy()
            ), (192, 0.1, self.HoldInterpolationStrategy())]))

        channel_pair = self.TaborChannelPair(self.instrument,
                                             identifier='asd',
                                             channels=(1, 2))

        channels = (1, None)
        markers = (None, None)

        tabor_program = TaborProgram(
            program,
            channels=channels,
            markers=markers,
            device_properties=channel_pair.device.dev_properties)

        test_sample_rate = channel_pair.sample_rate
        test_amplitudes = (
            channel_pair.device.amplitude(channel_pair._channels[0]) / 2,
            channel_pair.device.amplitude(channel_pair._channels[1]) / 2)
        test_offset = 0.1
        test_transform = (lambda x: x, lambda x: x)

        with patch('qupulse.hardware.awgs.tabor.TaborProgram', return_value=tabor_program) as tabor_program_mock, \
             patch.object(tabor_program, 'sampled_segments', wraps=tabor_program.sampled_segments) as sampled_segments_mock, \
             patch.object(channel_pair.device, 'offset', return_value=test_offset):

            channel_pair.amplitude_offset_handling = AWGAmplitudeOffsetHandling.CONSIDER_OFFSET
            channel_pair.upload('test1', program, (1, None), (None, None),
                                test_transform)

            sampled_segments_mock.assert_called_once_with(
                sample_rate=test_sample_rate,
                voltage_amplitude=test_amplitudes,
                voltage_offset=(test_offset, test_offset),
                voltage_transformation=test_transform)

            channel_pair.amplitude_offset_handling = AWGAmplitudeOffsetHandling.IGNORE_OFFSET
            channel_pair.upload('test2', program, (1, None), (None, None),
                                test_transform)

            sampled_segments_mock.assert_called_with(
                sample_rate=test_sample_rate,
                voltage_amplitude=test_amplitudes,
                voltage_offset=(0, 0),
                voltage_transformation=test_transform)
Exemplo n.º 5
0
    def test_depth_1_advanced_sequence_unroll(self):
        wf_1 = DummyWaveform(defined_channels={'A'})
        wf_2 = DummyWaveform(defined_channels={'A'})

        program = Loop(children=[
            Loop(waveform=wf_1, repetition_count=3),
            Loop(waveform=wf_2, repetition_count=4)
        ],
                       repetition_count=5)

        t_program = TaborProgram(program,
                                 channels=(None, 'A'),
                                 markers=(None, None),
                                 device_properties=self.instr_props)

        self.assertEqual(t_program.waveform_mode, TaborSequencing.ADVANCED)

        # partial unroll of the last segment
        self.assertEqual(t_program.get_sequencer_tables(), [[(3, 0, 0),
                                                             (3, 1, 0),
                                                             (1, 1, 0)]])
        self.assertEqual(t_program.get_advanced_sequencer_table(), [(5, 1, 0)])
Exemplo n.º 6
0
    def test_depth_1_single_sequence_2(self):
        """Use the same wf twice"""
        wf_1 = DummyWaveform(defined_channels={'A'})
        wf_2 = DummyWaveform(defined_channels={'A'})

        program = Loop(children=[
            Loop(waveform=wf_1, repetition_count=3),
            Loop(waveform=wf_2, repetition_count=4),
            Loop(waveform=wf_1, repetition_count=1)
        ],
                       repetition_count=1)

        t_program = TaborProgram(program,
                                 channels=(None, 'A'),
                                 markers=(None, None),
                                 device_properties=self.instr_props)

        self.assertEqual(t_program.waveform_mode, TaborSequencing.SINGLE)

        self.assertEqual(t_program.get_sequencer_tables(), [[(3, 0, 0),
                                                             (4, 1, 0),
                                                             (1, 0, 0)]])
        self.assertEqual(t_program.get_advanced_sequencer_table(), [(1, 1, 0)])
Exemplo n.º 7
0
    def test_sampled_segments(self):
        def my_gen(gen):
            alternating_on_off = itertools.cycle((np.ones(192), np.zeros(192)))
            chan_gen = gen
            while True:
                for _ in range(2):
                    yield next(chan_gen)
                yield next(alternating_on_off)[::2]
                yield np.zeros(192)[::2]

        sample_rate = 10**9
        with self.assertRaises(TaborException):
            root_loop = LoopTests.get_test_loop(
                WaveformGenerator(waveform_data_generator=my_gen(
                    self.waveform_data_generator),
                                  duration_generator=itertools.repeat(12),
                                  num_channels=4))

            mcp = MultiChannelProgram(InstructionBlock(), tuple())
            mcp.programs[frozenset(('A', 'B', 'C', 'D'))] = root_loop
            TaborProgram(root_loop, self.instr_props, ('A', 'B'),
                         (None, None)).sampled_segments(
                             8000, (1., 1.), (0, 0),
                             (lambda x: x, lambda x: x))

        root_loop = LoopTests.get_test_loop(
            WaveformGenerator(waveform_data_generator=my_gen(
                self.waveform_data_generator),
                              duration_generator=itertools.repeat(192),
                              num_channels=4))

        mcp = MultiChannelProgram(InstructionBlock(), tuple())
        mcp.programs[frozenset(('A', 'B', 'C', 'D'))] = root_loop

        prog = TaborProgram(root_loop, self.instr_props, ('A', 'B'),
                            (None, None))

        sampled, sampled_length = prog.sampled_segments(
            sample_rate, (1., 1.), (0, 0), (lambda x: x, lambda x: x))

        self.assertEqual(len(sampled), 3)

        prog = TaborProgram(root_loop, self.instr_props, ('A', 'B'),
                            ('C', None))
        sampled, sampled_length = prog.sampled_segments(
            sample_rate, (1., 1.), (0, 0), (lambda x: x, lambda x: x))
        self.assertEqual(len(sampled), 6)

        iteroe = my_gen(self.waveform_data_generator)
        for i, sampled_seg in enumerate(sampled):
            data = [next(iteroe) for _ in range(4)]
            data = (voltage_to_uint16(data[0], 1., 0., 14),
                    voltage_to_uint16(data[1], 1., 0., 14), data[2], data[3])
            if i % 2 == 0:
                np.testing.assert_equal(sampled_seg.marker_a,
                                        np.ones(192, dtype=np.uint16)[::2])
            else:
                np.testing.assert_equal(sampled_seg.marker_a,
                                        np.zeros(192, dtype=np.uint16)[::2])
            np.testing.assert_equal(sampled_seg.marker_b,
                                    np.zeros(192, dtype=np.uint16)[::2])

            np.testing.assert_equal(sampled_seg.ch_a, data[0])
            np.testing.assert_equal(sampled_seg.ch_b, data[1])
Exemplo n.º 8
0
 def test_channels(self):
     self.assertEqual(
         TaborProgram(self.root_loop, self.instr_props, ('A', None),
                      (None, 'B')).channels, ('A', None))
Exemplo n.º 9
0
 def test_markers(self):
     self.assertEqual(
         TaborProgram(self.root_loop, self.instr_props, ('A', None),
                      (None, 'B')).markers, (None, 'B'))