Ejemplo n.º 1
0
    def test_issue_584_uninitialized_table_sample(self):
        """issue 584"""
        d = 598.3333333333334 - 480
        tpt = TablePulseTemplate(
            entries={'P': [(0, 1.0, 'hold'), (d, 1.0, 'hold')]})
        with mock.patch('qupulse._program.waveforms.PULSE_TO_WAVEFORM_ERROR',
                        1e-6):
            wf = to_waveform(tpt.create_program())
            self.assertTrue(isclose(d, wf.duration, abs_tol=1e-6))

            start_time = 0.
            end_time = wf.duration
            sample_rate = 3.

            sample_count = (end_time - start_time) * sample_rate + 1

            times = np.linspace(float(start_time),
                                float(wf.duration),
                                num=int(sample_count),
                                dtype=float)
            times[-1] = np.nextafter(times[-1], times[-2])

            out = np.full_like(times, fill_value=np.nan)
            sampled = wf.get_sampled(channel='P',
                                     sample_times=times,
                                     output_array=out)

            expected = np.full_like(times, fill_value=1.)
            np.testing.assert_array_equal(expected, sampled)
Ejemplo n.º 2
0
    def test_bug_422_mock(self):
        pt = TablePulseTemplate({'X': [(0, 1), (100, 1)]})
        program = pt.create_program()

        mock_program = mock.Mock(spec=dir(program))

        for attr in dir(Loop):
            if not attr.endswith('_'):
                setattr(mock_program, attr, getattr(program, attr))
        mock_program.__len__ = lambda x: 1
        mock_program.__iter__ = lambda x: iter(program)
        mock_program.__getitem__ = lambda x, idx: program[idx]

        self.assertNotIsInstance(mock_program, Loop)

        render(mock_program, sample_rate=1)