Beispiel #1
0
    def test_gaussian(self):
        """Test gaussian pulse."""
        amp = 0.5
        duration = 20
        center = duration / 2
        sigma = 2
        times, dt = np.linspace(0, duration, 1001, retstep=True)
        gaussian_arr = continuous.gaussian(times, amp, center, sigma)
        gaussian_arr_zeroed = continuous.gaussian(
            np.array([-1, center, duration + 1]),
            amp,
            center,
            sigma,
            zeroed_width=2 * (center + 1),
            rescale_amp=True,
        )

        self.assertEqual(gaussian_arr.dtype, np.complex_)

        center_time = np.argmax(gaussian_arr)
        self.assertAlmostEqual(times[center_time], center)
        self.assertAlmostEqual(gaussian_arr[center_time], amp)
        self.assertAlmostEqual(gaussian_arr_zeroed[0], 0.0, places=6)
        self.assertAlmostEqual(gaussian_arr_zeroed[1], amp)
        self.assertAlmostEqual(gaussian_arr_zeroed[2], 0.0, places=6)
        self.assertAlmostEqual(
            np.sum(gaussian_arr * dt), amp * np.sqrt(2 * np.pi * sigma**2), places=3
        )
    def test_drag(self):
        """Test drag pulse."""
        amp = 0.5
        center = 10
        sigma = 0.1
        beta = 0
        times = np.linspace(0, 20, 2001)
        # test that we recover gaussian for beta=0
        gaussian_arr = continuous.gaussian(times,
                                           amp,
                                           center,
                                           sigma,
                                           zeroed_width=2 * (center + 1),
                                           rescale_amp=True)

        drag_arr = continuous.drag(times,
                                   amp,
                                   center,
                                   sigma,
                                   beta=beta,
                                   zeroed_width=2 * (center + 1),
                                   rescale_amp=True)

        self.assertEqual(drag_arr.dtype, np.complex_)

        np.testing.assert_equal(drag_arr, gaussian_arr)
Beispiel #3
0
 def test_gaussian(self):
     """Test gaussian pulse."""
     amp = 0.5
     sigma = 2
     duration = 10
     center = duration/2
     times = np.arange(0, duration) + 0.5
     gaussian_ref = continuous.gaussian(times, amp, center, sigma,
                                        zeroed_width=2*(center+1), rescale_amp=True)
     gaussian_pulse = library.gaussian(duration, amp, sigma)
     self.assertIsInstance(gaussian_pulse, Waveform)
     np.testing.assert_array_almost_equal(gaussian_pulse.samples, gaussian_ref)