Ejemplo n.º 1
0
 def test_gauss_square_extremes(self):
     """Test that the gaussian square pulse can build a gaussian."""
     duration = 125
     sigma = 4
     amp = 0.5j
     gaus_square = GaussianSquare(duration=duration, sigma=sigma, amp=amp, width=0)
     gaus = Gaussian(duration=duration, sigma=sigma, amp=amp)
     np.testing.assert_almost_equal(gaus_square.get_sample_pulse().samples,
                                    gaus.get_sample_pulse().samples)
     gaus_square = GaussianSquare(duration=duration, sigma=sigma, amp=amp, width=121)
     const = ConstantPulse(duration=duration, amp=amp)
     np.testing.assert_almost_equal(gaus_square.get_sample_pulse().samples[2:-2],
                                    const.get_sample_pulse().samples[2:-2])
Ejemplo n.º 2
0
 def test_parameters(self):
     """Test that the parameters can be extracted as a dict through the `parameters`
     attribute."""
     drag = Drag(duration=25, amp=0.2 + 0.3j, sigma=7.8, beta=4)
     self.assertEqual(set(drag.parameters.keys()), {'duration', 'amp', 'sigma', 'beta'})
     const = ConstantPulse(duration=150, amp=1)
     self.assertEqual(set(const.parameters.keys()), {'duration', 'amp'})
Ejemplo n.º 3
0
 def test_repr(self):
     """Test the repr methods for parametric pulses."""
     gaus = Gaussian(duration=25, amp=0.7, sigma=4)
     self.assertEqual(repr(gaus), 'Gaussian(duration=25, amp=(0.7+0j), sigma=4)')
     gaus_square = GaussianSquare(duration=20, sigma=30, amp=1.0, width=3)
     self.assertEqual(repr(gaus_square),
                      'GaussianSquare(duration=20, amp=(1+0j), sigma=30, width=3)')
     drag = Drag(duration=5, amp=0.5, sigma=7, beta=1)
     self.assertEqual(repr(drag), 'Drag(duration=5, amp=(0.5+0j), sigma=7, beta=1)')
     const = ConstantPulse(duration=150, amp=0.1 + 0.4j)
     self.assertEqual(repr(const), 'ConstantPulse(duration=150, amp=(0.1+0.4j))')
Ejemplo n.º 4
0
 def test_param_validation(self):
     """Test that parametric pulse parameters are validated when initialized."""
     with self.assertRaises(PulseError):
         Gaussian(duration=25, sigma=0, amp=0.5j)
     with self.assertRaises(PulseError):
         GaussianSquare(duration=150, amp=0.2, sigma=8, width=160)
     with self.assertRaises(PulseError):
         ConstantPulse(duration=150, amp=0.9 + 0.8j)
     with self.assertRaises(PulseError):
         Drag(duration=25, amp=0.2 + 0.3j, sigma=-7.8, beta=4)
     with self.assertRaises(PulseError):
         Drag(duration=25, amp=0.2 + 0.3j, sigma=7.8, beta=4j)
Ejemplo n.º 5
0
 def test_construction(self):
     """Test that parametric pulses can be constructed without error."""
     Gaussian(duration=25, sigma=4, amp=0.5j)
     GaussianSquare(duration=150, amp=0.2, sigma=8, width=140)
     ConstantPulse(duration=150, amp=0.1 + 0.4j)
     Drag(duration=25, amp=0.2 + 0.3j, sigma=7.8, beta=4)
Ejemplo n.º 6
0
 def test_complex_param_is_complex(self):
     """Check that complex param 'amp' is cast to complex."""
     const = ConstantPulse(duration=150, amp=1)
     self.assertIsInstance(const.amp, complex)
Ejemplo n.º 7
0
 def test_constant_samples(self):
     """Test the constant pulse and its sampled construction."""
     const = ConstantPulse(duration=150, amp=0.1 + 0.4j)
     self.assertEqual(const.get_sample_pulse().samples[0], 0.1 + 0.4j)
     self.assertEqual(len(const.get_sample_pulse().samples), 150)
Ejemplo n.º 8
0
 def test_deprecated_parametric_pulses(self):
     """Test deprecated parametric pulses."""
     with self.assertWarns(DeprecationWarning):
         const = ConstantPulse(duration=150, amp=0.1 + 0.4j)
         self.assertEqual(const.get_sample_pulse().samples[0], 0.1 + 0.4j)
         self.assertEqual(len(const.get_sample_pulse().samples), 150)