Esempio n. 1
0
    def test_deserialize_old(self) -> None:
        # test for deprecated version during transition period, remove after final switch
        with self.assertWarnsRegex(
                DeprecationWarning,
                "deprecated",
                msg=
                "SequencePT does not issue warning for old serialization routines."
        ):
            dummy1 = DummyPulseTemplate()
            dummy2 = DummyPulseTemplate()

            serializer = DummySerializer(
                serialize_callback=lambda x: str(id(x)))

            data = dict(subtemplates=[
                serializer.dictify(dummy1),
                serializer.dictify(dummy2)
            ],
                        identifier='foo',
                        parameter_constraints=['a < b'],
                        measurements=[('m', 0, 1)])

            template = SequencePulseTemplate.deserialize(serializer, **data)
            self.assertEqual(template.subtemplates, [dummy1, dummy2])
            self.assertEqual(template.parameter_constraints,
                             [ParameterConstraint('a<b')])
            self.assertEqual(template.measurement_declarations, [('m', 0, 1)])
Esempio n. 2
0
 def test_get_serialization_data(self) -> None:
     # test for deprecated version during transition period, remove after final switch
     with self.assertWarnsRegex(DeprecationWarning, "deprecated",
                                msg="SequencePT does not issue warning for old serialization routines."):
         dummy_pt = DummyPulseTemplate(defined_channels={'foo'},
                                       measurement_names={'meas'},
                                       parameter_names={'hugo', 'herbert', 'ilse'})
         mpt = MappingPulseTemplate(
             template=dummy_pt,
             parameter_mapping={'hugo': Expression('2*k+c'), 'herbert': Expression('c-1.5'), 'ilse': Expression('ilse')},
             measurement_mapping={'meas': 'seam'},
             channel_mapping={'foo': 'default_channel'},
             parameter_constraints=[str(ParameterConstraint('c > 0'))]
         )
         serializer = DummySerializer()
         expected_data = {
             'template': serializer.dictify(dummy_pt),
             'parameter_mapping': {'hugo': str(Expression('2*k+c')), 'herbert': str(Expression('c-1.5')),
                                   'ilse': str(Expression('ilse'))},
             'measurement_mapping': {'meas': 'seam'},
             'channel_mapping': {'foo': 'default_channel'},
             'parameter_constraints': [str(ParameterConstraint('c > 0'))]
         }
         data = mpt.get_serialization_data(serializer=serializer)
         self.assertEqual(expected_data, data)
    def test_deserialize(self) -> None:
        dummy1 = DummyPulseTemplate()
        dummy2 = DummyPulseTemplate()

        serializer = DummySerializer(serialize_callback=lambda x: str(id(x)))

        data = dict(subtemplates=[
            serializer.dictify(dummy1),
            serializer.dictify(dummy2)
        ],
                    identifier='foo',
                    parameter_constraints=['a<b'])

        template = SequencePulseTemplate.deserialize(serializer, **data)
        self.assertEqual(template.subtemplates, [dummy1, dummy2])
        self.assertEqual(template.parameter_constraints,
                         [ParameterConstraint('a<b')])
    def test_deserialize(self) -> None:
        # test for deprecated version during transition period, remove after final switch
        with self.assertWarnsRegex(
                DeprecationWarning,
                "deprecated",
                msg=
                "SequencePT does not issue warning for old serialization routines."
        ):
            dummy_pt = DummyPulseTemplate(
                defined_channels={'foo'},
                measurement_names={'meas'},
                parameter_names={'hugo', 'herbert', 'ilse'})
            serializer = DummySerializer()
            data = {
                'template': serializer.dictify(dummy_pt),
                'parameter_mapping': {
                    'hugo': str(Expression('2*k+c')),
                    'herbert': str(Expression('c-1.5')),
                    'ilse': str(Expression('ilse'))
                },
                'measurement_mapping': {
                    'meas': 'seam'
                },
                'channel_mapping': {
                    'foo': 'default_channel'
                },
                'parameter_constraints': [str(ParameterConstraint('c > 0'))]
            }
            deserialized = MappingPulseTemplate.deserialize(
                serializer=serializer, **data)

            self.assertIsInstance(deserialized, MappingPulseTemplate)
            self.assertEqual(data['parameter_mapping'],
                             deserialized.parameter_mapping)
            self.assertEqual(data['channel_mapping'],
                             deserialized.channel_mapping)
            self.assertEqual(data['measurement_mapping'],
                             deserialized.measurement_mapping)
            self.assertEqual(
                data['parameter_constraints'],
                [str(pc) for pc in deserialized.parameter_constraints])
            self.assertIs(deserialized.template, dummy_pt)