-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
Add optional qubit_set property to cirq.Device #2605
Conversation
- Make 'validate_operation' optional to implement - qubit_set falls back to looking for qubit/_qubit fields/methods, otherwise returns None
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This seems fine, but I would like to understand a bit more about what we are trying to accomplish with Device. It would be better to have a long-term strategy than have it grow organically.
(Though, having a set of qubits seems pretty standard to a Device, so I don't foresee any issues)
cirq/devices/device.py
Outdated
"""Returns a set or frozenset of qubits on the device, if possible. | ||
|
||
This method returns None when the set of qubits is unavailable. For | ||
example, `cirq.UnconstrainedDevice` returns `None` because allows any |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is redundant with the Returns statement. I would probably keep one or the other rather than repeating it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
""" | ||
|
||
# Compatibility hack to work with devices that were written before this | ||
# method was defined. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As @dstrain115 mentioned, it'd be nice to have a plan for where we are going with Device
so that we can converge on an interface in the future and get rid of this hack. Maybe create an issue to track this and reference the issue number here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Acknowledged.
cirq/devices/device_test.py
Outdated
|
||
class PrivateQubitMethodDevice(cirq.Device): | ||
|
||
def qubits(self): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should be _qubits
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
echoing others' comments about long-term-plan. "Qubits" are inexorably linked to gate sets. Is
I might want to write: qubits = Sycamore.qubits
cirq.Circuit(cirq.CNOT(qubits[0], qubits[1])) but that's not possible, so I might write qubits = list(Sycamore.qubit_set())
.... and then wonder why my program is different after python changes set ordering / we change how qubits are fed into the device constructor / who knows what |
Sets preserve order in python 3, so you shouldn't see the order change like that. |
Automerge cancelled: A status check is failing. |
I have discovered that sets do not preserve order in python 3, only dictionaries. |
Automerge cancelled: There are merge conflicts. |
Automerge cancelled: A status check is failing. |
See my concerns above. I think it will be more helpful to have ordered qubits in a device |
This makes devices easier to consume (because a common task is to want to view the qubits, knowing that the device is not the unconstrained device) and easier to make (because when prototyping you don't care about validating operations yet).
The shortest interesting device class now looks like this:
or this: