Skip to content
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

Deprecate create_device_proto_for_qubits #5592

Merged
Show file tree
Hide file tree
Changes from 1 commit
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
9 changes: 8 additions & 1 deletion cirq-google/cirq_google/devices/grid_device_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -418,7 +418,14 @@ def test_to_proto_invalid_input(error_match, qubits, qubit_pairs, gateset, gate_


def test_to_proto_backward_compatibility():
with cirq.testing.assert_deprecated('SerializableGateSet', deadline='v0.16', count=None):
# Deprecations: cirq_google.SerializableGateSet and
# cirq_google.device.known_devices.create_device_proto_for_qubits()
with cirq.testing.assert_deprecated(
'SerializableGateSet',
'create_device_specification_proto()` can be used',
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
Expand Down
7 changes: 7 additions & 0 deletions cirq-google/cirq_google/devices/known_devices.py
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,13 @@ def _create_grid_device_from_diagram(
return grid_device.GridDevice.from_proto(device_specification)


@_compat.deprecated(
deadline='v0.16',
fix='This function will no longer be available.'
' `cirq_google.grid_device.create_device_specification_proto()` can be used'
' to generate a DeviceSpecification proto which matches the format expected'
' by GridDevice.',
)
def create_device_proto_for_qubits(
qubits: Collection[cirq.Qid],
pairs: Collection[Tuple[cirq.Qid, cirq.Qid]],
Expand Down
23 changes: 13 additions & 10 deletions cirq-google/cirq_google/devices/known_devices_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,13 @@ def test_create_device_proto_for_irregular_grid():
(cirq.GridQubit(0, 0), cirq.GridQubit(1, 0)),
(cirq.GridQubit(1, 0), cirq.GridQubit(1, 1)),
]
proto = known_devices.create_device_proto_for_qubits(qubits, pairs)
assert (
str(proto)
== """\
with cirq.testing.assert_deprecated(
'create_device_specification_proto()` can be used', deadline='v0.16', count=1
):
proto = known_devices.create_device_proto_for_qubits(qubits, pairs)
assert (
str(proto)
== """\
valid_qubits: "0_0"
valid_qubits: "0_1"
valid_qubits: "1_0"
Expand All @@ -57,15 +60,15 @@ 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
with cirq.testing.assert_deprecated(
'SerializableGateSet', 'no longer be available', deadline='v0.16', count=3
'SerializableGateSet', 'no longer be available', deadline='v0.16', count=4
):
halfPiGateSet = cirq_google.SerializableGateSet(
gate_set_name='half_pi_gateset',
Expand Down Expand Up @@ -234,7 +237,7 @@ def test_sycamore_circuitop_device():
'SerializableGateSet',
'no longer be available',
deadline='v0.16',
count=6,
count=7,
):
circuitop_gateset = cirq_google.SerializableGateSet(
gate_set_name='circuitop_gateset',
Expand Down Expand Up @@ -281,7 +284,7 @@ def test_proto_with_circuitop():
# 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
'SerializableGateSet', 'no longer be available', deadline='v0.16', count=3
):
circuitop_gateset = cirq_google.SerializableGateSet(
gate_set_name='circuitop_gateset',
Expand Down Expand Up @@ -341,7 +344,7 @@ def test_proto_with_waitgate():
'SerializableGateSet',
'no longer be available',
deadline='v0.16',
count=4,
count=5,
):
wait_gateset = cirq_google.SerializableGateSet(
gate_set_name='wait_gateset',
Expand Down Expand Up @@ -412,7 +415,7 @@ def test_adding_gates_multiple_times():
'SerializableGateSet',
'no longer be available',
deadline='v0.16',
count=4,
count=5,
):
waiting_for_godot = cirq_google.SerializableGateSet(
gate_set_name='wait_gateset',
Expand Down
38 changes: 25 additions & 13 deletions cirq-google/cirq_google/devices/serializable_device_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,10 +59,15 @@ def _just_meas():


def test_str_with_grid_qubits():
# Deprecations: cirq_google.SerializableDevice and well-known cirq_google SerializableGateSets
# (e.g. cirq_google.SYC_GATESET)
# Deprecations: cirq_google.SerializableDevice, well-known cirq_google SerializableGateSets
# (e.g. cirq_google.SYC_GATESET) and
# cirq_google.devices.known_devices.create_device_proto_for_qubits
with cirq.testing.assert_deprecated(
'Use cirq_google.GridDevice', 'SerializableGateSet', deadline='v0.16', count=4
'Use cirq_google.GridDevice',
'SerializableGateSet',
'create_device_specification_proto()` can be used',
deadline='v0.16',
count=5,
):
qubits = cirq.GridQubit.rect(2, 3, left=1, top=1)
device_proto = cgdk.create_device_proto_for_qubits(
Expand Down Expand Up @@ -94,9 +99,16 @@ def test_repr_pretty(cycle, func):


def test_metadata_correct():
# Deprecations: cirq_google.SerializableDevice and well-known cirq_google SerializableGateSets
# (e.g. cirq_google.SYC_GATESET)
with cirq.testing.assert_deprecated('Use cirq_google.GridDevice', deadline='v0.16', count=4):
# Deprecations: cirq_google.SerializableDevice, well-known cirq_google SerializableGateSets
# (e.g. cirq_google.SYC_GATESET) and
# cirq_google.devices.known_devices.create_device_proto_for_qubits
with cirq.testing.assert_deprecated(
'Use cirq_google.GridDevice',
'SerializableGateSet',
'create_device_specification_proto()` can be used',
deadline='v0.16',
count=5,
):
qubits = cirq.GridQubit.rect(2, 3, left=1, top=1)
pairs = [
(qubits[0], qubits[1]),
Expand Down Expand Up @@ -161,7 +173,7 @@ def test_mismatched_proto_serializer():
'SerializableGateSet',
'no longer be available',
deadline='v0.16',
count=5,
count=6,
):
augmented_proto = cgdk.create_device_proto_from_diagram(
cgdk._SYCAMORE_GRID,
Expand All @@ -186,7 +198,7 @@ def test_named_qubit():
'SerializableGateSet',
'no longer be available',
deadline='v0.16',
count=6,
count=7,
):
augmented_proto = cgdk.create_device_proto_from_diagram(
cgdk._SYCAMORE_GRID,
Expand All @@ -211,7 +223,7 @@ def test_duration_of():
'SerializableGateSet',
'no longer be available',
deadline='v0.16',
count=5,
count=6,
):
valid_qubit1 = cirq.GridQubit(0, 0)

Expand Down Expand Up @@ -382,7 +394,7 @@ def test_multiple_gatesets():
'SerializableGateSet',
'no longer be available',
deadline='v0.16',
count=5,
count=6,
):
halfPiGateSet = cirq_google.SerializableGateSet(
gate_set_name='half_pi_gateset',
Expand Down Expand Up @@ -424,7 +436,7 @@ def test_half_pi_takes_half_duration():
'SerializableGateSet',
'no longer be available',
deadline='v0.16',
count=4,
count=5,
):
half_pi_gs = cirq_google.SerializableGateSet(
gate_set_name='half_pi',
Expand Down Expand Up @@ -457,7 +469,7 @@ def test_multiple_fsim_gatesets():
'SerializableGateSet',
'no longer be available',
deadline='v0.16',
count=4,
count=5,
):
half_pi_gs = cirq_google.SerializableGateSet(
gate_set_name='half_pi',
Expand Down Expand Up @@ -487,7 +499,7 @@ def test_serializable_device_str_grid_qubits():
'SerializableGateSet',
'no longer be available',
deadline='v0.16',
count=5,
count=6,
):
spec = cirq_google.devices.known_devices.create_device_proto_from_diagram(
"aa\naa", [cg.SYC_GATESET]
Expand Down