diff --git a/cirq-google/cirq_google/devices/known_devices_test.py b/cirq-google/cirq_google/devices/known_devices_test.py index 3dfbf64ccbd..228ee93ef19 100644 --- a/cirq-google/cirq_google/devices/known_devices_test.py +++ b/cirq-google/cirq_google/devices/known_devices_test.py @@ -65,10 +65,14 @@ def test_create_device_proto_for_irregular_grid(): def test_multiple_gate_sets(): # Deprecations: cirq_google.SerializableGateSets class, - # well-known cirq_google SerializableGateSets (e.g. cirq_google.SYC_GATESET), and - # cirq_google.devices.known_devices.create_device_proto_from_diagram + # well-known cirq_google SerializableGateSets (e.g. cirq_google.SYC_GATESET), common serializers + # and cirq_google.devices.known_devices.create_device_proto_from_diagram with cirq.testing.assert_deprecated( - 'SerializableGateSet', 'no longer be available', deadline='v0.16', count=4 + 'SerializableGateSet', + 'CircuitSerializer', + 'no longer be available', + deadline='v0.16', + count=8, ): halfPiGateSet = cirq_google.SerializableGateSet( gate_set_name='half_pi_gateset', @@ -229,7 +233,7 @@ def test_multiple_gate_sets(): def test_sycamore_circuitop_device(): - # Deprecations: cirq_google.SerializableGateSets class, + # Deprecations: cirq_google.SerializableDevice, cirq_google.SerializableGateSets class, # well-known cirq_google SerializableGateSets (e.g. cirq_google.SYC_GATESET), and # cirq_google.devices.known_devices.create_device_proto_from_diagram with cirq.testing.assert_deprecated( @@ -337,14 +341,16 @@ def test_proto_with_circuitop(): def test_proto_with_waitgate(): - # Deprecations: cirq_google.SerializableDevice, cirq_google.SerializableGateSet, and + # Deprecations: cirq_google.SerializableDevice, cirq_google.SerializableGateSet, + # common serializers, and # cirq_google.devices.known_devices.create_device_proto_from_diagram with cirq.testing.assert_deprecated( 'Use cirq_google.GridDevice', 'SerializableGateSet', + 'CircuitSerializer', 'no longer be available', deadline='v0.16', - count=5, + count=7, ): wait_gateset = cirq_google.SerializableGateSet( gate_set_name='wait_gateset', @@ -408,14 +414,16 @@ def test_proto_with_waitgate(): def test_adding_gates_multiple_times(): - # Deprecations: cirq_google.SerializableDevice, cirq_google.SerializableGateSet, and + # Deprecations: cirq_google.SerializableDevice, cirq_google.SerializableGateSet, + # common serializers, and # cirq_google.devices.known_devices.create_device_proto_from_diagram with cirq.testing.assert_deprecated( 'Use cirq_google.GridDevice', 'SerializableGateSet', + 'CircuitSerializer', 'no longer be available', deadline='v0.16', - count=5, + count=11, ): waiting_for_godot = cirq_google.SerializableGateSet( gate_set_name='wait_gateset', diff --git a/cirq-google/cirq_google/devices/serializable_device_test.py b/cirq-google/cirq_google/devices/serializable_device_test.py index e6ec898f0a1..db2c55bcb4c 100644 --- a/cirq-google/cirq_google/devices/serializable_device_test.py +++ b/cirq-google/cirq_google/devices/serializable_device_test.py @@ -395,14 +395,16 @@ def test_mixing_types(): def test_multiple_gatesets(): - # Deprecations: cirq_google.SerializableDevice, cirq_google.SerializableGateSet, and - # cirq_google.devices.known_devices.create_device_proto_from_diagram + # Deprecations: cirq_google.SerializableDevice, cirq_google.SerializableGateSet, + # common serializers, and + # cirq_google.devices.known_devices.create_device_proto_from_diagram, with cirq.testing.assert_deprecated( 'Use cirq_google.GridDevice', 'SerializableGateSet', + 'CircuitSerializer', 'no longer be available', deadline='v0.16', - count=6, + count=10, ): halfPiGateSet = cirq_google.SerializableGateSet( gate_set_name='half_pi_gateset', @@ -437,14 +439,16 @@ def test_half_pi_takes_half_duration(): gate perform correctly. In this case, we set the XPowGate to be half the duration of the full exponent and make sure it still works. """ - # Deprecations: cirq_google.SerializableDevice, cirq_google.SerializableGateSet, and - # cirq_google.devices.known_devices.create_device_proto_from_diagram + # Deprecations: cirq_google.SerializableDevice, cirq_google.SerializableGateSet, + # common serializers, and + # cirq_google.devices.known_devices.create_device_proto_from_diagram, with cirq.testing.assert_deprecated( 'Use cirq_google.GridDevice', 'SerializableGateSet', + 'CircuitSerializer', 'no longer be available', deadline='v0.16', - count=5, + count=7, ): half_pi_gs = cirq_google.SerializableGateSet( gate_set_name='half_pi', @@ -470,14 +474,16 @@ def test_multiple_fsim_gatesets(): gate perform correctly. In this case, we set the XPowGate to be half the duration of the full exponent and make sure it still works. """ - # Deprecations: cirq_google.SerializableDevice, cirq_google.SerializableGateSet, and - # cirq_google.devices.known_devices.create_device_proto_from_diagram + # Deprecations: cirq_google.SerializableDevice, cirq_google.SerializableGateSet, + # common serializers, and + # cirq_google.devices.known_devices.create_device_proto_from_diagram, with cirq.testing.assert_deprecated( 'Use cirq_google.GridDevice', 'SerializableGateSet', + 'CircuitSerializer', 'no longer be available', deadline='v0.16', - count=5, + count=7, ): half_pi_gs = cirq_google.SerializableGateSet( gate_set_name='half_pi', diff --git a/cirq-google/cirq_google/serialization/common_serializers.py b/cirq-google/cirq_google/serialization/common_serializers.py index 1d3b41a5a6a..d6fb6b15075 100644 --- a/cirq-google/cirq_google/serialization/common_serializers.py +++ b/cirq-google/cirq_google/serialization/common_serializers.py @@ -74,7 +74,7 @@ def _convert_physical_z(op: cirq.Operation, proto: v2.program_pb2.Operation): # # Single qubit serializers for arbitrary rotations # -SINGLE_QUBIT_SERIALIZERS = [ +_SINGLE_QUBIT_SERIALIZERS = [ op_serializer._GateOpSerializer( gate_type=cirq.PhasedXPowGate, serialized_gate_id='xy', @@ -186,7 +186,7 @@ def _convert_physical_z(op: cirq.Operation, proto: v2.program_pb2.Operation): # # Single qubit deserializers for arbitrary rotations # -SINGLE_QUBIT_DESERIALIZERS = [ +_SINGLE_QUBIT_DESERIALIZERS = [ op_deserializer._GateOpDeserializer( serialized_gate_id='xy', gate_constructor=cirq.PhasedXPowGate, @@ -252,7 +252,7 @@ def _convert_physical_z(op: cirq.Operation, proto: v2.program_pb2.Operation): # # Measurement Serializer and Deserializer # -MEASUREMENT_SERIALIZER = op_serializer._GateOpSerializer( +_MEASUREMENT_SERIALIZER = op_serializer._GateOpSerializer( gate_type=cirq.MeasurementGate, serialized_gate_id='meas', args=[ @@ -270,7 +270,7 @@ def _convert_physical_z(op: cirq.Operation, proto: v2.program_pb2.Operation): ), ], ) -MEASUREMENT_DESERIALIZER = op_deserializer._GateOpDeserializer( +_MEASUREMENT_DESERIALIZER = op_deserializer._GateOpDeserializer( serialized_gate_id='meas', gate_constructor=cirq.MeasurementGate, args=[ @@ -294,7 +294,7 @@ def _convert_physical_z(op: cirq.Operation, proto: v2.program_pb2.Operation): # # Serializers for single qubit rotations confined to half-pi increments # -SINGLE_QUBIT_HALF_PI_SERIALIZERS = [ +_SINGLE_QUBIT_HALF_PI_SERIALIZERS = [ op_serializer._GateOpSerializer( gate_type=cirq.PhasedXPowGate, serialized_gate_id='xy_pi', @@ -394,7 +394,7 @@ def _convert_physical_z(op: cirq.Operation, proto: v2.program_pb2.Operation): # # Deserializers for single qubit rotations confined to half-pi increments # -SINGLE_QUBIT_HALF_PI_DESERIALIZERS = [ +_SINGLE_QUBIT_HALF_PI_DESERIALIZERS = [ op_deserializer._GateOpDeserializer( serialized_gate_id='xy_pi', gate_constructor=cirq.PhasedXPowGate, @@ -482,7 +482,7 @@ def _add_phase_match(op: cirq.Operation, proto: v2.program_pb2.Operation): ) # CZ to any power -CZ_POW_SERIALIZER = op_serializer._GateOpSerializer( +_CZ_POW_SERIALIZER = op_serializer._GateOpSerializer( gate_type=cirq.CZPowGate, serialized_gate_id='cz', args=[ @@ -496,7 +496,7 @@ def _add_phase_match(op: cirq.Operation, proto: v2.program_pb2.Operation): ], ) -CZ_POW_DESERIALIZER = op_deserializer._GateOpDeserializer( +_CZ_POW_DESERIALIZER = op_deserializer._GateOpDeserializer( serialized_gate_id='cz', gate_constructor=cirq.CZPowGate, args=[ @@ -513,7 +513,7 @@ def _add_phase_match(op: cirq.Operation, proto: v2.program_pb2.Operation): # # Sycamore Gate Serializer and deserializer # -SYC_SERIALIZER = op_serializer._GateOpSerializer( +_SYC_SERIALIZER = op_serializer._GateOpSerializer( gate_type=cirq.FSimGate, serialized_gate_id='syc', args=[_phase_match_arg], @@ -523,7 +523,7 @@ def _add_phase_match(op: cirq.Operation, proto: v2.program_pb2.Operation): ), ) -SYC_DESERIALIZER = op_deserializer._GateOpDeserializer( +_SYC_DESERIALIZER = op_deserializer._GateOpDeserializer( serialized_gate_id='syc', gate_constructor=lambda: cirq.FSimGate(theta=np.pi / 2, phi=np.pi / 6), args=[], @@ -534,7 +534,7 @@ def _add_phase_match(op: cirq.Operation, proto: v2.program_pb2.Operation): # sqrt(ISWAP) serializer and deserializer # (e.g. ISWAP ** 0.5) # -SQRT_ISWAP_SERIALIZERS = [ +_SQRT_ISWAP_SERIALIZERS = [ op_serializer._GateOpSerializer( gate_type=cirq.FSimGate, serialized_gate_id='fsim_pi_4', @@ -571,7 +571,7 @@ def _add_phase_match(op: cirq.Operation, proto: v2.program_pb2.Operation): ), ] -SQRT_ISWAP_DESERIALIZERS = [ +_SQRT_ISWAP_DESERIALIZERS = [ op_deserializer._GateOpDeserializer( serialized_gate_id='fsim_pi_4', gate_constructor=lambda: cirq.FSimGate(theta=np.pi / 4, phi=0), @@ -610,7 +610,7 @@ def _add_phase_match(op: cirq.Operation, proto: v2.program_pb2.Operation): gate_types_to_check=[cirq.ISwapPowGate], allow_symbols=True, ) -LIMITED_FSIM_SERIALIZERS = [ +_LIMITED_FSIM_SERIALIZERS = [ op_serializer._GateOpSerializer( gate_type=cirq.FSimGate, serialized_gate_id='fsim', @@ -677,7 +677,7 @@ def _add_phase_match(op: cirq.Operation, proto: v2.program_pb2.Operation): ] -LIMITED_FSIM_DESERIALIZER = op_deserializer._GateOpDeserializer( +_LIMITED_FSIM_DESERIALIZER = op_deserializer._GateOpDeserializer( serialized_gate_id='fsim', gate_constructor=cirq.FSimGate, args=[ @@ -707,7 +707,7 @@ def _add_phase_match(op: cirq.Operation, proto: v2.program_pb2.Operation): # Coupler Pulse serializer and deserializer # -COUPLER_PULSE_SERIALIZER = op_serializer._GateOpSerializer( +_COUPLER_PULSE_SERIALIZER = op_serializer._GateOpSerializer( gate_type=CouplerPulse, serialized_gate_id='coupler_pulse', args=[ @@ -743,7 +743,7 @@ def _add_phase_match(op: cirq.Operation, proto: v2.program_pb2.Operation): ), ], ) -COUPLER_PULSE_DESERIALIZER = op_deserializer._GateOpDeserializer( +_COUPLER_PULSE_DESERIALIZER = op_deserializer._GateOpDeserializer( serialized_gate_id='coupler_pulse', gate_constructor=CouplerPulse, args=[ @@ -789,7 +789,7 @@ def _add_phase_match(op: cirq.Operation, proto: v2.program_pb2.Operation): # # WaitGate serializer and deserializer # -WAIT_GATE_SERIALIZER = op_serializer._GateOpSerializer( +_WAIT_GATE_SERIALIZER = op_serializer._GateOpSerializer( gate_type=cirq.WaitGate, serialized_gate_id='wait', args=[ @@ -803,7 +803,7 @@ def _add_phase_match(op: cirq.Operation, proto: v2.program_pb2.Operation): ) ], ) -WAIT_GATE_DESERIALIZER = op_deserializer._GateOpDeserializer( +_WAIT_GATE_DESERIALIZER = op_deserializer._GateOpDeserializer( serialized_gate_id='wait', gate_constructor=cirq.WaitGate, args=[ @@ -826,3 +826,127 @@ def _add_phase_match(op: cirq.Operation, proto: v2.program_pb2.Operation): # CIRCUIT_OP_SERIALIZER = op_serializer.CircuitOpSerializer() CIRCUIT_OP_DESERIALIZER = op_deserializer.CircuitOpDeserializer() + + +# HACK: to allow these to be used in gate_sets.py without throwing deprecation warnings during +# module load. +SINGLE_QUBIT_SERIALIZERS = _SINGLE_QUBIT_SERIALIZERS +SINGLE_QUBIT_DESERIALIZERS = _SINGLE_QUBIT_DESERIALIZERS +SINGLE_QUBIT_HALF_PI_SERIALIZERS = _SINGLE_QUBIT_HALF_PI_SERIALIZERS +SINGLE_QUBIT_HALF_PI_DESERIALIZERS = _SINGLE_QUBIT_HALF_PI_DESERIALIZERS +MEASUREMENT_SERIALIZER = _MEASUREMENT_SERIALIZER +MEASUREMENT_DESERIALIZER = _MEASUREMENT_DESERIALIZER +CZ_POW_SERIALIZER = _CZ_POW_SERIALIZER +CZ_POW_DESERIALIZER = _CZ_POW_DESERIALIZER +SYC_SERIALIZER = _SYC_SERIALIZER +SYC_DESERIALIZER = _SYC_DESERIALIZER +SQRT_ISWAP_SERIALIZERS = _SQRT_ISWAP_SERIALIZERS +SQRT_ISWAP_DESERIALIZERS = _SQRT_ISWAP_DESERIALIZERS +LIMITED_FSIM_SERIALIZERS = _LIMITED_FSIM_SERIALIZERS +LIMITED_FSIM_DESERIALIZER = _LIMITED_FSIM_DESERIALIZER +COUPLER_PULSE_SERIALIZER = _COUPLER_PULSE_SERIALIZER +COUPLER_PULSE_DESERIALIZER = _COUPLER_PULSE_DESERIALIZER +WAIT_GATE_SERIALIZER = _WAIT_GATE_SERIALIZER +WAIT_GATE_DESERIALIZER = _WAIT_GATE_DESERIALIZER + + +cirq._compat.deprecate_attributes( + __name__, + { + 'SINGLE_QUBIT_SERIALIZERS': ( + 'v0.16', + 'GateOpSerializer will no longer be available.' + ' CircuitSerializer will be the only supported circuit serializer going forward.', + ), + 'SINGLE_QUBIT_DESERIALIZERS': ( + 'v0.16', + 'GateOpDeserializer will no longer be available.' + ' CircuitSerializer will be the only supported circuit serializer going forward.', + ), + 'SINGLE_QUBIT_HALF_PI_SERIALIZERS': ( + 'v0.16', + 'GateOpSerializer will no longer be available.' + ' CircuitSerializer will be the only supported circuit serializer going forward.', + ), + 'SINGLE_QUBIT_HALF_PI_DESERIALIZERS': ( + 'v0.16', + 'GateOpDeserializer will no longer be available.' + ' CircuitSerializer will be the only supported circuit serializer going forward.', + ), + 'MEASUREMENT_SERIALIZER': ( + 'v0.16', + 'GateOpSerializer will no longer be available.' + ' CircuitSerializer will be the only supported circuit serializer going forward.', + ), + 'MEASUREMENT_DESERIALIZER': ( + 'v0.16', + 'GateOpDeserializer will no longer be available.' + ' CircuitSerializer will be the only supported circuit serializer going forward.', + ), + 'CZ_SERIALIZER': ( + 'v0.16', + 'GateOpSerializer will no longer be available.' + ' CircuitSerializer will be the only supported circuit serializer going forward.', + ), + 'CZ_POW_SERIALIZER': ( + 'v0.16', + 'GateOpSerializer will no longer be available.' + ' CircuitSerializer will be the only supported circuit serializer going forward.', + ), + 'CZ_POW_DESERIALIZER': ( + 'v0.16', + 'GateOpDeserializer will no longer be available.' + ' CircuitSerializer will be the only supported circuit serializer going forward.', + ), + 'SYC_SERIALIZER': ( + 'v0.16', + 'GateOpSerializer will no longer be available.' + ' CircuitSerializer will be the only supported circuit serializer going forward.', + ), + 'SYC_DESERIALIZER': ( + 'v0.16', + 'GateOpDeserializer will no longer be available.' + ' CircuitSerializer will be the only supported circuit serializer going forward.', + ), + 'SQRT_ISWAP_SERIALIZERS': ( + 'v0.16', + 'GateOpSerializer will no longer be available.' + ' CircuitSerializer will be the only supported circuit serializer going forward.', + ), + 'SQRT_ISWAP_DESERIALIZERS': ( + 'v0.16', + 'GateOpDeserializer will no longer be available.' + ' CircuitSerializer will be the only supported circuit serializer going forward.', + ), + 'LIMITED_FSIM_SERIALIZERS': ( + 'v0.16', + 'GateOpSerializer will no longer be available.' + ' CircuitSerializer will be the only supported circuit serializer going forward.', + ), + 'LIMITED_FSIM_DESERIALIZER': ( + 'v0.16', + 'GateOpDeserializer will no longer be available.' + ' CircuitSerializer will be the only supported circuit serializer going forward.', + ), + 'COUPLER_PULSE_SERIALIZER': ( + 'v0.16', + 'GateOpSerializer will no longer be available.' + ' CircuitSerializer will be the only supported circuit serializer going forward.', + ), + 'COUPLER_PULSE_DESERIALIZER': ( + 'v0.16', + 'GateOpDeserializer will no longer be available.' + ' CircuitSerializer will be the only supported circuit serializer going forward.', + ), + 'WAIT_GATE_SERIALIZER': ( + 'v0.16', + 'GateOpSerializer will no longer be available.' + ' CircuitSerializer will be the only supported circuit serializer going forward.', + ), + 'WAIT_GATE_DESERIALIZER': ( + 'v0.16', + 'GateOpDeserializer will no longer be available.' + ' CircuitSerializer will be the only supported circuit serializer going forward.', + ), + }, +) diff --git a/cirq-google/cirq_google/serialization/common_serializers_test.py b/cirq-google/cirq_google/serialization/common_serializers_test.py index 69fbc9ea013..6bdc4f18355 100644 --- a/cirq-google/cirq_google/serialization/common_serializers_test.py +++ b/cirq-google/cirq_google/serialization/common_serializers_test.py @@ -28,7 +28,10 @@ def _single_qubit_gate_set(): - with cirq.testing.assert_deprecated('SerializableGateSet', deadline='v0.16', count=None): + # Deprecations: cirq_google.SerializableGateSet and common serializers. + with cirq.testing.assert_deprecated( + 'SerializableGateSet', 'CircuitSerializer', deadline='v0.16', count=5 + ): return cg.SerializableGateSet( gate_set_name='test_half_pi', serializers=([cgc.MEASUREMENT_SERIALIZER] + cgc.SINGLE_QUBIT_SERIALIZERS), @@ -37,7 +40,10 @@ def _single_qubit_gate_set(): def _half_pi_gate_set(): - with cirq.testing.assert_deprecated('SerializableGateSet', deadline='v0.16', count=None): + # Deprecations: cirq_google.SerializableGateSet and common serializers. + with cirq.testing.assert_deprecated( + 'SerializableGateSet', 'CircuitSerializer', deadline='v0.16', count=5 + ): return cg.SerializableGateSet( gate_set_name='test_half_pi', serializers=([cgc.MEASUREMENT_SERIALIZER] + cgc.SINGLE_QUBIT_HALF_PI_SERIALIZERS), @@ -422,7 +428,10 @@ def assert_phys_z_tag(phys_z, op): ) @pytest.mark.parametrize('phys_z', [False, True]) def test_serialize_deserialize_cz_gate(gate, exponent, phys_z): - with cirq.testing.assert_deprecated('SerializableGateSet', deadline='v0.16', count=None): + # Deprecations: cirq_google.SerializableGateSet and common serializers. + with cirq.testing.assert_deprecated( + 'SerializableGateSet', 'CircuitSerializer', deadline='v0.16', count=3 + ): gate_set = cg.SerializableGateSet('test', [cgc.CZ_SERIALIZER], [cgc.CZ_POW_DESERIALIZER]) proto = op_proto( { @@ -449,7 +458,10 @@ def test_serialize_deserialize_cz_gate(gate, exponent, phys_z): def test_cz_pow_non_integer_does_not_serialize(): - with cirq.testing.assert_deprecated('SerializableGateSet', deadline='v0.16', count=None): + # Deprecations: cirq_google.SerializableGateSet and common serializers. + with cirq.testing.assert_deprecated( + 'SerializableGateSet', 'CircuitSerializer', deadline='v0.16', count=3 + ): gate_set = cg.SerializableGateSet('test', [cgc.CZ_SERIALIZER], [cgc.CZ_POW_DESERIALIZER]) q1 = cirq.GridQubit(5, 4) q2 = cirq.GridQubit(5, 5) @@ -458,7 +470,10 @@ def test_cz_pow_non_integer_does_not_serialize(): def test_coupler_pulse(): - with cirq.testing.assert_deprecated('SerializableGateSet', deadline='v0.16', count=None): + # Deprecations: cirq_google.SerializableGateSet and common serializers. + with cirq.testing.assert_deprecated( + 'SerializableGateSet', 'CircuitSerializer', deadline='v0.16', count=3 + ): gate_set = cg.SerializableGateSet( 'test', [cgc.COUPLER_PULSE_SERIALIZER], [cgc.COUPLER_PULSE_DESERIALIZER] ) @@ -487,7 +502,10 @@ def test_coupler_pulse(): def test_wait_gate(): - with cirq.testing.assert_deprecated('SerializableGateSet', deadline='v0.16', count=None): + # Deprecations: cirq_google.SerializableGateSet and common serializers. + with cirq.testing.assert_deprecated( + 'SerializableGateSet', 'CircuitSerializer', deadline='v0.16', count=3 + ): gate_set = cg.SerializableGateSet( 'test', [cgc.WAIT_GATE_SERIALIZER], [cgc.WAIT_GATE_DESERIALIZER] ) @@ -505,7 +523,10 @@ def test_wait_gate(): def test_wait_gate_multi_qubit(): - with cirq.testing.assert_deprecated('SerializableGateSet', deadline='v0.16', count=1): + # Deprecations: cirq_google.SerializableGateSet and common serializers. + with cirq.testing.assert_deprecated( + 'SerializableGateSet', 'CircuitSerializer', deadline='v0.16', count=3 + ): gate_set = cg.SerializableGateSet( 'test', [cgc.WAIT_GATE_SERIALIZER], [cgc.WAIT_GATE_DESERIALIZER] ) @@ -552,7 +573,10 @@ def test_wait_gate_multi_qubit(): ) @pytest.mark.parametrize('phys_z', [False, True]) def test_serialize_deserialize_fsim_gate(gate, theta, phi, phys_z): - with cirq.testing.assert_deprecated('SerializableGateSet', deadline='v0.16', count=None): + # Deprecations: cirq_google.SerializableGateSet and common serializers. + with cirq.testing.assert_deprecated( + 'SerializableGateSet', 'CircuitSerializer', deadline='v0.16', count=3 + ): gate_set = cg.SerializableGateSet( 'test', cgc.LIMITED_FSIM_SERIALIZERS, [cgc.LIMITED_FSIM_DESERIALIZER] ) @@ -598,7 +622,10 @@ def test_serialize_deserialize_fsim_gate(gate, theta, phi, phys_z): ) @pytest.mark.parametrize('phys_z', [False, True]) def test_serialize_deserialize_fsim_gate_symbols(gate, theta, phi, phys_z): - with cirq.testing.assert_deprecated('SerializableGateSet', deadline='v0.16', count=None): + # Deprecations: cirq_google.SerializableGateSet and common serializers. + with cirq.testing.assert_deprecated( + 'SerializableGateSet', 'CircuitSerializer', deadline='v0.16', count=3 + ): gate_set = cg.SerializableGateSet( 'test', cgc.LIMITED_FSIM_SERIALIZERS, [cgc.LIMITED_FSIM_DESERIALIZER] ) @@ -623,7 +650,10 @@ def test_serialize_deserialize_fsim_gate_symbols(gate, theta, phi, phys_z): @pytest.mark.parametrize('phys_z', [False, True]) def test_serialize_deserialize_iswap_symbols(phys_z): - with cirq.testing.assert_deprecated('SerializableGateSet', deadline='v0.16', count=None): + # Deprecations: cirq_google.SerializableGateSet and common serializers. + with cirq.testing.assert_deprecated( + 'SerializableGateSet', 'CircuitSerializer', deadline='v0.16', count=3 + ): gate_set = cg.SerializableGateSet( 'test', cgc.LIMITED_FSIM_SERIALIZERS, [cgc.LIMITED_FSIM_DESERIALIZER] ) @@ -651,7 +681,10 @@ def test_serialize_deserialize_iswap_symbols(phys_z): ], ) def test_fsim_gate_not_allowed(gate): - with cirq.testing.assert_deprecated('SerializableGateSet', deadline='v0.16', count=None): + # Deprecations: cirq_google.SerializableGateSet and common serializers. + with cirq.testing.assert_deprecated( + 'SerializableGateSet', 'CircuitSerializer', deadline='v0.16', count=3 + ): q1 = cirq.GridQubit(5, 4) q2 = cirq.GridQubit(5, 5) gate_set = cg.SerializableGateSet( diff --git a/cirq-google/cirq_google/serialization/gate_sets.py b/cirq-google/cirq_google/serialization/gate_sets.py index 14b89a1bb38..bd30277a032 100644 --- a/cirq-google/cirq_google/serialization/gate_sets.py +++ b/cirq-google/cirq_google/serialization/gate_sets.py @@ -18,24 +18,24 @@ from cirq import _compat from cirq_google.serialization import serializable_gate_set from cirq_google.serialization.common_serializers import ( - SINGLE_QUBIT_SERIALIZERS, - SINGLE_QUBIT_DESERIALIZERS, - SINGLE_QUBIT_HALF_PI_SERIALIZERS, - SINGLE_QUBIT_HALF_PI_DESERIALIZERS, - MEASUREMENT_SERIALIZER, - MEASUREMENT_DESERIALIZER, - CZ_POW_SERIALIZER, - CZ_POW_DESERIALIZER, - SYC_SERIALIZER, - SYC_DESERIALIZER, - SQRT_ISWAP_SERIALIZERS, - SQRT_ISWAP_DESERIALIZERS, - LIMITED_FSIM_SERIALIZERS, - LIMITED_FSIM_DESERIALIZER, - COUPLER_PULSE_SERIALIZER, - COUPLER_PULSE_DESERIALIZER, - WAIT_GATE_SERIALIZER, - WAIT_GATE_DESERIALIZER, + _SINGLE_QUBIT_SERIALIZERS, + _SINGLE_QUBIT_DESERIALIZERS, + _SINGLE_QUBIT_HALF_PI_SERIALIZERS, + _SINGLE_QUBIT_HALF_PI_DESERIALIZERS, + _MEASUREMENT_SERIALIZER, + _MEASUREMENT_DESERIALIZER, + _CZ_POW_SERIALIZER, + _CZ_POW_DESERIALIZER, + _SYC_SERIALIZER, + _SYC_DESERIALIZER, + _SQRT_ISWAP_SERIALIZERS, + _SQRT_ISWAP_DESERIALIZERS, + _LIMITED_FSIM_SERIALIZERS, + _LIMITED_FSIM_DESERIALIZER, + _COUPLER_PULSE_SERIALIZER, + _COUPLER_PULSE_DESERIALIZER, + _WAIT_GATE_SERIALIZER, + _WAIT_GATE_DESERIALIZER, CIRCUIT_OP_SERIALIZER, CIRCUIT_OP_DESERIALIZER, ) @@ -45,19 +45,19 @@ serializable_gate_set._SerializableGateSet( gate_set_name='sycamore', serializers=[ - SYC_SERIALIZER, - *SINGLE_QUBIT_SERIALIZERS, - *SINGLE_QUBIT_HALF_PI_SERIALIZERS, - MEASUREMENT_SERIALIZER, - WAIT_GATE_SERIALIZER, + _SYC_SERIALIZER, + *_SINGLE_QUBIT_SERIALIZERS, + *_SINGLE_QUBIT_HALF_PI_SERIALIZERS, + _MEASUREMENT_SERIALIZER, + _WAIT_GATE_SERIALIZER, CIRCUIT_OP_SERIALIZER, ], deserializers=[ - SYC_DESERIALIZER, - *SINGLE_QUBIT_DESERIALIZERS, - *SINGLE_QUBIT_HALF_PI_DESERIALIZERS, - MEASUREMENT_DESERIALIZER, - WAIT_GATE_DESERIALIZER, + _SYC_DESERIALIZER, + *_SINGLE_QUBIT_DESERIALIZERS, + *_SINGLE_QUBIT_HALF_PI_DESERIALIZERS, + _MEASUREMENT_DESERIALIZER, + _WAIT_GATE_DESERIALIZER, CIRCUIT_OP_DESERIALIZER, ], ), @@ -69,17 +69,17 @@ serializable_gate_set._SerializableGateSet( gate_set_name='sqrt_iswap', serializers=[ - *SQRT_ISWAP_SERIALIZERS, - *SINGLE_QUBIT_SERIALIZERS, - MEASUREMENT_SERIALIZER, - WAIT_GATE_SERIALIZER, + *_SQRT_ISWAP_SERIALIZERS, + *_SINGLE_QUBIT_SERIALIZERS, + _MEASUREMENT_SERIALIZER, + _WAIT_GATE_SERIALIZER, CIRCUIT_OP_SERIALIZER, ], deserializers=[ - *SQRT_ISWAP_DESERIALIZERS, - *SINGLE_QUBIT_DESERIALIZERS, - MEASUREMENT_DESERIALIZER, - WAIT_GATE_DESERIALIZER, + *_SQRT_ISWAP_DESERIALIZERS, + *_SINGLE_QUBIT_DESERIALIZERS, + _MEASUREMENT_DESERIALIZER, + _WAIT_GATE_DESERIALIZER, CIRCUIT_OP_DESERIALIZER, ], ), @@ -92,17 +92,17 @@ serializable_gate_set._SerializableGateSet( gate_set_name='fsim', serializers=[ - *LIMITED_FSIM_SERIALIZERS, - *SINGLE_QUBIT_SERIALIZERS, - MEASUREMENT_SERIALIZER, - WAIT_GATE_SERIALIZER, + *_LIMITED_FSIM_SERIALIZERS, + *_SINGLE_QUBIT_SERIALIZERS, + _MEASUREMENT_SERIALIZER, + _WAIT_GATE_SERIALIZER, CIRCUIT_OP_SERIALIZER, ], deserializers=[ - LIMITED_FSIM_DESERIALIZER, - *SINGLE_QUBIT_DESERIALIZERS, - MEASUREMENT_DESERIALIZER, - WAIT_GATE_DESERIALIZER, + _LIMITED_FSIM_DESERIALIZER, + *_SINGLE_QUBIT_DESERIALIZERS, + _MEASUREMENT_DESERIALIZER, + _WAIT_GATE_DESERIALIZER, CIRCUIT_OP_DESERIALIZER, ], ), @@ -115,19 +115,19 @@ serializable_gate_set._SerializableGateSet( gate_set_name='pulse', serializers=[ - COUPLER_PULSE_SERIALIZER, - *LIMITED_FSIM_SERIALIZERS, - *SINGLE_QUBIT_SERIALIZERS, - MEASUREMENT_SERIALIZER, - WAIT_GATE_SERIALIZER, + _COUPLER_PULSE_SERIALIZER, + *_LIMITED_FSIM_SERIALIZERS, + *_SINGLE_QUBIT_SERIALIZERS, + _MEASUREMENT_SERIALIZER, + _WAIT_GATE_SERIALIZER, CIRCUIT_OP_SERIALIZER, ], deserializers=[ - COUPLER_PULSE_DESERIALIZER, - LIMITED_FSIM_DESERIALIZER, - *SINGLE_QUBIT_DESERIALIZERS, - MEASUREMENT_DESERIALIZER, - WAIT_GATE_DESERIALIZER, + _COUPLER_PULSE_DESERIALIZER, + _LIMITED_FSIM_DESERIALIZER, + *_SINGLE_QUBIT_DESERIALIZERS, + _MEASUREMENT_DESERIALIZER, + _WAIT_GATE_DESERIALIZER, CIRCUIT_OP_DESERIALIZER, ], ), @@ -144,15 +144,15 @@ serializable_gate_set._SerializableGateSet( gate_set_name='xmon', serializers=[ - *SINGLE_QUBIT_SERIALIZERS, - CZ_POW_SERIALIZER, - MEASUREMENT_SERIALIZER, + *_SINGLE_QUBIT_SERIALIZERS, + _CZ_POW_SERIALIZER, + _MEASUREMENT_SERIALIZER, CIRCUIT_OP_SERIALIZER, ], deserializers=[ - *SINGLE_QUBIT_DESERIALIZERS, - CZ_POW_DESERIALIZER, - MEASUREMENT_DESERIALIZER, + *_SINGLE_QUBIT_DESERIALIZERS, + _CZ_POW_DESERIALIZER, + _MEASUREMENT_DESERIALIZER, CIRCUIT_OP_DESERIALIZER, ], ),