Skip to content

Commit

Permalink
Enforce LineQubit type for IonDevices (quantumlib#4690)
Browse files Browse the repository at this point in the history
  • Loading branch information
dabacon authored and rht committed May 1, 2023
1 parent 89a2b6a commit 00ad692
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
10 changes: 9 additions & 1 deletion cirq-core/cirq/ion/ion_device.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,11 +55,19 @@ 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.
"""
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()

Expand Down
8 changes: 8 additions & 0 deletions cirq-core/cirq/ion/ion_device_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 00ad692

Please sign in to comment.