25
25
import cirq_google .devices .known_devices as cgdk
26
26
import cirq_google .serialization .common_serializers as cgc
27
27
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
+ ],
44
58
)
45
- ],
46
- )
47
59
48
60
49
61
def test_str_with_grid_qubits ():
@@ -241,8 +253,9 @@ def test_asymmetric_gate():
241
253
gate .id = 'cz'
242
254
gate .valid_targets .extend (['left_to_right' ])
243
255
256
+ cz_gateset = _just_cz ()
244
257
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 ])
246
259
247
260
for row in range (5 ):
248
261
dev .validate_operation (cirq .CZ (cirq .GridQubit (row , 0 ), cirq .GridQubit (row , 1 )))
@@ -265,8 +278,9 @@ def test_unconstrained_gate():
265
278
gate .id = 'cz'
266
279
gate .valid_targets .extend (['2_qubit_anywhere' ])
267
280
281
+ cz_gateset = _just_cz ()
268
282
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 ])
270
284
271
285
valid_qubit1 = cirq .GridQubit (4 , 4 )
272
286
for row in range (4 ):
@@ -292,8 +306,9 @@ def test_number_of_qubits_cz():
292
306
gate .valid_targets .extend (['2_qubit_anywhere' ])
293
307
gate .number_of_qubits = 3
294
308
309
+ cz_gateset = _just_cz ()
295
310
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 ])
297
312
298
313
with pytest .raises (ValueError ):
299
314
dev .validate_operation (cirq .CZ (cirq .GridQubit (0 , 0 ), cirq .GridQubit (0 , 1 )))
@@ -318,8 +333,9 @@ def test_constrained_permutations():
318
333
gate .id = 'meas'
319
334
gate .valid_targets .extend (['meas_on_first_line' ])
320
335
336
+ meas_gateset = _just_meas ()
321
337
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 ])
323
339
324
340
dev .validate_operation (cirq .measure (cirq .GridQubit (0 , 0 )))
325
341
dev .validate_operation (cirq .measure (cirq .GridQubit (1 , 0 )))
@@ -352,16 +368,21 @@ def test_mixing_types():
352
368
gate .id = 'meas'
353
369
gate .valid_targets .extend (['subset' , 'sym' ])
354
370
371
+ meas_gateset = _just_meas ()
355
372
with cirq .testing .assert_deprecated ('Use cirq_google.GridDevice' , deadline = 'v0.16' , count = 1 ):
356
373
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 ])
358
375
359
376
360
377
def test_multiple_gatesets ():
361
- # Deprecations: cirq_google.SerializableDevice and
378
+ # Deprecations: cirq_google.SerializableDevice, cirq_google.SerializableGateSet, and
362
379
# cirq_google.devices.known_devices.create_device_proto_from_diagram
363
380
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 ,
365
386
):
366
387
halfPiGateSet = cirq_google .SerializableGateSet (
367
388
gate_set_name = 'half_pi_gateset' ,
@@ -396,10 +417,14 @@ def test_half_pi_takes_half_duration():
396
417
gate perform correctly. In this case, we set the XPowGate to be
397
418
half the duration of the full exponent and make sure it still works.
398
419
"""
399
- # Deprecations: cirq_google.SerializableDevice and
420
+ # Deprecations: cirq_google.SerializableDevice, cirq_google.SerializableGateSet, and
400
421
# cirq_google.devices.known_devices.create_device_proto_from_diagram
401
422
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 ,
403
428
):
404
429
half_pi_gs = cirq_google .SerializableGateSet (
405
430
gate_set_name = 'half_pi' ,
@@ -425,10 +450,14 @@ def test_multiple_fsim_gatesets():
425
450
gate perform correctly. In this case, we set the XPowGate to be
426
451
half the duration of the full exponent and make sure it still works.
427
452
"""
428
- # Deprecations: cirq_google.SerializableDevice and
453
+ # Deprecations: cirq_google.SerializableDevice, cirq_google.SerializableGateSet, and
429
454
# cirq_google.devices.known_devices.create_device_proto_from_diagram
430
455
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 ,
432
461
):
433
462
half_pi_gs = cirq_google .SerializableGateSet (
434
463
gate_set_name = 'half_pi' ,
0 commit comments