def test_measurement_windows(self) -> None: pulse = FunctionPulseTemplate(5, 5, measurements=[('mw', 0, 5)]) windows = pulse.get_measurement_windows( parameters={}, measurement_mapping={'mw': 'asd'}) self.assertEqual([('asd', 0, 5)], windows) self.assertEqual(pulse.measurement_declarations, [('mw', 0, 5)])
def test_measurement_windows_with_parameters(self) -> None: pulse = FunctionPulseTemplate(5, 'length', measurements=[('mw', 1, '(1+length)/2')]) parameters = dict(length=100) windows = pulse.get_measurement_windows( parameters, measurement_mapping={'mw': 'asd'}) self.assertEqual(windows, [('asd', 1, 101 / 2)]) declared = pulse.measurement_declarations self.assertEqual(declared, [('mw', 1, '(1+length)/2')])
def test_multiple_measurement_windows(self) -> None: pulse = FunctionPulseTemplate(5, 'length', measurements=[('A', 0, '(1+length)/2'), ('A', 1, 3), ('B', 'begin', 2)]) parameters = dict(length=5, begin=1) measurement_mapping = dict(A='A', B='C') windows = pulse.get_measurement_windows( parameters=parameters, measurement_mapping=measurement_mapping) expected = [('A', 0, 3), ('A', 1, 3), ('C', 1, 2)] self.assertEqual(sorted(windows), sorted(expected)) self.assertEqual(pulse.measurement_declarations, [('A', 0, '(1+length)/2'), ('A', 1, 3), ('B', 'begin', 2)])
class FunctionPulseTest(unittest.TestCase): def setUp(self): self.s = 'a + b' self.s2 = 'c' self.pars = dict(a=1, b=2, c=3) self.fpt = FunctionPulseTemplate(self.s, self.s2) def test_get_pulse_length(self): self.assertEqual(self.fpt.get_pulse_length(self.pars), 3) def test_get_measurement_windows(self): self.assertEqual(self.fpt.get_measurement_windows(self.pars), None) fpt2 = FunctionPulseTemplate(self.s, self.s2, measurement=True) self.assertEqual(fpt2.get_measurement_windows(self.pars), [(0, 3)]) def test_serialization_data(self): expected_data = dict(type='FunctionPulseTemplate', parameter_names=set(['a', 'b', 'c']), duration_expression=self.s2, expression=self.s, measurement=False) self.assertEqual(expected_data, self.fpt.get_serialization_data(DummySerializer()))
def test_no_measurement_windows(self) -> None: pulse = FunctionPulseTemplate(5, 5) windows = pulse.get_measurement_windows({}, {'mw': 'asd'}) self.assertEqual([], windows) self.assertEqual([], pulse.measurement_declarations)
def test_get_measurement_windows(self): self.assertEqual(self.fpt.get_measurement_windows(self.pars), None) fpt2 = FunctionPulseTemplate(self.s, self.s2, measurement=True) self.assertEqual(fpt2.get_measurement_windows(self.pars), [(0, 3)])