當前位置: 首頁>>代碼示例>>Python>>正文


Python TablePulseTemplate.get_serialization_data方法代碼示例

本文整理匯總了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)
開發者ID:carriercomm,項目名稱:qc-toolkit,代碼行數:49,代碼來源:table_pulse_template_tests.py


注:本文中的qctoolkit.pulses.table_pulse_template.TablePulseTemplate.get_serialization_data方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。