Exemplo n.º 1
0
    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)
Exemplo n.º 2
0
    def validate_parameters(self) -> None:
        if abs(self.amp) > 1.:
            raise PulseError("The amplitude norm must be <= 1, "
                             "found: {}".format(abs(self.amp)))
        if self.sigma <= 0:
            raise PulseError("Sigma must be greater than 0.")
        if isinstance(self.beta, complex):
            raise PulseError("Beta must be real.")
        # Check if beta is too large: the amplitude norm must be <=1 for all points
        if self.beta > self.sigma:
            # If beta <= sigma, then the maximum amplitude is at duration / 2, which is
            # already constrainted by self.amp <= 1

            # 1. Find the first maxima associated with the beta * d/dx gaussian term
            #    This eq is derived from solving for the roots of the norm of the drag function.
            #    There is a second maxima mirrored around the center of the pulse with the same
            #    norm as the first, so checking the value at the first x maxima is sufficient.
            argmax_x = (self.duration / 2 - (self.sigma / self.beta) *
                        math.sqrt(self.beta**2 - self.sigma**2))
            if argmax_x < 0:
                # If the max point is out of range, either end of the pulse will do
                argmax_x = 0

            # 2. Find the value at that maximum
            max_val = continuous.drag(np.array(argmax_x),
                                      sigma=self.sigma,
                                      beta=self.beta,
                                      amp=self.amp,
                                      center=self.duration / 2)
            if abs(max_val) > 1.:
                raise PulseError(
                    "Beta is too large; pulse amplitude norm exceeds 1.")
 def test_drag(self):
     """Test discrete sampled drag pulse."""
     amp = 0.5
     sigma = 0.1
     beta = 0
     duration = 10
     center = 10/2
     times = np.arange(0, duration)
     # reference drag pulse
     drag_ref = continuous.drag(times, amp, center, sigma, beta=beta,
                                zeroed_width=2*(center+1), rescale_amp=True)
     drag_pulse = pulse_lib.drag(duration, amp, sigma, beta=beta)
     self.assertIsInstance(drag_pulse, SamplePulse)
     np.testing.assert_array_almost_equal(drag_pulse.samples, drag_ref)