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

Enforce LineQubit type for IonDevices #4690

Merged
merged 4 commits into from
Nov 16, 2021
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
8 changes: 8 additions & 0 deletions cirq-core/cirq/ion/ion_device.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Copy link
Collaborator

@vtomole vtomole Nov 16, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove identified by their x, y location because it's not x,y location anymore.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nice catch!


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