示例#1
0
    def test_loop_to_seqc_len_1(self):
        """Test the translation of loops with len(loop) == 1"""
        loop = Loop(children=[Loop()])
        waveform_to_bin = mock.Mock(wraps=make_binary_waveform)
        loop_to_seqc_kwargs = dict(min_repetitions_for_for_loop=2,
                                   min_repetitions_for_shared_wf=3,
                                   waveform_to_bin=waveform_to_bin)

        expected = 'asdf'
        with mock.patch('qupulse._program.seqc.loop_to_seqc',
                        return_value=expected) as mocked_loop_to_seqc:
            result = loop_to_seqc(loop, **loop_to_seqc_kwargs)
            self.assertEqual(result, expected)
            mocked_loop_to_seqc.assert_called_once_with(
                loop[0], **loop_to_seqc_kwargs)

        loop.repetition_count = 14
        expected = Repeat(14, 'asdfg')
        with mock.patch('qupulse._program.seqc.loop_to_seqc',
                        return_value=expected.scope) as mocked_loop_to_seqc:
            result = loop_to_seqc(loop, **loop_to_seqc_kwargs)
            self.assertEqual(result, expected)
            mocked_loop_to_seqc.assert_called_once_with(
                loop[0], **loop_to_seqc_kwargs)

        waveform_to_bin.assert_not_called()
示例#2
0
    def test_loop_to_seqc_leaf(self):
        """Test the translation of leaves"""
        # we use None because it is not used in this test
        user_registers = None

        wf = DummyWaveform(duration=32)
        loop = Loop(waveform=wf)

        # with wrapping repetition
        loop.repetition_count = 15
        waveform_to_bin = mock.Mock(wraps=make_binary_waveform)
        expected = Repeat(loop.repetition_count,
                          WaveformPlayback(waveform=make_binary_waveform(wf)))
        result = loop_to_seqc(loop,
                              1,
                              1,
                              waveform_to_bin,
                              user_registers=user_registers)
        waveform_to_bin.assert_called_once_with(wf)
        self.assertEqual(expected, result)

        # without wrapping repetition
        loop.repetition_count = 1
        waveform_to_bin = mock.Mock(wraps=make_binary_waveform)
        expected = WaveformPlayback(waveform=make_binary_waveform(wf))
        result = loop_to_seqc(loop,
                              1,
                              1,
                              waveform_to_bin,
                              user_registers=user_registers)
        waveform_to_bin.assert_called_once_with(wf)
        self.assertEqual(expected, result)
示例#3
0
    def test_loop_to_seqc_cluster_handling(self):
        """Test handling of clusters"""
        with self.assertRaises(AssertionError):
            loop_to_seqc(Loop(repetition_count=12, children=[Loop()]),
                         min_repetitions_for_for_loop=3,
                         min_repetitions_for_shared_wf=2,
                         waveform_to_bin=make_binary_waveform)

        loop_to_seqc_kwargs = dict(min_repetitions_for_for_loop=3,
                                   min_repetitions_for_shared_wf=4,
                                   waveform_to_bin=make_binary_waveform)

        wf_same = map(WaveformPlayback,
                      map(make_binary_waveform, get_unique_wfs(100000, 32)))
        wf_sep, = map(WaveformPlayback,
                      map(make_binary_waveform, get_unique_wfs(1, 64)))

        node_clusters = [
            take(2, wf_same), [wf_sep],
            take(3, wf_same), [wf_sep],
            take(4, wf_same),
            take(4, wf_same)
        ]
        root = Loop(
            repetition_count=12,
            children=[Loop() for _ in range(2 + 1 + 3 + 1 + 4 + 1 + 4)])

        expected = Repeat(
            12,
            Scope([
                *node_clusters[0], wf_sep,
                SteppingRepeat(node_clusters[2]), wf_sep,
                SteppingRepeat(node_clusters[4]),
                SteppingRepeat(node_clusters[5])
            ]))

        def dummy_find_sharable_waveforms(cluster):
            if cluster is node_clusters[4]:
                return [True]
            else:
                return None

        p1 = mock.patch('qupulse._program.seqc.to_node_clusters',
                        return_value=node_clusters)
        p2 = mock.patch('qupulse._program.seqc.find_sharable_waveforms',
                        wraps=dummy_find_sharable_waveforms)
        p3 = mock.patch('qupulse._program.seqc.mark_sharable_waveforms')

        with p1 as to_node_clusters_mock, p2 as find_share_mock, p3 as mark_share_mock:
            result = loop_to_seqc(root, **loop_to_seqc_kwargs)
            self.assertEqual(expected, result)

            to_node_clusters_mock.assert_called_once_with(
                root, loop_to_seqc_kwargs)
            self.assertEqual(
                find_share_mock.mock_calls,
                [mock.call(node_clusters[4]),
                 mock.call(node_clusters[5])])
            mark_share_mock.assert_called_once_with(node_clusters[4], [True])
示例#4
0
    def test_program_translation(self):
        """Integration test"""
        unique_wfs = get_unique_wfs()
        same_wf = DummyWaveform(duration=32, sample_output=np.ones(32))
        root = complex_program_as_loop(unique_wfs, wf_same=same_wf)

        t0 = time.perf_counter()

        seqc = loop_to_seqc(root, 50, 100, make_binary_waveform)

        t1 = time.perf_counter()
        print('took', t1 - t0, 's')

        expected = complex_program_as_seqc(unique_wfs, wf_same=same_wf)
        self.assertEqual(expected, seqc)