Skip to content

Commit 8071b1e

Browse files
committed
Deprecate global SerializableGateSets
1 parent a58b7fc commit 8071b1e

13 files changed

+730
-545
lines changed

cirq-google/cirq_google/__init__.py

Lines changed: 45 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,50 @@
164164
_compat.deprecate_attributes(
165165
__name__,
166166
{
167-
'Bristlecone': ('v0.15', 'Bristlecone will no longer be supported.'),
168-
'Foxtail': ('v0.15', 'Foxtail will no longer be supported.'),
167+
'XMON': (
168+
'v0.16',
169+
'SerializableGateSet will no longer be supported.'
170+
' In cirq_google.GridDevice, the new representation of Google devices, the gateset of '
171+
' a device is represented as a cirq.Gateset and is available as'
172+
' GridDevice.metadata.gateset.'
173+
' Engine methods no longer require gate sets to be passed in.'
174+
' In addition, circuit serialization is replaced by cirq_google.CircuitSerializer.',
175+
),
176+
'FSIM_GATESET': (
177+
'v0.16',
178+
'SerializableGateSet will no longer be supported.'
179+
' In cirq_google.GridDevice, the new representation of Google devices, the gateset of '
180+
' a device is represented as a cirq.Gateset and is available as'
181+
' GridDevice.metadata.gateset.'
182+
' Engine methods no longer require gate sets to be passed in.'
183+
' In addition, circuit serialization is replaced by cirq_google.CircuitSerializer.',
184+
),
185+
'SQRT_ISWAP_GATESET': (
186+
'v0.16',
187+
'SerializableGateSet will no longer be supported.'
188+
' In cirq_google.GridDevice, the new representation of Google devices, the gateset of '
189+
' a device is represented as a cirq.Gateset and is available as'
190+
' GridDevice.metadata.gateset.'
191+
' Engine methods no longer require gate sets to be passed in.'
192+
' In addition, circuit serialization is replaced by cirq_google.CircuitSerializer.',
193+
),
194+
'SYC_GATESET': (
195+
'v0.16',
196+
'SerializableGateSet will no longer be supported.'
197+
' In cirq_google.GridDevice, the new representation of Google devices, the gateset of '
198+
' a device is represented as a cirq.Gateset and is available as'
199+
' GridDevice.metadata.gateset.'
200+
' Engine methods no longer require gate sets to be passed in.'
201+
' In addition, circuit serialization is replaced by cirq_google.CircuitSerializer.',
202+
),
203+
'NAMED_GATESETS': (
204+
'v0.16',
205+
'SerializableGateSet will no longer be supported.'
206+
' In cirq_google.GridDevice, the new representation of Google devices, the gateset of '
207+
' a device is represented as a cirq.Gateset and is available as'
208+
' GridDevice.metadata.gateset.'
209+
' Engine methods no longer require gate sets to be passed in.'
210+
' In addition, circuit serialization is replaced by cirq_google.CircuitSerializer.',
211+
),
169212
},
170213
)

cirq-google/cirq_google/calibration/phased_fsim_test.py

Lines changed: 47 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -221,54 +221,55 @@ def test_floquet_to_calibration_layer_with_measure_qubits():
221221

222222

