Skip to content

Commit 0bb9a06

Browse files
committed
Deprecate SerializableGateSet.
Deprecating the class directly will cause global gatesets such as SYC_GATESET to throw a deprecation warning during module loading. A shell class (containing class documentation) is created to avoid this.
1 parent 8071b1e commit 0bb9a06

7 files changed

+839
-522
lines changed

cirq-google/cirq_google/devices/known_devices_test.py

Lines changed: 23 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -61,11 +61,11 @@ def test_create_device_proto_for_irregular_grid():
6161

6262

6363
def test_multiple_gate_sets():
64-
# Deprecations: well-known cirq_google SerializableGateSets
65-
# (e.g. cirq_google.SYC_GATESET), and
64+
# Deprecations: cirq_google.SerializableGateSets class,
65+
# well-known cirq_google SerializableGateSets (e.g. cirq_google.SYC_GATESET), and
6666
# cirq_google.devices.known_devices.create_device_proto_from_diagram
6767
with cirq.testing.assert_deprecated(
68-
'SerializableGateSet', 'no longer be available', deadline='v0.16', count=2
68+
'SerializableGateSet', 'no longer be available', deadline='v0.16', count=3
6969
):
7070
halfPiGateSet = cirq_google.SerializableGateSet(
7171
gate_set_name='half_pi_gateset',
@@ -226,15 +226,15 @@ def test_multiple_gate_sets():
226226

227227

228228
def test_sycamore_circuitop_device():
229-
# Deprecations: cirq_google.SerializableDevice, well-known cirq_google SerializableGateSets
230-
# (e.g. cirq_google.SYC_GATESET), and
229+
# Deprecations: cirq_google.SerializableGateSets class,
230+
# well-known cirq_google SerializableGateSets (e.g. cirq_google.SYC_GATESET), and
231231
# cirq_google.devices.known_devices.create_device_proto_from_diagram
232232
with cirq.testing.assert_deprecated(
233233
'Use cirq_google.GridDevice',
234234
'SerializableGateSet',
235235
'no longer be available',
236236
deadline='v0.16',
237-
count=5,
237+
count=6,
238238
):
239239
circuitop_gateset = cirq_google.SerializableGateSet(
240240
gate_set_name='circuitop_gateset',
@@ -278,7 +278,11 @@ def test_sycamore_grid_layout():
278278

279279

280280
def test_proto_with_circuitop():
281-
with cirq.testing.assert_deprecated('no longer be available', deadline='v0.16', count=1):
281+
# Deprecations: cirq_google.SerializableGateSets class and
282+
# cirq_google.devices.known_devices.create_device_proto_from_diagram
283+
with cirq.testing.assert_deprecated(
284+
'SerializableGateSet', 'no longer be available', deadline='v0.16', count=2
285+
):
282286
circuitop_gateset = cirq_google.SerializableGateSet(
283287
gate_set_name='circuitop_gateset',
284288
serializers=[cgc.CIRCUIT_OP_SERIALIZER],
@@ -330,10 +334,14 @@ def test_proto_with_circuitop():
330334

331335

332336
def test_proto_with_waitgate():
333-
# Deprecations: cirq_google.SerializableDevice and
337+
# Deprecations: cirq_google.SerializableDevice, cirq_google.SerializableGateSet, and
334338
# cirq_google.devices.known_devices.create_device_proto_from_diagram
335339
with cirq.testing.assert_deprecated(
336-
'Use cirq_google.GridDevice', 'no longer be available', deadline='v0.16', count=3
340+
'Use cirq_google.GridDevice',
341+
'SerializableGateSet',
342+
'no longer be available',
343+
deadline='v0.16',
344+
count=4,
337345
):
338346
wait_gateset = cirq_google.SerializableGateSet(
339347
gate_set_name='wait_gateset',
@@ -397,10 +405,14 @@ def test_proto_with_waitgate():
397405

398406

399407
def test_adding_gates_multiple_times():
400-
# Deprecations: cirq_google.SerializableDevice and
408+
# Deprecations: cirq_google.SerializableDevice, cirq_google.SerializableGateSet, and
401409
# cirq_google.devices.known_devices.create_device_proto_from_diagram
402410
with cirq.testing.assert_deprecated(
403-
'Use cirq_google.GridDevice', 'no longer be available', deadline='v0.16', count=3
411+
'Use cirq_google.GridDevice',
412+
'SerializableGateSet',
413+
'no longer be available',
414+
deadline='v0.16',
415+
count=4,
404416
):
405417
waiting_for_godot = cirq_google.SerializableGateSet(
406418
gate_set_name='wait_gateset',

cirq-google/cirq_google/devices/serializable_device_test.py

Lines changed: 58 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -25,25 +25,37 @@
2525
import cirq_google.devices.known_devices as cgdk
2626
import cirq_google.serialization.common_serializers as cgc
2727

28-
_JUST_CZ = cg.SerializableGateSet(
29-
gate_set_name='cz_gate_set',
30-
serializers=[cg.GateOpSerializer(gate_type=cirq.CZPowGate, serialized_gate_id='cz', args=[])],
31-
deserializers=[
32-
cg.GateOpDeserializer(serialized_gate_id='cz', gate_constructor=cirq.CZPowGate, args=[])
33-
],
34-
)
35-
36-
_JUST_MEAS = cg.SerializableGateSet(
37-
gate_set_name='meas_gate_set',
38-
serializers=[
39-
cg.GateOpSerializer(gate_type=cirq.MeasurementGate, serialized_gate_id='meas', args=[])
40-
],
41-
deserializers=[
42-
cg.GateOpDeserializer(
43-
serialized_gate_id='meas', gate_constructor=cirq.MeasurementGate, args=[]
28+
29+
def _just_cz():
30+
with cirq.testing.assert_deprecated('SerializableGateSet', deadline='v0.16', count=None):
31+
return cg.SerializableGateSet(
32+
gate_set_name='cz_gate_set',
33+
serializers=[
34+
cg.GateOpSerializer(gate_type=cirq.CZPowGate, serialized_gate_id='cz', args=[])
35+
],
36+
deserializers=[
37+
cg.GateOpDeserializer(
38+
serialized_gate_id='cz', gate_constructor=cirq.CZPowGate, args=[]
39+
)
40+
],
41+
)
42+
43+
44+
def _just_meas():
45+
with cirq.testing.assert_deprecated('SerializableGateSet', deadline='v0.16', count=None):
46+
return cg.SerializableGateSet(
47+
gate_set_name='meas_gate_set',
48+
serializers=[
49+
cg.GateOpSerializer(
50+
gate_type=cirq.MeasurementGate, serialized_gate_id='meas', args=[]
51+
)
52+
],
53+
deserializers=[
54+
cg.GateOpDeserializer(
55+
serialized_gate_id='meas', gate_constructor=cirq.MeasurementGate, args=[]
56+
)
57+
],
4458
)
45-
],
46-
)
4759

4860

4961
def test_str_with_grid_qubits():
@@ -241,8 +253,9 @@ def test_asymmetric_gate():
241253
gate.id = 'cz'
242254
gate.valid_targets.extend(['left_to_right'])
243255

256+
cz_gateset = _just_cz()
244257
with cirq.testing.assert_deprecated('Use cirq_google.GridDevice', deadline='v0.16', count=2):
245-
dev = cg.SerializableDevice.from_proto(proto=spec, gate_sets=[_JUST_CZ])
258+
dev = cg.SerializableDevice.from_proto(proto=spec, gate_sets=[cz_gateset])
246259

247260
for row in range(5):
248261
dev.validate_operation(cirq.CZ(cirq.GridQubit(row, 0), cirq.GridQubit(row, 1)))
@@ -265,8 +278,9 @@ def test_unconstrained_gate():
265278
gate.id = 'cz'
266279
gate.valid_targets.extend(['2_qubit_anywhere'])
267280

281+
cz_gateset = _just_cz()
268282
with cirq.testing.assert_deprecated('Use cirq_google.GridDevice', deadline='v0.16', count=2):
269-
dev = cg.SerializableDevice.from_proto(proto=spec, gate_sets=[_JUST_CZ])
283+
dev = cg.SerializableDevice.from_proto(proto=spec, gate_sets=[cz_gateset])
270284

271285
valid_qubit1 = cirq.GridQubit(4, 4)
272286
for row in range(4):
@@ -292,8 +306,9 @@ def test_number_of_qubits_cz():
292306
gate.valid_targets.extend(['2_qubit_anywhere'])
293307
gate.number_of_qubits = 3
294308

309+
cz_gateset = _just_cz()
295310
with cirq.testing.assert_deprecated('Use cirq_google.GridDevice', deadline='v0.16', count=2):
296-
dev = cg.SerializableDevice.from_proto(proto=spec, gate_sets=[_JUST_CZ])
311+
dev = cg.SerializableDevice.from_proto(proto=spec, gate_sets=[cz_gateset])
297312

298313
with pytest.raises(ValueError):
299314
dev.validate_operation(cirq.CZ(cirq.GridQubit(0, 0), cirq.GridQubit(0, 1)))
@@ -318,8 +333,9 @@ def test_constrained_permutations():
318333
gate.id = 'meas'
319334
gate.valid_targets.extend(['meas_on_first_line'])
320335

336+
meas_gateset = _just_meas()
321337
with cirq.testing.assert_deprecated('Use cirq_google.GridDevice', deadline='v0.16', count=2):
322-
dev = cg.SerializableDevice.from_proto(proto=spec, gate_sets=[_JUST_MEAS])
338+
dev = cg.SerializableDevice.from_proto(proto=spec, gate_sets=[meas_gateset])
323339

324340
dev.validate_operation(cirq.measure(cirq.GridQubit(0, 0)))
325341
dev.validate_operation(cirq.measure(cirq.GridQubit(1, 0)))
@@ -352,16 +368,21 @@ def test_mixing_types():
352368
gate.id = 'meas'
353369
gate.valid_targets.extend(['subset', 'sym'])
354370

371+
meas_gateset = _just_meas()
355372
with cirq.testing.assert_deprecated('Use cirq_google.GridDevice', deadline='v0.16', count=1):
356373
with pytest.raises(NotImplementedError):
357-
_ = cg.SerializableDevice.from_proto(proto=spec, gate_sets=[_JUST_MEAS])
374+
_ = cg.SerializableDevice.from_proto(proto=spec, gate_sets=[meas_gateset])
358375

359376

360377
def test_multiple_gatesets():
361-
# Deprecations: cirq_google.SerializableDevice and
378+
# Deprecations: cirq_google.SerializableDevice, cirq_google.SerializableGateSet, and
362379
# cirq_google.devices.known_devices.create_device_proto_from_diagram
363380
with cirq.testing.assert_deprecated(
364-
'Use cirq_google.GridDevice', 'no longer be available', deadline='v0.16', count=3
381+
'Use cirq_google.GridDevice',
382+
'SerializableGateSet',
383+
'no longer be available',
384+
deadline='v0.16',
385+
count=5,
365386
):
366387
halfPiGateSet = cirq_google.SerializableGateSet(
367388
gate_set_name='half_pi_gateset',
@@ -396,10 +417,14 @@ def test_half_pi_takes_half_duration():
396417
gate perform correctly. In this case, we set the XPowGate to be
397418
half the duration of the full exponent and make sure it still works.
398419
"""
399-
# Deprecations: cirq_google.SerializableDevice and
420+
# Deprecations: cirq_google.SerializableDevice, cirq_google.SerializableGateSet, and
400421
# cirq_google.devices.known_devices.create_device_proto_from_diagram
401422
with cirq.testing.assert_deprecated(
402-
'Use cirq_google.GridDevice', 'no longer be available', deadline='v0.16', count=3
423+
'Use cirq_google.GridDevice',
424+
'SerializableGateSet',
425+
'no longer be available',
426+
deadline='v0.16',
427+
count=4,
403428
):
404429
half_pi_gs = cirq_google.SerializableGateSet(
405430
gate_set_name='half_pi',
@@ -425,10 +450,14 @@ def test_multiple_fsim_gatesets():
425450
gate perform correctly. In this case, we set the XPowGate to be
426451
half the duration of the full exponent and make sure it still works.
427452
"""
428-
# Deprecations: cirq_google.SerializableDevice and
453+
# Deprecations: cirq_google.SerializableDevice, cirq_google.SerializableGateSet, and
429454
# cirq_google.devices.known_devices.create_device_proto_from_diagram
430455
with cirq.testing.assert_deprecated(
431-
'Use cirq_google.GridDevice', 'no longer be available', deadline='v0.16', count=3
456+
'Use cirq_google.GridDevice',
457+
'SerializableGateSet',
458+
'no longer be available',
459+
deadline='v0.16',
460+
count=4,
432461
):
433462
half_pi_gs = cirq_google.SerializableGateSet(
434463
gate_set_name='half_pi',

cirq-google/cirq_google/engine/engine_processor_test.py

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -100,15 +100,6 @@ def _to_timestamp(json_string):
100100
)
101101

102102

103-
_GATE_SET = cg.SerializableGateSet(
104-
gate_set_name='x_gate_set',
105-
serializers=[cg.GateOpSerializer(gate_type=cirq.XPowGate, serialized_gate_id='x', args=[])],
106-
deserializers=[
107-
cg.GateOpDeserializer(serialized_gate_id='x', gate_constructor=cirq.XPowGate, args=[])
108-
],
109-
)
110-
111-
112103
_CIRCUIT = cirq.Circuit(
113104
cirq.X(cirq.GridQubit(5, 2)) ** 0.5, cirq.measure(cirq.GridQubit(5, 2), key='result')
114105
)

0 commit comments

Comments
 (0)