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 |
maffoo
left a comment
There was a problem hiding this comment.
One minor comment, then LGTM.
Accept exactly one argument when it is an iterable of qubits. Co-authored-by: Matthew Neeley <mneeley@gmail.com>
Accept exactly one argument when it is an iterable of qubits.
Done. Thank you for the mypy tip on double underscore! |
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.measureandcirq.measure_eachina single iterable argument.
Keep accepting them as variable-length arguments as before.
Fixes #2408.