本文整理汇总了Python中qctoolkit.pulses.table_pulse_template.TablePulseTemplate.get_serialization_data方法的典型用法代码示例。如果您正苦于以下问题:Python TablePulseTemplate.get_serialization_data方法的具体用法?Python TablePulseTemplate.get_serialization_data怎么用?Python TablePulseTemplate.get_serialization_data使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类qctoolkit.pulses.table_pulse_template.TablePulseTemplate
的用法示例。
在下文中一共展示了TablePulseTemplate.get_serialization_data方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: TablePulseTemplateSerializationTests
# 需要导入模块: from qctoolkit.pulses.table_pulse_template import TablePulseTemplate [as 别名]
# 或者: from qctoolkit.pulses.table_pulse_template.TablePulseTemplate import get_serialization_data [as 别名]
class TablePulseTemplateSerializationTests(unittest.TestCase):
def setUp(self) -> None:
self.serializer = DummySerializer(lambda x: dict(name=x.name), lambda x: x.name, lambda x: x['name'])
self.template = TablePulseTemplate(measurement=True, identifier='foo')
self.expected_data = dict(type=self.serializer.get_type_identifier(self.template))
def test_get_serialization_data(self) -> None:
self.template.add_entry('foo', 2)
self.template.add_entry('hugo', 'ilse', interpolation='linear')
self.expected_data['is_measurement_pulse'] = True
self.expected_data['time_parameter_declarations'] = [dict(name='foo'), dict(name='hugo')]
self.expected_data['voltage_parameter_declarations'] = [dict(name='ilse')]
self.expected_data['entries'] = [(0, 0, 'hold'), ('foo', 2, 'hold'), ('hugo', 'ilse', 'linear')]
self.assertEqual(self.expected_data, self.template.get_serialization_data(self.serializer))
def test_deserialize(self) -> None:
data = dict(is_measurement_pulse=True,
time_parameter_declarations=[dict(name='hugo'), dict(name='foo')],
voltage_parameter_declarations=[dict(name='ilse')],
entries=[(0, 0, 'hold'), ('foo', 2, 'hold'), ('hugo', 'ilse', 'linear')],
identifier='foo')
# prepare dependencies for deserialization
self.serializer.subelements['foo'] = ParameterDeclaration('foo')
self.serializer.subelements['hugo'] = ParameterDeclaration('hugo')
self.serializer.subelements['ilse'] = ParameterDeclaration('ilse')
# deserialize
template = TablePulseTemplate.deserialize(self.serializer, **data)
# prepare expected parameter declarations
self.serializer.subelements['foo'].min_value = 0
self.serializer.subelements['foo'].max_value = self.serializer.subelements['hugo']
all_declarations = set(self.serializer.subelements.values())
# prepare expected entries
entries = [(0, 0, HoldInterpolationStrategy()),
(self.serializer.subelements['foo'], 2, HoldInterpolationStrategy()),
(self.serializer.subelements['hugo'], self.serializer.subelements['ilse'], LinearInterpolationStrategy())]
# compare!
self.assertEqual(all_declarations, template.parameter_declarations)
self.assertEqual({'foo', 'hugo', 'ilse'}, template.parameter_names)
self.assertEqual(entries, template.entries)
self.assertEqual('foo', template.identifier)