Skip to content

Commit

Permalink
Serializers deprecation (quantumlib#5589)
Browse files Browse the repository at this point in the history
This PR deprecates all serializers we plan to deprecate
* Deprecated GateOpSerializer, GateOpDeserializer, DeserializingArg, and SerializingArg using the class wrapper technique. 
* CircuitSerializer and serializer classes it depends on (`CircuitOp[De]Serializer`, `Serializer`) are left in place.
* Skipping deprecation of common serializers in `common_serializers.py` for now and remove them directly after the 0.15 release as it's very unlikely for users to access them directly. Most users interact with them via global gatesets, e.g.

https://github.com/quantumlib/Cirq/blob/abfc619bfe31e93573993c76cecfddc5689dea9b/cirq-google/cirq_google/serialization/gate_sets.py#L43-L64

But if time allows, I'll try to deprecate common serializers as well.

* Added mentions of serializer deprecations in global gateset deprecation warnings.

@dstrain115
  • Loading branch information
verult authored and rht committed May 1, 2023
1 parent 6258596 commit be26afc
Show file tree
Hide file tree
Showing 10 changed files with 862 additions and 443 deletions.
62 changes: 17 additions & 45 deletions cirq-google/cirq_google/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -160,53 +160,25 @@

_register_resolver(_class_resolver_dictionary)


_SERIALIZABLE_GATESET_DEPRECATION_MESSAGE = (
'SerializableGateSet and associated classes (GateOpSerializer, GateOpDeserializer,'
' SerializingArgs, DeserializingArgs) will no longer be supported.'
' In cirq_google.GridDevice, the new representation of Google devices, the gateset of a device'
' is represented as a cirq.Gateset and is available as'
' GridDevice.metadata.gateset.'
' Engine methods no longer require gate sets to be passed in.'
' In addition, circuit serialization is replaced by cirq_google.CircuitSerializer.'
)


_compat.deprecate_attributes(
__name__,
{
'XMON': (
'v0.16',
'SerializableGateSet will no longer be supported.'
' In cirq_google.GridDevice, the new representation of Google devices, the gateset of '
' a device is represented as a cirq.Gateset and is available as'
' GridDevice.metadata.gateset.'
' Engine methods no longer require gate sets to be passed in.'
' In addition, circuit serialization is replaced by cirq_google.CircuitSerializer.',
),
'FSIM_GATESET': (
'v0.16',
'SerializableGateSet will no longer be supported.'
' In cirq_google.GridDevice, the new representation of Google devices, the gateset of '
' a device is represented as a cirq.Gateset and is available as'
' GridDevice.metadata.gateset.'
' Engine methods no longer require gate sets to be passed in.'
' In addition, circuit serialization is replaced by cirq_google.CircuitSerializer.',
),
'SQRT_ISWAP_GATESET': (
'v0.16',
'SerializableGateSet will no longer be supported.'
' In cirq_google.GridDevice, the new representation of Google devices, the gateset of '
' a device is represented as a cirq.Gateset and is available as'
' GridDevice.metadata.gateset.'
' Engine methods no longer require gate sets to be passed in.'
' In addition, circuit serialization is replaced by cirq_google.CircuitSerializer.',
),
'SYC_GATESET': (
'v0.16',
'SerializableGateSet will no longer be supported.'
' In cirq_google.GridDevice, the new representation of Google devices, the gateset of '
' a device is represented as a cirq.Gateset and is available as'
' GridDevice.metadata.gateset.'
' Engine methods no longer require gate sets to be passed in.'
' In addition, circuit serialization is replaced by cirq_google.CircuitSerializer.',
),
'NAMED_GATESETS': (
'v0.16',
'SerializableGateSet will no longer be supported.'
' In cirq_google.GridDevice, the new representation of Google devices, the gateset of '
' a device is represented as a cirq.Gateset and is available as'
' GridDevice.metadata.gateset.'
' Engine methods no longer require gate sets to be passed in.'
' In addition, circuit serialization is replaced by cirq_google.CircuitSerializer.',
),
'XMON': ('v0.16', _SERIALIZABLE_GATESET_DEPRECATION_MESSAGE),
'FSIM_GATESET': ('v0.16', _SERIALIZABLE_GATESET_DEPRECATION_MESSAGE),
'SQRT_ISWAP_GATESET': ('v0.16', _SERIALIZABLE_GATESET_DEPRECATION_MESSAGE),
'SYC_GATESET': ('v0.16', _SERIALIZABLE_GATESET_DEPRECATION_MESSAGE),
'NAMED_GATESETS': ('v0.16', _SERIALIZABLE_GATESET_DEPRECATION_MESSAGE),
},
)
2 changes: 1 addition & 1 deletion cirq-google/cirq_google/devices/known_devices.py
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ def create_device_proto_for_qubits(
gate = gs_proto.valid_gates.add()
gate.id = gate_id

if not isinstance(serializer, op_serializer.GateOpSerializer):
if not isinstance(serializer, op_serializer._GateOpSerializer):
# This implies that 'serializer' handles non-gate ops,
# such as CircuitOperations. No other properties apply.
continue
Expand Down
12 changes: 10 additions & 2 deletions cirq-google/cirq_google/devices/serializable_device_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,11 @@


def _just_cz():
with cirq.testing.assert_deprecated('SerializableGateSet', deadline='v0.16', count=None):
# Deprecations: cirq_google.SerializableGateSet, cirq_google.GateOpSerializer, and
# cirq_google.GateOpDeserializer
with cirq.testing.assert_deprecated(
'SerializableGateSet', 'CircuitSerializer', deadline='v0.16', count=None
):
return cg.SerializableGateSet(
gate_set_name='cz_gate_set',
serializers=[
Expand All @@ -42,7 +46,11 @@ def _just_cz():


def _just_meas():
with cirq.testing.assert_deprecated('SerializableGateSet', deadline='v0.16', count=None):
# Deprecations: cirq_google.SerializableGateSet, cirq_google.GateOpSerializer, and
# cirq_google.GateOpDeserializer
with cirq.testing.assert_deprecated(
'SerializableGateSet', 'CircuitSerializer', deadline='v0.16', count=None
):
return cg.SerializableGateSet(
gate_set_name='meas_gate_set',
serializers=[
Expand Down
Loading

0 comments on commit be26afc

Please sign in to comment.