Skip to content

Commit

Permalink
Merge branch 'master' into issues/287_pt_create_program
Browse files Browse the repository at this point in the history
  • Loading branch information
terrorfisch committed Aug 17, 2018
2 parents f4783d7 + a06b5ff commit 16692fd
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 15 deletions.
6 changes: 6 additions & 0 deletions qctoolkit/pulses/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,12 @@
from qctoolkit.pulses.table_pulse_template import TablePulseTemplate as TablePT
from qctoolkit.pulses.point_pulse_template import PointPulseTemplate as PointPT

import warnings
with warnings.catch_warnings():
warnings.simplefilter('ignore')
# ensure this is included.. it adds a deserialization handler for pulse_template_parameter_mapping.MappingPT which is not present otherwise
import qctoolkit.pulses.pulse_template_parameter_mapping

from qctoolkit.pulses.sequencing import Sequencer

__all__ = ["FunctionPT", "ForLoopPT", "AtomicMultiChannelPT", "MappingPT", "RepetitionPT", "SequencePT", "TablePT",
Expand Down
19 changes: 10 additions & 9 deletions qctoolkit/serialization.py
Original file line number Diff line number Diff line change
Expand Up @@ -367,18 +367,18 @@ def new_default_pulse_registry() -> None:
class Serializable(metaclass=SerializableMeta):
"""Any object that can be converted into a serialized representation for storage and back.
Serializable is the interface used by Serializer to obtain representations of objects that
Serializable is the interface used by PulseStorage to obtain representations of objects that
need to be stored. It essentially provides the methods get_serialization_data, which returns
a dictionary which contains all relevant properties of the Serializable object encoded as
basic Python types, and deserialize, which is able to reconstruct the object from given
such a dictionary.
Additionally, a Serializable object MAY have a unique identifier, which indicates towards
the Serializer that this object should be stored as a separate data item and accessed by
the PulseStorage that this object should be stored as a separate data item and accessed by
reference instead of possibly embedding it into a containing Serializable's representation.
See also:
Serializer
PulseStorage
"""

type_identifier_name = '#type'
Expand Down Expand Up @@ -432,7 +432,7 @@ def get_serialization_data(self, serializer: Optional['Serializer']=None) -> Dic
"""Return all data relevant for serialization as a dictionary containing only base types.
Implementation hint:
In the old serialization routines, if the Serializer contains complex objects which are itself
In the old serialization routines, if the Serializable contains complex objects which are itself
Serializables, a serialized representation for these MUST be obtained by calling the dictify()
method of serializer. The reason is that serializer may decide to either return a dictionary
to embed or only a reference to the Serializable subelement. This is DEPRECATED behavior as of May 2018.
Expand Down Expand Up @@ -472,12 +472,13 @@ def deserialize(cls, serializer: Optional['Serializer']=None, **kwargs) -> 'Seri
For greater clarity, implementations of this method should be precise in their return value,
i.e., give their exact class name, and also replace the **kwargs argument by a list of
arguments required, i.e., those returned by get_serialization_data.
If this Serializable contains complex objects which are itself of type Serializable, their
dictionary representations MUST be converted into objects using serializers deserialize()
method when using the old serialization routines. This is DEPRECATED behavior.
Using the new routines a serializable is only responsible to decode it's own dictionary,
Using old serialization routines, if this Serializable contains complex objects which are itself
of type Serializable, their dictionary representations MUST be converted into objects using
serializers deserialize() method. This is DEPRECATED behavior.
Using the new routines, a serializable is only responsible to decode it's own dictionary,
not those of nested objects (i.e., all incoming arguments are already processed by the
serialization routines). For the transition time where both implementations are
serialization routines).
For the transition time where both variants are
available, implementations of this method should support the old and new routines, using
the presence of the serializer argument to differentiate between both. For the new routines,
just call this base class function.
Expand Down
3 changes: 1 addition & 2 deletions tests/pulses/pulse_template_parameter_mapping_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ def test_pulse_template_parameter_include(self) -> None:
from qctoolkit.pulses.pulse_template_parameter_mapping import MappingPulseTemplate
dummy_t = DummyPulseTemplate()
map_t = MappingPulseTemplate(dummy_t)
serializer = Serializer(DummyStorageBackend())
type_str = serializer.get_type_identifier(map_t)
type_str = map_t.get_type_identifier()
self.assertEqual("qctoolkit.pulses.mapping_pulse_template.MappingPulseTemplate", type_str)

4 changes: 2 additions & 2 deletions tests/pulses/pulse_template_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,8 @@ def parameter_names(self) -> Set[str]:
def get_serialization_data(self, serializer: Optional['Serializer']=None) -> Dict[str, Any]:
raise NotImplementedError()

@staticmethod
def deserialize(serializer: Optional['Serializer']=None, **kwargs) -> 'AtomicPulseTemplateStub':
@classmethod
def deserialize(cls, serializer: Optional['Serializer']=None, **kwargs) -> 'AtomicPulseTemplateStub':
raise NotImplementedError()

@property
Expand Down
4 changes: 2 additions & 2 deletions tests/serialization_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -731,7 +731,7 @@ def test_overwrite(self):
def test_write_through(self):
instance_1 = DummySerializable(identifier='my_id_1', registry=dict())
inner_instance = DummySerializable(identifier='my_id_2', registry=dict())
outer_instance = NestedDummySerializable(inner_instance, identifier='my_id_3', registry=dict())
outer_instance = DummySerializable(inner=inner_instance, identifier='my_id_3', registry=dict())

def get_expected():
return {identifier: serialized
Expand All @@ -745,7 +745,7 @@ def get_expected():
def test_write_through_does_not_overwrite_subpulses(self) -> None:
previous_inner = DummySerializable(identifier='my_id_1', data='hey', registry=dict())
inner_instance = DummySerializable(identifier='my_id_1', data='ho', registry=dict())
outer_instance = NestedDummySerializable(inner_instance, identifier='my_id_2', registry=dict())
outer_instance = DummySerializable(inner=inner_instance, identifier='my_id_2', registry=dict())

self.storage['my_id_1'] = previous_inner
with self.assertRaises(RuntimeError):
Expand Down

0 comments on commit 16692fd

Please sign in to comment.