From 200e376c4ec78703660a9a04cfddd699e103be0d Mon Sep 17 00:00:00 2001 From: Dave Bacon Date: Tue, 16 Nov 2021 02:05:05 +0000 Subject: [PATCH 1/2] Enforce LineQubit type for IonDevices --- cirq-core/cirq/ion/ion_device.py | 8 ++++++++ cirq-core/cirq/ion/ion_device_test.py | 8 ++++++++ 2 files changed, 16 insertions(+) diff --git a/cirq-core/cirq/ion/ion_device.py b/cirq-core/cirq/ion/ion_device.py index a1a1c2b3bc8..ef8bfda4b19 100644 --- a/cirq-core/cirq/ion/ion_device.py +++ b/cirq-core/cirq/ion/ion_device.py @@ -56,10 +56,18 @@ def __init__( oneq_gates_duration: The maximum duration of a single qubit operation. qubits: Qubits on the device, identified by their x, y location. + + Raises: + TypeError: If not all the qubits supplied are `cirq.LineQubit`s. """ self._measurement_duration = value.Duration(measurement_duration) self._twoq_gates_duration = value.Duration(twoq_gates_duration) self._oneq_gates_duration = value.Duration(oneq_gates_duration) + if not all(isinstance(qubit, devices.LineQubit) for qubit in qubits): + raise TypeError( + "All qubits were not of type cirq.LineQubit, instead were " + f"{set(type(qubit) for qubit in qubits)}" + ) self.qubits = frozenset(qubits) self.gateset = get_ion_gateset() diff --git a/cirq-core/cirq/ion/ion_device_test.py b/cirq-core/cirq/ion/ion_device_test.py index 9eae53cc457..56f9eb5f69b 100644 --- a/cirq-core/cirq/ion/ion_device_test.py +++ b/cirq-core/cirq/ion/ion_device_test.py @@ -56,6 +56,14 @@ def test_init(): with pytest.raises(ValueError): _ = d.duration_of(cirq.SingleQubitGate().on(q0)) + with pytest.raises(TypeError, match="NamedQubit"): + _ = cirq.IonDevice( + measurement_duration=ms, + twoq_gates_duration=ms, + oneq_gates_duration=ms, + qubits=[cirq.LineQubit(0), cirq.NamedQubit("a")], + ) + def test_init_timedelta(): d = ion_device(3, use_timedelta=True) From b093b629dfe2f3e8bdc7dc9370fb9cb8e20e1eb8 Mon Sep 17 00:00:00 2001 From: Dave Bacon Date: Tue, 16 Nov 2021 17:30:29 +0000 Subject: [PATCH 2/2] fix doc --- cirq-core/cirq/ion/ion_device.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cirq-core/cirq/ion/ion_device.py b/cirq-core/cirq/ion/ion_device.py index ef8bfda4b19..ba46e3774bd 100644 --- a/cirq-core/cirq/ion/ion_device.py +++ b/cirq-core/cirq/ion/ion_device.py @@ -55,7 +55,7 @@ def __init__( twoq_gates_duration: The maximum duration of a two qubit operation. oneq_gates_duration: The maximum duration of a single qubit operation. - qubits: Qubits on the device, identified by their x, y location. + qubits: Qubits on the device, identified by their x location. Raises: TypeError: If not all the qubits supplied are `cirq.LineQubit`s.