223223
def test_xeb_to_calibration_layer():
224-
q_00, q_01, q_02, q_03 = [cirq.GridQubit(0, index) for index in range(4)]
225-
gate = cirq.FSimGate(theta=np.pi / 4, phi=0.0)
226-
request = XEBPhasedFSimCalibrationRequest(
227-
gate=gate,
228-
pairs=((q_00, q_01), (q_02, q_03)),
229-
options=XEBPhasedFSimCalibrationOptions(
230-
n_library_circuits=22,
231-
fsim_options=XEBPhasedFSimCharacterizationOptions(
232-
characterize_theta=True,
233-
characterize_zeta=True,
234-
characterize_chi=False,
235-
characterize_gamma=False,
236-
characterize_phi=True,
224+
with cirq.testing.assert_deprecated('SerializableGateSet', deadline='v0.16', count=None):
225+
q_00, q_01, q_02, q_03 = [cirq.GridQubit(0, index) for index in range(4)]
226+
gate = cirq.FSimGate(theta=np.pi / 4, phi=0.0)
227+
request = XEBPhasedFSimCalibrationRequest(
228+
gate=gate,
229+
pairs=((q_00, q_01), (q_02, q_03)),
230+
options=XEBPhasedFSimCalibrationOptions(
231+
n_library_circuits=22,
232+
fsim_options=XEBPhasedFSimCharacterizationOptions(
233+
characterize_theta=True,
234+
characterize_zeta=True,
235+
characterize_chi=False,
236+
characterize_gamma=False,
237+
characterize_phi=True,
238+
),
237239
),
238-
),
239-
)
240-
layer = request.to_calibration_layer()
241-
assert layer == cirq_google.CalibrationLayer(
242-
calibration_type='xeb_phased_fsim_characterization',
243-
program=cirq.Circuit([gate.on(q_00, q_01), gate.on(q_02, q_03)]),
244-
args={
245-
'n_library_circuits': 22,
246-
'n_combinations': 10,
247-
'cycle_depths': '5_25_50_100_200_300',
248-
'fatol': 5e-3,
249-
'xatol': 5e-3,
250-
'characterize_theta': True,
251-
'characterize_zeta': True,
252-
'characterize_chi': False,
253-
'characterize_gamma': False,
254-
'characterize_phi': True,
255-
},
256-
)
240+
)
241+
layer = request.to_calibration_layer()
242+
assert layer == cirq_google.CalibrationLayer(
243+
calibration_type='xeb_phased_fsim_characterization',
244+
program=cirq.Circuit([gate.on(q_00, q_01), gate.on(q_02, q_03)]),
245+
args={
246+
'n_library_circuits': 22,
247+
'n_combinations': 10,
248+
'cycle_depths': '5_25_50_100_200_300',
249+
'fatol': 5e-3,
250+
'xatol': 5e-3,
251+
'characterize_theta': True,
252+
'characterize_zeta': True,
253+
'characterize_chi': False,
254+
'characterize_gamma': False,
255+
'characterize_phi': True,
256+
},
257+
)
257258

258-
# Serialize to proto
259-
calibration = v2.calibration_pb2.FocusedCalibration()
260-
new_layer = calibration.layers.add()
261-
new_layer.calibration_type = layer.calibration_type
262-
for arg in layer.args:
263-
arg_to_proto(layer.args[arg], out=new_layer.args[arg])
264-
cirq_google.SQRT_ISWAP_GATESET.serialize(layer.program, msg=new_layer.layer)
265-
with open(os.path.dirname(__file__) + '/test_data/xeb_calibration_layer.textproto') as f:
266-
desired_textproto = f.read()
267-
268-
layer_str = str(new_layer)
269-
# Fix precision issues
270-
layer_str = re.sub(r'0.004999\d+', '0.005', layer_str)
271-
assert layer_str == desired_textproto
259+
# Serialize to proto
260+
calibration = v2.calibration_pb2.FocusedCalibration()
261+
new_layer = calibration.layers.add()
262+
new_layer.calibration_type = layer.calibration_type
263+
for arg in layer.args:
264+
arg_to_proto(layer.args[arg], out=new_layer.args[arg])
265+
cirq_google.SQRT_ISWAP_GATESET.serialize(layer.program, msg=new_layer.layer)
266+
with open(os.path.dirname(__file__) + '/test_data/xeb_calibration_layer.textproto') as f:
267+
desired_textproto = f.read()
268+
269+
layer_str = str(new_layer)
270+
# Fix precision issues
271+
layer_str = re.sub(r'0.004999\d+', '0.005', layer_str)
272+
assert layer_str == desired_textproto
272273

273274

274275
def test_from_moment():

cirq-google/cirq_google/calibration/workflow_test.py

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1155,23 +1155,21 @@ def test_run_calibrations_empty():
11551155

11561156
def test_run_calibrations_fails_when_invalid_arguments():
11571157
with pytest.raises(ValueError):
1158-
assert workflow.run_calibrations(
1159-
[], None, 'qproc', cirq_google.FSIM_GATESET, max_layers_per_request=0
1160-
)
1158+
assert workflow.run_calibrations([], None, 'qproc', max_layers_per_request=0)
11611159

11621160
request = FloquetPhasedFSimCalibrationRequest(
11631161
gate=SQRT_ISWAP_INV_GATE, pairs=(), options=WITHOUT_CHI_FLOQUET_PHASED_FSIM_CHARACTERIZATION
11641162
)
11651163
engine = mock.MagicMock(spec=cirq_google.Engine)
11661164

11671165
with pytest.raises(ValueError):
1168-
assert workflow.run_calibrations([request], engine, None, cirq_google.FSIM_GATESET)
1166+
assert workflow.run_calibrations([request], engine, None)
11691167

11701168
with pytest.raises(ValueError):
11711169
assert workflow.run_calibrations([request], engine, 'qproc', None)
11721170

11731171
with pytest.raises(ValueError):
1174-
assert workflow.run_calibrations([request], 0, 'qproc', cirq_google.FSIM_GATESET)
1172+
assert workflow.run_calibrations([request], 0, 'qproc')
11751173

11761174

11771175
def test_run_calibrations_with_simulator():

cirq-google/cirq_google/devices/grid_device_test.py

Lines changed: 72 additions & 68 deletions
Original file line numberDiff line numberDiff line change
@@ -418,78 +418,82 @@ def test_to_proto_invalid_input(error_match, qubits, qubit_pairs, gateset, gate_
418418

419419

420420
def test_to_proto_backward_compatibility():
421-
device_info, _ = _create_device_spec_with_horizontal_couplings()
422-
423-
# The set of gates in gate_durations are consistent with what's generated in
424-
# _create_device_spec_with_horizontal_couplings()
425-
base_duration = cirq.Duration(picos=1_000)
426-
gate_durations = {
427-
cirq.GateFamily(cirq_google.SYC): base_duration * 0,
428-
cirq.GateFamily(cirq.SQRT_ISWAP): base_duration * 1,
429-
cirq.GateFamily(cirq.SQRT_ISWAP_INV): base_duration * 2,
430-
cirq.GateFamily(cirq.CZ): base_duration * 3,
431-
cirq.GateFamily(cirq.ops.phased_x_z_gate.PhasedXZGate): base_duration * 4,
432-
cirq.GateFamily(
433-
cirq.ops.common_gates.ZPowGate, tags_to_ignore=[cirq_google.PhysicalZTag()]
434-
): base_duration
435-
* 5,
436-
cirq.GateFamily(
437-
cirq.ops.common_gates.ZPowGate, tags_to_accept=[cirq_google.PhysicalZTag()]
438-
): base_duration
439-
* 6,
440-
cirq.GateFamily(cirq_google.experimental.ops.coupler_pulse.CouplerPulse): base_duration * 7,
441-
cirq.GateFamily(cirq.ops.measurement_gate.MeasurementGate): base_duration * 8,
442-
cirq.GateFamily(cirq.ops.wait_gate.WaitGate): base_duration * 9,
443-
}
444-
445-
# Serialize the old way
446-
spec = known_devices.create_device_proto_for_qubits(
447-
device_info.grid_qubits,
448-
device_info.qubit_pairs,
449-
[cirq_google.FSIM_GATESET],
450-
known_devices._SYCAMORE_DURATIONS_PICOS,
451-
)
452-
453-
# Serialize the new way
454-
grid_device.create_device_specification_proto(
455-
qubits=device_info.grid_qubits,
456-
pairs=device_info.qubit_pairs,
457-
gateset=cirq.Gateset(*gate_durations.keys()),
458-
gate_durations=gate_durations,
459-
out=spec,
460-
)
461-
462-
with cirq.testing.assert_deprecated('Use cirq_google.GridDevice', deadline='v0.16', count=None):
463-
# Deserialize both ways
464-
serializable_dev = cirq_google.SerializableDevice.from_proto(
465-
spec, [cirq_google.FSIM_GATESET]
466-
)
467-
grid_dev = cirq_google.GridDevice.from_proto(spec)
468-
469-
assert serializable_dev.metadata.qubit_set == grid_dev.metadata.qubit_set
470-
assert serializable_dev.metadata.qubit_pairs == grid_dev.metadata.qubit_pairs
471-
472-
assert serializable_dev.metadata.gateset == cirq.Gateset(
473-
cirq.FSimGate,
474-
cirq.ISwapPowGate,
475-
cirq.CZPowGate,
476-
cirq.PhasedXPowGate,
477-
cirq.XPowGate,
478-
cirq.YPowGate,
479-
cirq.ZPowGate,
480-
cirq.PhasedXZGate,
481-
cirq.MeasurementGate,
482-
cirq.WaitGate,
483-
cirq.GlobalPhaseGate,
421+
with cirq.testing.assert_deprecated('SerializableGateSet', deadline='v0.16', count=None):
422+
device_info, _ = _create_device_spec_with_horizontal_couplings()
423+
424+
# The set of gates in gate_durations are consistent with what's generated in
425+
# _create_device_spec_with_horizontal_couplings()
426+
base_duration = cirq.Duration(picos=1_000)
427+
gate_durations = {
428+
cirq.GateFamily(cirq_google.SYC): base_duration * 0,
429+
cirq.GateFamily(cirq.SQRT_ISWAP): base_duration * 1,
430+
cirq.GateFamily(cirq.SQRT_ISWAP_INV): base_duration * 2,
431+
cirq.GateFamily(cirq.CZ): base_duration * 3,
432+
cirq.GateFamily(cirq.ops.phased_x_z_gate.PhasedXZGate): base_duration * 4,
433+
cirq.GateFamily(
434+
cirq.ops.common_gates.ZPowGate, tags_to_ignore=[cirq_google.PhysicalZTag()]
435+
): base_duration
436+
* 5,
437+
cirq.GateFamily(
438+
cirq.ops.common_gates.ZPowGate, tags_to_accept=[cirq_google.PhysicalZTag()]
439+
): base_duration
440+
* 6,
441+
cirq.GateFamily(cirq_google.experimental.ops.coupler_pulse.CouplerPulse): base_duration
442+
* 7,
443+
cirq.GateFamily(cirq.ops.measurement_gate.MeasurementGate): base_duration * 8,
444+
cirq.GateFamily(cirq.ops.wait_gate.WaitGate): base_duration * 9,
445+
}
446+
447+
# Serialize the old way
448+
spec = known_devices.create_device_proto_for_qubits(
449+
device_info.grid_qubits,
450+
device_info.qubit_pairs,
451+
[cirq_google.FSIM_GATESET],
452+
known_devices._SYCAMORE_DURATIONS_PICOS,
484453
)
485454

486-
assert grid_dev.metadata.gateset == device_info.expected_gateset
487-
assert (
488-
tuple(grid_dev.metadata.compilation_target_gatesets)
489-
== device_info.expected_target_gatesets
455+
# Serialize the new way
456+
grid_device.create_device_specification_proto(
457+
qubits=device_info.grid_qubits,
458+
pairs=device_info.qubit_pairs,
459+
gateset=cirq.Gateset(*gate_durations.keys()),
460+
gate_durations=gate_durations,
461+
out=spec,
490462
)
491463

492-
assert grid_dev.metadata.gate_durations == device_info.expected_gate_durations
464+
with cirq.testing.assert_deprecated(
465+
'Use cirq_google.GridDevice', deadline='v0.16', count=None
466+
):
467+
# Deserialize both ways
468+
serializable_dev = cirq_google.SerializableDevice.from_proto(
469+
spec, [cirq_google.FSIM_GATESET]
470+
)
471+
grid_dev = cirq_google.GridDevice.from_proto(spec)
472+
473+
assert serializable_dev.metadata.qubit_set == grid_dev.metadata.qubit_set
474+
assert serializable_dev.metadata.qubit_pairs == grid_dev.metadata.qubit_pairs
475+
476+
assert serializable_dev.metadata.gateset == cirq.Gateset(
477+
cirq.FSimGate,
478+
cirq.ISwapPowGate,
479+
cirq.CZPowGate,
480+
cirq.PhasedXPowGate,
481+
cirq.XPowGate,
482+
cirq.YPowGate,
483+
cirq.ZPowGate,
484+
cirq.PhasedXZGate,
485+
cirq.MeasurementGate,
486+
cirq.WaitGate,
487+
cirq.GlobalPhaseGate,
488+
)
489+
490+
assert grid_dev.metadata.gateset == device_info.expected_gateset
491+
assert (
492+
tuple(grid_dev.metadata.compilation_target_gatesets)
493+
== device_info.expected_target_gatesets
494+
)
495+
496+
assert grid_dev.metadata.gate_durations == device_info.expected_gate_durations
493497

494498

495499
def test_to_proto_empty():

cirq-google/cirq_google/devices/known_devices_test.py

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,12 @@ def test_create_device_proto_for_irregular_grid():
6161

6262

6363
def test_multiple_gate_sets():
64-
with cirq.testing.assert_deprecated('no longer be available', deadline='v0.16', count=1):
64+
# Deprecations: well-known cirq_google SerializableGateSets
65+
# (e.g. cirq_google.SYC_GATESET), and
66+
# cirq_google.devices.known_devices.create_device_proto_from_diagram
67+
with cirq.testing.assert_deprecated(
68+
'SerializableGateSet', 'no longer be available', deadline='v0.16', count=2
69+
):
6570
halfPiGateSet = cirq_google.SerializableGateSet(
6671
gate_set_name='half_pi_gateset',
6772
serializers=[*cgc.SINGLE_QUBIT_HALF_PI_SERIALIZERS, cgc.MEASUREMENT_SERIALIZER],
@@ -221,10 +226,15 @@ def test_multiple_gate_sets():
221226

222227

223228
def test_sycamore_circuitop_device():
224-
# Deprecations: cirq_google.SerializableDevice and
229+
# Deprecations: cirq_google.SerializableDevice, well-known cirq_google SerializableGateSets
230+
# (e.g. cirq_google.SYC_GATESET), and
225231
# cirq_google.devices.known_devices.create_device_proto_from_diagram
226232
with cirq.testing.assert_deprecated(
227-
'Use cirq_google.GridDevice', 'no longer be available', deadline='v0.16', count=3
233+
'Use cirq_google.GridDevice',
234+
'SerializableGateSet',
235+
'no longer be available',
236+
deadline='v0.16',
237+
count=5,
228238
):
229239
circuitop_gateset = cirq_google.SerializableGateSet(
230240
gate_set_name='circuitop_gateset',

0 commit comments

Comments
 (0)