def test_fully_parametrized_pulse(self): """Test instantiating a pulse with parameters.""" amp = Parameter("amp") duration = Parameter("duration") sigma = Parameter("sigma") beta = Parameter("beta") # doesn't raise an error drag = Drag(duration=duration, amp=amp, sigma=sigma, beta=beta) with self.assertRaises(PulseError): drag.get_waveform()
def test_drag_pulse(self): """Test that the Drag sample pulse matches the pulse library.""" drag = Drag(duration=25, sigma=4, amp=0.5j, beta=1) sample_pulse = drag.get_waveform() self.assertIsInstance(sample_pulse, Waveform) pulse_lib_drag = pl_drag(duration=25, sigma=4, amp=0.5j, beta=1, zero_ends=True).samples np.testing.assert_almost_equal(sample_pulse.samples, pulse_lib_drag)
def test_deepcopy(self): """Test deep copying instance.""" import copy drag = Drag(duration=100, amp=0.1, sigma=40, beta=3) drag_copied = copy.deepcopy(drag) self.assertNotEqual(id(drag), id(drag_copied)) orig_wf = drag.get_waveform() copied_wf = drag_copied.get_waveform() np.testing.assert_almost_equal(orig_wf.samples, copied_wf.samples)
def test_drag_validation(self): """Test drag parameter validation, specifically the beta validation.""" duration = 25 sigma = 4 amp = 0.5j beta = 1 wf = Drag(duration=duration, sigma=sigma, amp=amp, beta=beta) samples = wf.get_waveform().samples self.assertTrue(max(np.abs(samples)) <= 1) beta = sigma ** 2 with self.assertRaises(PulseError): wf = Drag(duration=duration, sigma=sigma, amp=amp, beta=beta) # If sigma is high enough, side peaks fall out of range and norm restriction is met sigma = 100 wf = Drag(duration=duration, sigma=sigma, amp=amp, beta=beta)
def test_drag_samples(self): """Test that the drag samples match the formula.""" duration = 25 sigma = 4 amp = 0.5j beta = 1 # formulaic times = np.array(range(25), dtype=np.complex_) times = times - (25 / 2) + 0.5 gauss = amp * np.exp(-(times / sigma)**2 / 2) gauss_deriv = -(times / sigma**2) * gauss drag = gauss + 1j * beta * gauss_deriv # wf wf = Drag(duration=duration, sigma=sigma, amp=amp, beta=beta) samples = wf.get_waveform().samples np.testing.assert_almost_equal(samples, drag)
def check_drag(duration, sigma, amp, beta): wf = Drag(duration=duration, sigma=sigma, amp=amp, beta=beta) samples = wf.get_waveform().samples self.assertTrue(max(np.abs(samples)) <= 1)