Skip to content

SerializableGateSet deprecation #5573

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 45 additions & 2 deletions cirq-google/cirq_google/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,50 @@
_compat.deprecate_attributes(
__name__,
{
'Bristlecone': ('v0.15', 'Bristlecone will no longer be supported.'),
'Foxtail': ('v0.15', 'Foxtail will no longer be supported.'),
'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.',
),
},
)
93 changes: 47 additions & 46 deletions cirq-google/cirq_google/calibration/phased_fsim_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -221,54 +221,55 @@ def test_floquet_to_calibration_layer_with_measure_qubits():


def test_xeb_to_calibration_layer():
q_00, q_01, q_02, q_03 = [cirq.GridQubit(0, index) for index in range(4)]
gate = cirq.FSimGate(theta=np.pi / 4, phi=0.0)
request = XEBPhasedFSimCalibrationRequest(
gate=gate,
pairs=((q_00, q_01), (q_02, q_03)),
options=XEBPhasedFSimCalibrationOptions(
n_library_circuits=22,
fsim_options=XEBPhasedFSimCharacterizationOptions(
characterize_theta=True,
characterize_zeta=True,
characterize_chi=False,
characterize_gamma=False,
characterize_phi=True,
with cirq.testing.assert_deprecated('SerializableGateSet', deadline='v0.16', count=None):
q_00, q_01, q_02, q_03 = [cirq.GridQubit(0, index) for index in range(4)]
gate = cirq.FSimGate(theta=np.pi / 4, phi=0.0)
request = XEBPhasedFSimCalibrationRequest(
gate=gate,
pairs=((q_00, q_01), (q_02, q_03)),
options=XEBPhasedFSimCalibrationOptions(
n_library_circuits=22,
fsim_options=XEBPhasedFSimCharacterizationOptions(
characterize_theta=True,
characterize_zeta=True,
characterize_chi=False,
characterize_gamma=False,
characterize_phi=True,
),
),
),
)
layer = request.to_calibration_layer()
assert layer == cirq_google.CalibrationLayer(
calibration_type='xeb_phased_fsim_characterization',
program=cirq.Circuit([gate.on(q_00, q_01), gate.on(q_02, q_03)]),
args={
'n_library_circuits': 22,
'n_combinations': 10,
'cycle_depths': '5_25_50_100_200_300',
'fatol': 5e-3,
'xatol': 5e-3,
'characterize_theta': True,
'characterize_zeta': True,
'characterize_chi': False,
'characterize_gamma': False,
'characterize_phi': True,
},
)
)
layer = request.to_calibration_layer()
assert layer == cirq_google.CalibrationLayer(
calibration_type='xeb_phased_fsim_characterization',
program=cirq.Circuit([gate.on(q_00, q_01), gate.on(q_02, q_03)]),
args={
'n_library_circuits': 22,
'n_combinations': 10,
'cycle_depths': '5_25_50_100_200_300',
'fatol': 5e-3,
'xatol': 5e-3,
'characterize_theta': True,
'characterize_zeta': True,
'characterize_chi': False,
'characterize_gamma': False,
'characterize_phi': True,
},
)

# Serialize to proto
calibration = v2.calibration_pb2.FocusedCalibration()
new_layer = calibration.layers.add()
new_layer.calibration_type = layer.calibration_type
for arg in layer.args:
arg_to_proto(layer.args[arg], out=new_layer.args[arg])
cirq_google.SQRT_ISWAP_GATESET.serialize(layer.program, msg=new_layer.layer)
with open(os.path.dirname(__file__) + '/test_data/xeb_calibration_layer.textproto') as f:
desired_textproto = f.read()

layer_str = str(new_layer)
# Fix precision issues
layer_str = re.sub(r'0.004999\d+', '0.005', layer_str)
assert layer_str == desired_textproto
# Serialize to proto
calibration = v2.calibration_pb2.FocusedCalibration()
new_layer = calibration.layers.add()
new_layer.calibration_type = layer.calibration_type
for arg in layer.args:
arg_to_proto(layer.args[arg], out=new_layer.args[arg])
cirq_google.SQRT_ISWAP_GATESET.serialize(layer.program, msg=new_layer.layer)
with open(os.path.dirname(__file__) + '/test_data/xeb_calibration_layer.textproto') as f:
desired_textproto = f.read()

layer_str = str(new_layer)
# Fix precision issues
layer_str = re.sub(r'0.004999\d+', '0.005', layer_str)
assert layer_str == desired_textproto


def test_from_moment():
Expand Down
140 changes: 72 additions & 68 deletions cirq-google/cirq_google/devices/grid_device_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -418,78 +418,82 @@ def test_to_proto_invalid_input(error_match, qubits, qubit_pairs, gateset, gate_


def test_to_proto_backward_compatibility():
device_info, _ = _create_device_spec_with_horizontal_couplings()

# The set of gates in gate_durations are consistent with what's generated in
# _create_device_spec_with_horizontal_couplings()
base_duration = cirq.Duration(picos=1_000)
gate_durations = {
cirq.GateFamily(cirq_google.SYC): base_duration * 0,
cirq.GateFamily(cirq.SQRT_ISWAP): base_duration * 1,
cirq.GateFamily(cirq.SQRT_ISWAP_INV): base_duration * 2,
cirq.GateFamily(cirq.CZ): base_duration * 3,
cirq.GateFamily(cirq.ops.phased_x_z_gate.PhasedXZGate): base_duration * 4,
cirq.GateFamily(
cirq.ops.common_gates.ZPowGate, tags_to_ignore=[cirq_google.PhysicalZTag()]
): base_duration
* 5,
cirq.GateFamily(
cirq.ops.common_gates.ZPowGate, tags_to_accept=[cirq_google.PhysicalZTag()]
): base_duration
* 6,
cirq.GateFamily(cirq_google.experimental.ops.coupler_pulse.CouplerPulse): base_duration * 7,
cirq.GateFamily(cirq.ops.measurement_gate.MeasurementGate): base_duration * 8,
cirq.GateFamily(cirq.ops.wait_gate.WaitGate): base_duration * 9,
}

# Serialize the old way
spec = known_devices.create_device_proto_for_qubits(
device_info.grid_qubits,
device_info.qubit_pairs,
[cirq_google.FSIM_GATESET],
known_devices._SYCAMORE_DURATIONS_PICOS,
)

# Serialize the new way
grid_device.create_device_specification_proto(
qubits=device_info.grid_qubits,
pairs=device_info.qubit_pairs,
gateset=cirq.Gateset(*gate_durations.keys()),
gate_durations=gate_durations,
out=spec,
)

with cirq.testing.assert_deprecated('Use cirq_google.GridDevice', deadline='v0.16', count=None):
# Deserialize both ways
serializable_dev = cirq_google.SerializableDevice.from_proto(
spec, [cirq_google.FSIM_GATESET]
)
grid_dev = cirq_google.GridDevice.from_proto(spec)

assert serializable_dev.metadata.qubit_set == grid_dev.metadata.qubit_set
assert serializable_dev.metadata.qubit_pairs == grid_dev.metadata.qubit_pairs

assert serializable_dev.metadata.gateset == cirq.Gateset(
cirq.FSimGate,
cirq.ISwapPowGate,
cirq.CZPowGate,
cirq.PhasedXPowGate,
cirq.XPowGate,
cirq.YPowGate,
cirq.ZPowGate,
cirq.PhasedXZGate,
cirq.MeasurementGate,
cirq.WaitGate,
cirq.GlobalPhaseGate,
with cirq.testing.assert_deprecated('SerializableGateSet', deadline='v0.16', count=None):
device_info, _ = _create_device_spec_with_horizontal_couplings()

# The set of gates in gate_durations are consistent with what's generated in
# _create_device_spec_with_horizontal_couplings()
base_duration = cirq.Duration(picos=1_000)
gate_durations = {
cirq.GateFamily(cirq_google.SYC): base_duration * 0,
cirq.GateFamily(cirq.SQRT_ISWAP): base_duration * 1,
cirq.GateFamily(cirq.SQRT_ISWAP_INV): base_duration * 2,
cirq.GateFamily(cirq.CZ): base_duration * 3,
cirq.GateFamily(cirq.ops.phased_x_z_gate.PhasedXZGate): base_duration * 4,
cirq.GateFamily(
cirq.ops.common_gates.ZPowGate, tags_to_ignore=[cirq_google.PhysicalZTag()]
): base_duration
* 5,
cirq.GateFamily(
cirq.ops.common_gates.ZPowGate, tags_to_accept=[cirq_google.PhysicalZTag()]
): base_duration
* 6,
cirq.GateFamily(cirq_google.experimental.ops.coupler_pulse.CouplerPulse): base_duration
* 7,
cirq.GateFamily(cirq.ops.measurement_gate.MeasurementGate): base_duration * 8,
cirq.GateFamily(cirq.ops.wait_gate.WaitGate): base_duration * 9,
}

# Serialize the old way
spec = known_devices.create_device_proto_for_qubits(
device_info.grid_qubits,
device_info.qubit_pairs,
[cirq_google.FSIM_GATESET],
known_devices._SYCAMORE_DURATIONS_PICOS,
)

assert grid_dev.metadata.gateset == device_info.expected_gateset
assert (
tuple(grid_dev.metadata.compilation_target_gatesets)
== device_info.expected_target_gatesets
# Serialize the new way
grid_device.create_device_specification_proto(
qubits=device_info.grid_qubits,
pairs=device_info.qubit_pairs,
gateset=cirq.Gateset(*gate_durations.keys()),
gate_durations=gate_durations,
out=spec,
)

assert grid_dev.metadata.gate_durations == device_info.expected_gate_durations
with cirq.testing.assert_deprecated(
'Use cirq_google.GridDevice', deadline='v0.16', count=None
):
# Deserialize both ways
serializable_dev = cirq_google.SerializableDevice.from_proto(
spec, [cirq_google.FSIM_GATESET]
)
grid_dev = cirq_google.GridDevice.from_proto(spec)

assert serializable_dev.metadata.qubit_set == grid_dev.metadata.qubit_set
assert serializable_dev.metadata.qubit_pairs == grid_dev.metadata.qubit_pairs

assert serializable_dev.metadata.gateset == cirq.Gateset(
cirq.FSimGate,
cirq.ISwapPowGate,
cirq.CZPowGate,
cirq.PhasedXPowGate,
cirq.XPowGate,
cirq.YPowGate,
cirq.ZPowGate,
cirq.PhasedXZGate,
cirq.MeasurementGate,
cirq.WaitGate,
cirq.GlobalPhaseGate,
)

assert grid_dev.metadata.gateset == device_info.expected_gateset
assert (
tuple(grid_dev.metadata.compilation_target_gatesets)
== device_info.expected_target_gatesets
)

assert grid_dev.metadata.gate_durations == device_info.expected_gate_durations


def test_to_proto_empty():
Expand Down
38 changes: 30 additions & 8 deletions cirq-google/cirq_google/devices/known_devices_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,12 @@ def test_create_device_proto_for_irregular_grid():


def test_multiple_gate_sets():
with cirq.testing.assert_deprecated('no longer be available', deadline='v0.16', count=1):
# 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
with cirq.testing.assert_deprecated(
'SerializableGateSet', 'no longer be available', deadline='v0.16', count=3
):
halfPiGateSet = cirq_google.SerializableGateSet(
gate_set_name='half_pi_gateset',
serializers=[*cgc.SINGLE_QUBIT_HALF_PI_SERIALIZERS, cgc.MEASUREMENT_SERIALIZER],
Expand Down Expand Up @@ -221,10 +226,15 @@ def test_multiple_gate_sets():


def test_sycamore_circuitop_device():
# Deprecations: cirq_google.SerializableDevice and
# 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
with cirq.testing.assert_deprecated(
'Use cirq_google.GridDevice', 'no longer be available', deadline='v0.16', count=3
'Use cirq_google.GridDevice',
'SerializableGateSet',
'no longer be available',
deadline='v0.16',
count=6,
):
circuitop_gateset = cirq_google.SerializableGateSet(
gate_set_name='circuitop_gateset',
Expand Down Expand Up @@ -268,7 +278,11 @@ def test_sycamore_grid_layout():


def test_proto_with_circuitop():
with cirq.testing.assert_deprecated('no longer be available', deadline='v0.16', count=1):
# Deprecations: cirq_google.SerializableGateSets class 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=2
):
circuitop_gateset = cirq_google.SerializableGateSet(
gate_set_name='circuitop_gateset',
serializers=[cgc.CIRCUIT_OP_SERIALIZER],
Expand Down Expand Up @@ -320,10 +334,14 @@ def test_proto_with_circuitop():


def test_proto_with_waitgate():
# Deprecations: cirq_google.SerializableDevice and
# Deprecations: cirq_google.SerializableDevice, cirq_google.SerializableGateSet, and
# cirq_google.devices.known_devices.create_device_proto_from_diagram
with cirq.testing.assert_deprecated(
'Use cirq_google.GridDevice', 'no longer be available', deadline='v0.16', count=3
'Use cirq_google.GridDevice',
'SerializableGateSet',
'no longer be available',
deadline='v0.16',
count=4,
):
wait_gateset = cirq_google.SerializableGateSet(
gate_set_name='wait_gateset',
Expand Down Expand Up @@ -387,10 +405,14 @@ def test_proto_with_waitgate():


def test_adding_gates_multiple_times():
# Deprecations: cirq_google.SerializableDevice and
# Deprecations: cirq_google.SerializableDevice, cirq_google.SerializableGateSet, and
# cirq_google.devices.known_devices.create_device_proto_from_diagram
with cirq.testing.assert_deprecated(
'Use cirq_google.GridDevice', 'no longer be available', deadline='v0.16', count=3
'Use cirq_google.GridDevice',
'SerializableGateSet',
'no longer be available',
deadline='v0.16',
count=4,
):
waiting_for_godot = cirq_google.SerializableGateSet(
gate_set_name='wait_gateset',
Expand Down
Loading