-
Notifications
You must be signed in to change notification settings - Fork 1.1k
cirq.measure - accept list arguments #5411
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
cirq.measure - accept list arguments #5411
Conversation
ndarray docstring advises to use np.array for array creation.
Not yet ready, expecting test failure.
Allow variable-length arguments as well as iterables. Resolve quantumlib#2408
I think allowing arbitrarily nested lists of Qids is probably more flexibility than we want to allow. I'd suggest that we accept either Qids as varargs, or a single iterable arg containins Qids. It should be possible to use |
Sounds good to me, but Cirq/cirq-core/cirq/ops/raw_types.py Lines 266 to 271 in 6273826
|
The In [1]: a, b, c, d = cirq.LineQubit.range(4)
In [2]: cirq.H.on_each([[[[a]]]], b, [[c], [[d]]])
Out[2]:
[cirq.H(cirq.LineQubit(0)),
cirq.H(cirq.LineQubit(1)),
cirq.H(cirq.LineQubit(2)),
cirq.H(cirq.LineQubit(3))] but for multi-qubit gates it only allows either varargs or a single sequence of sequences of qids: n [3]: cirq.CZ.on_each((a, b), (c, d))
Out[3]:
[cirq.CZ(cirq.LineQubit(0), cirq.LineQubit(1)),
cirq.CZ(cirq.LineQubit(2), cirq.LineQubit(3))]
In [4]: cirq.CZ.on_each([(a, b), (c, d)])
Out[4]:
[cirq.CZ(cirq.LineQubit(0), cirq.LineQubit(1)),
cirq.CZ(cirq.LineQubit(2), cirq.LineQubit(3))]
In [5]: cirq.CZ.on_each([(a, b)], [(c, d)])
...
ValueError: All values in sequence should be Qids, but got [(cirq.LineQubit(0), cirq.LineQubit(1))] I'm not sure if this behavior for single-qubit gates was intentional, but I'd be surprised if it were. I think just accepting For Whatever we decide to do, we should probably also modify |
@maffoo - sounds good, I will adjust it that way. |
Simplify arguments handling - qubits must be either passed in a single iterable argument or as multiple scalar arguments.
Not yet ready, expecting test failure.
Accept qubits in variable-length arguments or as a single argument which must be an iterable of qubits.
Ready for next review. I am not entirely sure if I got right the typing in function implementations after |
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.
One minor comment, then LGTM.
Accept exactly one argument when it is an iterable of qubits. Co-authored-by: Matthew Neeley <[email protected]>
Accept exactly one argument when it is an iterable of qubits.
Done. Thank you for the mypy tip on double underscore! |
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.
LGTM
Allow passing qubits for `cirq.measure` and `cirq.measure_each` in a single iterable argument. Keep accepting them as variable-length arguments as before. Fixes quantumlib#2408.
Allow passing qubits for `cirq.measure` and `cirq.measure_each` in a single iterable argument. Keep accepting them as variable-length arguments as before. Fixes quantumlib#2408.
Allow passing qubits for
cirq.measure
andcirq.measure_each
ina single iterable argument.
Keep accepting them as variable-length arguments as before.
Fixes #2408.